tests/utils/utils.sh: bt_diff(): validate that both files exist
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 9 May 2024 04:44:34 +0000 (00:44 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 10 May 2024 18:12:28 +0000 (14:12 -0400)
Otherwise bt_diff() returns 0 (happy) with a nonexistent file.

This change reveals that `tests/plugins/src.ctf.fs/field/test-field.sh`
passes, but for the wrong reason: run_python() doesn't exist (I replaced
it with bt_run_in_py_env() a while ago), therefore that line doesn't
create any expectation file and bt_diff() returns 0. Change it to
use bt_run_in_py_env().

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I259123f5c0946ece7f58e4ef185313bf26354b46
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12534
Tested-by: jenkins <jenkins@lttng.org>
tests/plugins/src.ctf.fs/field/test-field.sh
tests/utils/utils.sh

index df035d36509f6551ac6179fdbe9bc091fb353410..72e4e4f58c09e68ed135fd689bb4301f8670ddff 100755 (executable)
@@ -22,7 +22,7 @@ test_pass() {
     local -r mp_path=$1
     local -r output_dir=$(mktemp -d)
 
-    run_python "$BT_TESTS_PYTHON_BIN" "$data_dir/data_from_mp.py" "$mp_path" "$output_dir"
+    bt_run_in_py_env "$BT_TESTS_PYTHON_BIN" "$data_dir/data_from_mp.py" "$mp_path" "$output_dir"
 
     local -r res_path=$(mktemp)
 
index 692def5d7656d58e7b68e39b99481b038dbdf401..f3d4d94572482114443dd0f21dbbbb67bf78d18e 100644 (file)
@@ -239,6 +239,16 @@ bt_diff() {
        local -r expected_file=$1
        local -r actual_file=$2
 
+       if [[ ! -e $expected_file ]]; then
+               echo "ERROR: expected file \`$expected_file\` doesn't exist" >&2
+               return 1
+       fi
+
+       if [[ ! -e $actual_file ]]; then
+               echo "ERROR: actual file \`$actual_file\` doesn't exist" >&2
+               return 1
+       fi
+
        diff -u <(bt_remove_cr_inline "$expected_file") <(bt_remove_cr_inline "$actual_file") 1>&2
 }
 
This page took 0.040937 seconds and 4 git commands to generate.