From 2e0d6c2597eb5aed4663638d2e1acc735bf1f593 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Thu, 9 May 2024 00:44:34 -0400 Subject: [PATCH] tests/utils/utils.sh: bt_diff(): validate that both files exist 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 Change-Id: I259123f5c0946ece7f58e4ef185313bf26354b46 Reviewed-on: https://review.lttng.org/c/babeltrace/+/12534 Tested-by: jenkins --- tests/plugins/src.ctf.fs/field/test-field.sh | 2 +- tests/utils/utils.sh | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/plugins/src.ctf.fs/field/test-field.sh b/tests/plugins/src.ctf.fs/field/test-field.sh index df035d36..72e4e4f5 100755 --- a/tests/plugins/src.ctf.fs/field/test-field.sh +++ b/tests/plugins/src.ctf.fs/field/test-field.sh @@ -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) diff --git a/tests/utils/utils.sh b/tests/utils/utils.sh index 692def5d..f3d4d945 100644 --- a/tests/utils/utils.sh +++ b/tests/utils/utils.sh @@ -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 } -- 2.34.1