@@ -135,50 +135,44 @@ install_package_from_source() {
135135}
136136
137137report () {
138- if [ " $_arg_verbose " = " on" ]; then
139- if [ $test_result -eq 0 ]; then
140- printf " Result: %-70s \x1b[32mpassed\x1b[0m\n" " $* "
141- else
142- printf " Result: %-70s \x1b[31mfailed\x1b[0m\n\n" " $* "
143- fi
138+ if [ $test_result -eq 0 ]; then
139+ printf " Result: %-70s \x1b[32mpassed\x1b[0m\n" " $* " # ]] <-- needed because of Argbash
140+ else
141+ printf " Result: %-70s \x1b[31mfailed\x1b[0m\n" " $* " # ]] <-- needed because of Argbash
144142 fi
145143}
146144
147- test () {
145+ test_command () {
148146 test_name=" $1 "
149147 command=" $2 "
150148 msg=" "
151- if [ " $_arg_verbose " = " on" ]; then
152- echo " Start: $test_name "
153- $command
154- else
155- $command & > /dev/null
156- fi
157- if [ $? -eq 0 ]; then
149+ echo " Start: $test_name "
150+ output=$( $command 2>&1 )
151+ exit_code=$?
152+ if [ $exit_code -eq 0 ]; then
158153 test_result=0
159154 msg=" $test_name "
160155 else
156+ echo " $output "
161157 test_result=1
162158 overall_test_result=1
163159 msg=" $test_name : $command "
164160 fi
165161 report " ${msg} "
166162}
167163
168- test_rise_error () {
164+ test_command_rise_error () {
169165 test_name=" $1 "
170166 command=" $2 "
171167 msg=" "
172- if [ " $_arg_verbose " = " on" ]; then
173- echo " Start: $test_name "
174- $command
175- else
176- $command & > /dev/null
177- fi
178- if [ $? -eq 2 ]; then
168+ echo " Start: $test_name "
169+ output=$( $command 2>&1 )
170+ exit_code=$?
171+ if [ $exit_code -eq 2 ]; then
179172 test_result=0
180173 msg=" $test_name "
181174 else
175+ echo " $output "
182176 test_result=1
183177 overall_test_result=1
184178 msg=" $test_name : $command "
@@ -195,39 +189,46 @@ clean() {
195189}
196190
197191help_tests () {
198- test arf-to-graph-help " arf-to-graph -h"
199- test arf-to-json-help " arf-to-json -h"
200- test json-to-graph-help " json-to-graph -h"
192+ test_command arf-to-graph-help " arf-to-graph -h"
193+ test_command arf-to-json-help " arf-to-json -h"
194+ test_command json-to-graph-help " json-to-graph -h"
201195}
202196
203197bad_args_tests () {
204- test_rise_error arf-to-graph-bad_arg " arf-to-graph -hello"
205- test_rise_error arf-to-json-bad_arg " arf-to-json -hello"
206- test_rise_error json-to-graph-bad_arg " json-to-graph -hello"
198+ test_command_rise_error arf-to-graph-bad_arg " arf-to-graph -hello"
199+ test_command_rise_error arf-to-json-bad_arg " arf-to-json -hello"
200+ test_command_rise_error json-to-graph-bad_arg " json-to-graph -hello"
207201}
208202
209203basic_test () {
210- test run-arf-to-graph " arf-to-graph -o ${tmp_dir_src} ${test_file_src} fips"
211- test run-arf-to-json " arf-to-json -o ${tmp_json_file_src} ${test_file_src} fips"
212- test run-json-to-graph " json-to-graph -o ${tmp_dir_src} ${tmp_json_file_src} fips"
204+ test_command run-arf-to-graph " arf-to-graph -o ${tmp_dir_src} ${test_file_src} fips"
205+ test_command run-arf-to-json " arf-to-json -o ${tmp_json_file_src} ${test_file_src} fips"
206+ test_command run-json-to-graph " json-to-graph -o ${tmp_dir_src} ${tmp_json_file_src} fips"
213207}
214208
215209regex_and_all_test () {
216- test run-arf-to-graph_regex " arf-to-graph -o ${tmp_dir_src} ${test_file_src} -a _package_\w+_removed"
217- test run-arf-to-json_regex " arf-to-json -o ${tmp_json_file_src} ${test_file_src} -a _package_\w+_removed"
218- test run-json-to-graph_regex " json-to-graph -o ${tmp_dir_src} ${tmp_json_file_src} -a _package_\w+_removed"
210+ test_command run-arf-to-graph_regex " arf-to-graph -o ${tmp_dir_src} ${test_file_src} -a _package_\w+_removed"
211+ test_command run-arf-to-json_regex " arf-to-json -o ${tmp_json_file_src} ${test_file_src} -a _package_\w+_removed"
212+ test_command run-json-to-graph_regex " json-to-graph -o ${tmp_dir_src} ${tmp_json_file_src} -a _package_\w+_removed"
219213}
220214
221215regex_and_all_in_one_test () {
222- test run-arf-to-graph_regex " arf-to-graph -o ${tmp_dir_src} ${test_file_src} -i _package_\w+_removed"
223- test run-json-to-graph_regex " json-to-graph -o ${tmp_dir_src} ${tmp_json_file_src} -i _package_\w+_removed"
216+ test_command run-arf-to-graph_regex " arf-to-graph -o ${tmp_dir_src} ${test_file_src} -i _package_\w+_removed"
217+ test_command run-json-to-graph_regex " json-to-graph -o ${tmp_dir_src} ${tmp_json_file_src} -i _package_\w+_removed"
224218}
225219
226220hide_all_passing_tests_test () {
227- test run-arf-to-graph " arf-to-graph -o ${tmp_dir_src} ${test_file_src} --hide-passing-tests fips"
228- test run-json-to-graph " json-to-graph -o ${tmp_dir_src} ${tmp_json_file_src} --hide-passing-tests -i fips"
221+ test_command run-arf-to-graph " arf-to-graph -o ${tmp_dir_src} ${test_file_src} --hide-passing-tests fips"
222+ test_command run-json-to-graph " json-to-graph -o ${tmp_dir_src} ${tmp_json_file_src} --hide-passing-tests -i fips"
229223}
230224
225+
226+ # Backup descriptors stdout -> 3, stderr -> 4
227+ exec 3>&1 4>&2
228+
229+ # Redirect stdout and stderr to file
230+ exec & > test_commands.log
231+
231232if [ " $_arg_install_oval_graph " = " on" ]; then
232233 install_package_from_source
233234fi
@@ -244,5 +245,12 @@ hide_all_passing_tests_test
244245if [ " $_arg_clean " = " on" ]; then
245246 clean " ${tmp_dir_src} "
246247fi
248+
249+ if [[ (" $_arg_verbose " = " on" ) || ($overall_test_result -eq 1) ]]; then
250+ # Restore descriptors
251+ exec 1>&3 2>&4
252+ cat test_commands.log
253+ fi
254+
247255exit " $overall_test_result "
248256# ] <-- needed because of Argbash
0 commit comments