Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
Merge pull request #191 from Honny1/output-test-commands
Browse files Browse the repository at this point in the history
The output of test_commands.sh
  • Loading branch information
matusmarhefka authored Jul 19, 2021
2 parents c63886c + 342725c commit f679568
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 38 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ stats
.tox/

tmp_data/
test_commands.log
84 changes: 46 additions & 38 deletions test_commands.sh
Original file line number Diff line number Diff line change
Expand Up @@ -135,50 +135,44 @@ install_package_from_source() {
}

report() {
if [ "$_arg_verbose" = "on" ]; then
if [ $test_result -eq 0 ]; then
printf "Result: %-70s \x1b[32mpassed\x1b[0m\n" "$*"
else
printf "Result: %-70s \x1b[31mfailed\x1b[0m\n\n" "$*"
fi
if [ $test_result -eq 0 ]; then
printf "Result: %-70s \x1b[32mpassed\x1b[0m\n" "$*" # ]] <-- needed because of Argbash
else
printf "Result: %-70s \x1b[31mfailed\x1b[0m\n" "$*" # ]] <-- needed because of Argbash
fi
}

test() {
test_command() {
test_name="$1"
command="$2"
msg=""
if [ "$_arg_verbose" = "on" ]; then
echo "Start: $test_name"
$command
else
$command &>/dev/null
fi
if [ $? -eq 0 ]; then
echo "Start: $test_name"
output=$($command 2>&1)
exit_code=$?
if [ $exit_code -eq 0 ]; then
test_result=0
msg="$test_name"
else
echo "$output"
test_result=1
overall_test_result=1
msg="$test_name: $command"
fi
report "${msg}"
}

test_rise_error() {
test_command_rise_error() {
test_name="$1"
command="$2"
msg=""
if [ "$_arg_verbose" = "on" ]; then
echo "Start: $test_name"
$command
else
$command &>/dev/null
fi
if [ $? -eq 2 ]; then
echo "Start: $test_name"
output=$($command 2>&1)
exit_code=$?
if [ $exit_code -eq 2 ]; then
test_result=0
msg="$test_name"
else
echo "$output"
test_result=1
overall_test_result=1
msg="$test_name: $command"
Expand All @@ -195,39 +189,46 @@ clean() {
}

help_tests() {
test arf-to-graph-help "arf-to-graph -h"
test arf-to-json-help "arf-to-json -h"
test json-to-graph-help "json-to-graph -h"
test_command arf-to-graph-help "arf-to-graph -h"
test_command arf-to-json-help "arf-to-json -h"
test_command json-to-graph-help "json-to-graph -h"
}

bad_args_tests() {
test_rise_error arf-to-graph-bad_arg "arf-to-graph -hello"
test_rise_error arf-to-json-bad_arg "arf-to-json -hello"
test_rise_error json-to-graph-bad_arg "json-to-graph -hello"
test_command_rise_error arf-to-graph-bad_arg "arf-to-graph -hello"
test_command_rise_error arf-to-json-bad_arg "arf-to-json -hello"
test_command_rise_error json-to-graph-bad_arg "json-to-graph -hello"
}

basic_test() {
test run-arf-to-graph "arf-to-graph -o ${tmp_dir_src} ${test_file_src} fips"
test run-arf-to-json "arf-to-json -o ${tmp_json_file_src} ${test_file_src} fips"
test run-json-to-graph "json-to-graph -o ${tmp_dir_src} ${tmp_json_file_src} fips"
test_command run-arf-to-graph "arf-to-graph -o ${tmp_dir_src} ${test_file_src} fips"
test_command run-arf-to-json "arf-to-json -o ${tmp_json_file_src} ${test_file_src} fips"
test_command run-json-to-graph "json-to-graph -o ${tmp_dir_src} ${tmp_json_file_src} fips"
}

regex_and_all_test() {
test run-arf-to-graph_regex "arf-to-graph -o ${tmp_dir_src} ${test_file_src} -a _package_\w+_removed"
test run-arf-to-json_regex "arf-to-json -o ${tmp_json_file_src} ${test_file_src} -a _package_\w+_removed"
test run-json-to-graph_regex "json-to-graph -o ${tmp_dir_src} ${tmp_json_file_src} -a _package_\w+_removed"
test_command run-arf-to-graph_regex "arf-to-graph -o ${tmp_dir_src} ${test_file_src} -a _package_\w+_removed"
test_command run-arf-to-json_regex "arf-to-json -o ${tmp_json_file_src} ${test_file_src} -a _package_\w+_removed"
test_command run-json-to-graph_regex "json-to-graph -o ${tmp_dir_src} ${tmp_json_file_src} -a _package_\w+_removed"
}

regex_and_all_in_one_test() {
test run-arf-to-graph_regex "arf-to-graph -o ${tmp_dir_src} ${test_file_src} -i _package_\w+_removed"
test run-json-to-graph_regex "json-to-graph -o ${tmp_dir_src} ${tmp_json_file_src} -i _package_\w+_removed"
test_command run-arf-to-graph_regex "arf-to-graph -o ${tmp_dir_src} ${test_file_src} -i _package_\w+_removed"
test_command run-json-to-graph_regex "json-to-graph -o ${tmp_dir_src} ${tmp_json_file_src} -i _package_\w+_removed"
}

hide_all_passing_tests_test() {
test run-arf-to-graph "arf-to-graph -o ${tmp_dir_src} ${test_file_src} --hide-passing-tests fips"
test run-json-to-graph "json-to-graph -o ${tmp_dir_src} ${tmp_json_file_src} --hide-passing-tests -i fips"
test_command run-arf-to-graph "arf-to-graph -o ${tmp_dir_src} ${test_file_src} --hide-passing-tests fips"
test_command run-json-to-graph "json-to-graph -o ${tmp_dir_src} ${tmp_json_file_src} --hide-passing-tests -i fips"
}


# Backup descriptors stdout -> 3, stderr -> 4
exec 3>&1 4>&2

# Redirect stdout and stderr to file
exec &>test_commands.log

if [ "$_arg_install_oval_graph" = "on" ]; then
install_package_from_source
fi
Expand All @@ -244,5 +245,12 @@ hide_all_passing_tests_test
if [ "$_arg_clean" = "on" ]; then
clean "${tmp_dir_src}"
fi

if [[ ("$_arg_verbose" = "on") || ($overall_test_result -eq 1) ]]; then
# Restore descriptors
exec 1>&3 2>&4
cat test_commands.log
fi

exit "$overall_test_result"
# ] <-- needed because of Argbash

0 comments on commit f679568

Please sign in to comment.