Verified Commit 05aa548b authored by Roman Lacko's avatar Roman Lacko
Browse files

hw02: Update CLI suite from upstream

* 5c120cd source: Make source path relative to "data" directory
* ab3a9e1 source: Update CLI from upstream
parent a8051403
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@


#   ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#   ┃   𝐃𝐎 𝐍𝐎𝐓 𝐄𝐃𝐈𝐓 𝐓𝐇𝐈𝐒 𝐅𝐈𝐋𝐄
#   ┃   DO NOT EDIT THIS FILE
#   ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛


+58 −8
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@


#   ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
#   ┃   𝐃𝐎 𝐍𝐎𝐓 𝐄𝐃𝐈𝐓 𝐓𝐇𝐈𝐒 𝐅𝐈𝐋𝐄
#   ┃   DO NOT EDIT THIS FILE
#   ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛


@@ -192,22 +192,49 @@ cli_run_diff() {
	return 0
}

cli_run_check_fail() {
	_cli_msg_fail "Output '$kind' did not pass the custom check"
}

_cli_run_check_output() {
	kind="$1"
	actual="$2"
	expected="$3"

	if type "cli_run_check_$kind" >/dev/null 2>&1; then
		if ! "cli_run_check_$kind" "$actual" "$expected"; then
	for prefix in suite cli; do
		if ! type "${prefix}_run_check_${kind}" >/dev/null 2>&1; then
			continue
		fi

		if ! "${prefix}_run_check_${kind}" "$actual" "$expected"; then
			if [ "$_cli_msg_dirty" -ne 0 ]; then
				cli_run_check_fail
			fi

			return 1
		fi
	elif ! cli_run_diff $@; then

		return 0
	done

	if ! cli_run_diff "$@"; then
		return 1
	fi

	return 0
}

cli_env() {
	export "$@"
	echo "export '$@'" >>"$cli_stash/env"
}

_cli_env_restore() {
	if [ -f "$cli_stash/env" ]; then
		. "$cli_stash/env"
	fi
}

_cli_test_usage() {
	_cli_msg_fatal "usage: run [OPTIONS] DESCRIPTION [--] TEST [ARGS...]"
}
@@ -262,12 +289,25 @@ _cli_run_test_options() {
	fi
}

_cli_resolve_data() {
	suffix="$1"
	name="$2"

	if [ -z "$name" ]; then
		echo "${cli_data}/${cli_test_name}.${suffix}"
	elif [ "${name}" = "${name%/}" ]; then
		echo "${cli_data}/${name}"
	else
		echo "${name}"
	fi
}

_cli_run_test_eval() {
	cli_data="${cli_script_bin}/${test_data:-data}"

	[ -n "$_in" ] || _in="${cli_data}/$cli_test_name.in"
	[ -n "$_exp_out" ] || _exp_out="${cli_data}/$cli_test_name.out"
	[ -n "$_exp_err" ] || _exp_err="${cli_data}/$cli_test_name.err"
	_in=$(_cli_resolve_data in "$_in")
	_exp_out=$(_cli_resolve_data out "$_exp_out")
	_exp_err=$(_cli_resolve_data err "$_exp_err")

	if [ ! -f "$_in" ]; then
		_cli_msg_debug "Input $_in not found, using /dev/null"
@@ -287,21 +327,25 @@ _cli_run_test_eval() {
	trap '_cli_run_cleanup "$cli_workdir" "$cli_stash"' EXIT TERM INT

	(
		_cli_msg_debug "Executing setup functions"
		cd "$cli_workdir"

		_cli_hook_run "tests_setup" "$cli_test_name"
		_cli_hook_run "suite_setup" "$cli_test_name"
		_cli_hook_run "${cli_test_name}_setup"
	)

	_cli_msg_test "#$((_cli_tests_total + 1)): ${cli_test_desc}"
	_cli_msg_debug "Executing test function"

	(
		_cli_msg_debug "Executing test function"

		set +x
		if [ "$_strict" -eq 1 ]; then
			set -e
		fi

		_cli_env_restore
		cd "$cli_workdir"
		"$@" >&4 2>&5
	) <$_in 3>&1 4>$_prog_out 5>$_prog_err
@@ -310,6 +354,9 @@ _cli_run_test_eval() {
	_cli_msg_debug "Exit code $exit_code"

	(
		_cli_msg_debug "Executing teardown functions"

		_cli_env_restore
		cd "$cli_workdir"
		_cli_hook_run "${cli_test_name}_teardown"
		_cli_hook_run "suite_teardown" "$cli_test_name"
@@ -454,12 +501,15 @@ for file in "${cli_script_bin}"/tests-*.sh; do

	unset -f suite_setup
	unset -f suite_teardown
	unset -f suite_run_check_stdout
	unset -f suite_run_check_stderr

	cli_suite_count=0
	. "$file"

	if [ "$cli_suite_count" -eq 0 ]; then
		printf "\e[37mNo tests\e[0m\n"
		echo
	fi
done

+5 −5
Original line number Diff line number Diff line
#!/bin/false

run -0 data/valid.in -1 data/valid.out -2 data/valid.err "Validation (--check-valid)" -- \
run -0 valid.in -1 valid.out -2 valid.err "Validation (--check-valid)" -- \
	$exe --load --check-valid

run -0 data/elimination.in -1 data/elimination.out -2 data/elimination.err "Eliminations (--eliminate-*)" -- \
run -0 elimination.in -1 elimination.out -2 elimination.err "Eliminations (--eliminate-*)" -- \
	$exe --load --eliminate-row 3 --eliminate-col 0 --eliminate-box 03 --print

run -0 data/load.in -1 data/load.out -2 data/load.err "Loading (--load, --print)" -- \
run -0 load.in -1 load.out -2 load.err "Loading (--load, --print)" -- \
	$exe --load --raw --load --print

run -0 data/needs-solving.in -1 data/needs-solving.out -2 data/needs-solving.err "Unsolved sudoku detection (--needs-solving)" -- \
run -0 needs-solving.in -1 needs-solving.out -2 needs-solving.err "Unsolved sudoku detection (--needs-solving)" -- \
	$exe --load --needs-solving

run -0 data/simple-full-solve.in -1 data/simple-full-solve.out -2 data/simple-full-solve.err "Solving (--solve, --print)" -- \
run -0 simple-full-solve.in -1 simple-full-solve.out -2 simple-full-solve.err "Solving (--solve, --print)" -- \
	$exe --load --solve --print