From 7e46c73b75cf837e6a40305e3790e966ab0a16ec Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Sun, 15 Sep 2024 06:39:46 -0700 Subject: [PATCH] Use grouping, not subshell --- framework/projects/Mockito/chooseDepedencyVersion.sh | 2 +- framework/test/test_bug_mining.sh | 4 ++-- framework/test/test_cp.sh | 2 +- framework/test/test_d4j_query.sh | 2 +- framework/test/test_export_command.sh | 8 ++++---- framework/test/test_fix_test_suite.sh | 8 ++++---- framework/test/test_gen_tests.sh | 2 +- framework/test/test_monitor_test.sh | 2 +- framework/test/test_mutation_analysis.sh | 2 +- framework/test/test_sanity_check.sh | 2 +- framework/test/test_style.sh | 4 ++-- framework/test/test_tutorial.sh | 4 ++-- framework/test/test_verify_bugs.sh | 2 +- 13 files changed, 22 insertions(+), 22 deletions(-) diff --git a/framework/projects/Mockito/chooseDepedencyVersion.sh b/framework/projects/Mockito/chooseDepedencyVersion.sh index 490f70bb2..4fcac44a8 100755 --- a/framework/projects/Mockito/chooseDepedencyVersion.sh +++ b/framework/projects/Mockito/chooseDepedencyVersion.sh @@ -4,7 +4,7 @@ # $1 = workDir # $2 = D4J_HOME -cd "$1" || (echo "cannot cd to workdir $1" && exit 1) +cd "$1" || { echo "cannot cd to workdir $1" && exit 2; } ./gradlew dependencies >> tmpDepend.txt if grep -q buddy tmpDepend.txt; then version=$(grep buddy tmpDepend.txt | head -1 | cut -d: -f 3) diff --git a/framework/test/test_bug_mining.sh b/framework/test/test_bug_mining.sh index b1fcfb523..2ae589cb3 100755 --- a/framework/test/test_bug_mining.sh +++ b/framework/test/test_bug_mining.sh @@ -7,7 +7,7 @@ set -e -HERE="$(cd "$(dirname "$0")" && pwd)" || (echo "cannot cd to $(dirname "$0")" && exit 1) +HERE="$(cd "$(dirname "$0")" && pwd)" || { echo "cannot cd to $(dirname "$0")" && exit 2; } # Import helper subroutines and variables, and init Defects4J source "$HERE/test.include" || exit 1 @@ -282,7 +282,7 @@ test_analyze_project() { local commit_db_file="$work_dir/framework/projects/$project_id/$BUGS_CSV_ACTIVE" local rev_v2; rev_v2=$(grep "^$bug_id," "$commit_db_file" | cut -f3 -d',') local failing_tests="framework/projects/$project_id/failing_tests/$rev_v2" - if [ -e $RESOURCES_OUTPUT_DIR/$failing_tests ]; then + if [ -e "$RESOURCES_OUTPUT_DIR/$failing_tests" ]; then [ -s "$work_dir/$failing_tests" ] || die "No failing test cases has been reported" # Same number of failing tests diff --git a/framework/test/test_cp.sh b/framework/test/test_cp.sh index b65cb8573..2c26ebdb7 100755 --- a/framework/test/test_cp.sh +++ b/framework/test/test_cp.sh @@ -5,7 +5,7 @@ # ################################################################################ -HERE="$(cd "$(dirname "$0")" && pwd)" || (echo "cannot cd to $(dirname "$0")" && exit 1) +HERE="$(cd "$(dirname "$0")" && pwd)" || { echo "cannot cd to $(dirname "$0")" && exit 2; } # Import helper subroutines and variables, and init Defects4J source "$HERE/test.include" || exit 1 diff --git a/framework/test/test_d4j_query.sh b/framework/test/test_d4j_query.sh index 9e5a5a1f4..6d35a1d79 100755 --- a/framework/test/test_d4j_query.sh +++ b/framework/test/test_d4j_query.sh @@ -5,7 +5,7 @@ # ################################################################################ -HERE="$(cd "$(dirname "$0")" && pwd)" || (echo "cannot cd to $(dirname "$0")" && exit 1) +HERE="$(cd "$(dirname "$0")" && pwd)" || { echo "cannot cd to $(dirname "$0")" && exit 2; } # Import helper subroutines and variables, and init Defects4J source "$HERE/test.include" || exit 1 diff --git a/framework/test/test_export_command.sh b/framework/test/test_export_command.sh index ed3daee86..cb933381a 100755 --- a/framework/test/test_export_command.sh +++ b/framework/test/test_export_command.sh @@ -10,7 +10,7 @@ # ################################################################################ -HERE="$(cd "$(dirname "$0")" && pwd)" || (echo "cannot cd to $(dirname "$0")" && exit 1) +HERE="$(cd "$(dirname "$0")" && pwd)" || { echo "cannot cd to $(dirname "$0")" && exit 2; } # Import helper subroutines and variables, and init Defects4J source "$HERE/test.include" || exit 1 @@ -25,12 +25,12 @@ _run_export_command() { local exp_cmp="$2" local exp_out="" - pushd "$work_dir" > /dev/null 2>&1 || (echo "Cannot pushd to $work_dir" && exit 1) + pushd "$work_dir" > /dev/null 2>&1 || { echo "Cannot pushd to $work_dir" && exit 2; } if ! defects4j export -p "$exp_cmp" ; then - popd > /dev/null 2>&1 || (echo "Cannot popd" && exit 1) + popd > /dev/null 2>&1 || { echo "Cannot popd" && exit 2; } return 1 fi - popd > /dev/null 2>&1 || (echo "Cannot popd" && exit 1) + popd > /dev/null 2>&1 || { echo "Cannot popd" && exit 2; } echo "$exp_out" return 0 diff --git a/framework/test/test_fix_test_suite.sh b/framework/test/test_fix_test_suite.sh index 44f11440f..d6cf052c2 100755 --- a/framework/test/test_fix_test_suite.sh +++ b/framework/test/test_fix_test_suite.sh @@ -5,7 +5,7 @@ # ################################################################################ -HERE="$(cd "$(dirname "$0")" && pwd)" || (echo "cannot cd to $(dirname "$0")" && exit 1) +HERE="$(cd "$(dirname "$0")" && pwd)" || { echo "cannot cd to $(dirname "$0")" && exit 2; } # Import helper subroutines and variables, and init Defects4J source "$HERE/test.include" || exit 1 @@ -62,12 +62,12 @@ _create_tar_bz2_file() { local suites_dir="$4" # Create a .tar.bz2 file with all test suites - pushd . > /dev/null 2>&1 || (echo "cannot pushd ." && exit 1) - cd "$HERE/resources/input" || (echo "cannot cd to $HERE/resources/input" && exit 1) + pushd . > /dev/null 2>&1 || { echo "cannot pushd ." && exit 2; } + cd "$HERE/resources/input" || { echo "cannot cd to $HERE/resources/input" && exit 2; } tar_bz2_file="$suites_dir/$pid-$bid-test.0.tar.bz2" # shellcheck disable=SC2086 # $input_files contains multiple files tar -jcvf "$tar_bz2_file" $input_files || return 1 - popd > /dev/null 2>&1 || (echo "cannot popd" && exit 1) + popd > /dev/null 2>&1 || { echo "cannot popd" && exit 2; } return 0 } diff --git a/framework/test/test_gen_tests.sh b/framework/test/test_gen_tests.sh index 04ada7eef..18eb0ac2f 100755 --- a/framework/test/test_gen_tests.sh +++ b/framework/test/test_gen_tests.sh @@ -12,7 +12,7 @@ # ################################################################################ -HERE="$(cd "$(dirname "$0")" && pwd)" || (echo "cannot cd to $(dirname "$0")" && exit 1) +HERE="$(cd "$(dirname "$0")" && pwd)" || { echo "cannot cd to $(dirname "$0")" && exit 2; } # Import helper subroutines and variables, and init Defects4J source "$HERE/test.include" || exit 1 diff --git a/framework/test/test_monitor_test.sh b/framework/test/test_monitor_test.sh index fef880bb2..6174023b9 100755 --- a/framework/test/test_monitor_test.sh +++ b/framework/test/test_monitor_test.sh @@ -6,7 +6,7 @@ # ################################################################################ -HERE="$(cd "$(dirname "$0")" && pwd)" || (echo "cannot cd to $(dirname "$0")" && exit 1) +HERE="$(cd "$(dirname "$0")" && pwd)" || { echo "cannot cd to $(dirname "$0")" && exit 2; } # Import helper subroutines and variables, and init Defects4J source "$HERE/test.include" || exit 1 diff --git a/framework/test/test_mutation_analysis.sh b/framework/test/test_mutation_analysis.sh index fa962d66a..98824c0b5 100755 --- a/framework/test/test_mutation_analysis.sh +++ b/framework/test/test_mutation_analysis.sh @@ -7,7 +7,7 @@ # TODO: There is some code duplication in this test script, which we can avoid # by extracting the mutation analysis workflow into a parameterized function. -HERE="$(cd "$(dirname "$0")" && pwd)" || (echo "cannot cd to $(dirname "$0")" && exit 1) +HERE="$(cd "$(dirname "$0")" && pwd)" || { echo "cannot cd to $(dirname "$0")" && exit 2; } # Import helper subroutines and variables, and init Defects4J source "$HERE/test.include" || exit 1 diff --git a/framework/test/test_sanity_check.sh b/framework/test/test_sanity_check.sh index 49c4dd3be..4a14607a5 100755 --- a/framework/test/test_sanity_check.sh +++ b/framework/test/test_sanity_check.sh @@ -5,7 +5,7 @@ # ################################################################################ -HERE="$(cd "$(dirname "$0")" && pwd)" || (echo "cannot cd to $(dirname "$0")" && exit 1) +HERE="$(cd "$(dirname "$0")" && pwd)" || { echo "cannot cd to $(dirname "$0")" && exit 2; } # Import helper subroutines and variables, and init Defects4J source "$HERE/test.include" || exit 1 diff --git a/framework/test/test_style.sh b/framework/test/test_style.sh index 8e5621406..91c26e00b 100755 --- a/framework/test/test_style.sh +++ b/framework/test/test_style.sh @@ -2,11 +2,11 @@ TOPLEVEL="$(git rev-parse --show-toplevel)" -cd "$TOPLEVEL" || (echo "Cannot cd to $TOPLEVEL" && exit 1) +cd "$TOPLEVEL" || { echo "Cannot cd to $TOPLEVEL" && exit 2; } # Check style of Perl scripts find . \( -name '*.pm' -o -name '*.pl' \) -print0 | xargs -0 -n1 perl -Mstrict -Mdiagnostics -cw -grep -l --exclude-dir=project_repos --exclude=\*.pm --exclude=\*.pl --exclude=\*.sh --exclude=template -r "=pod" . | while IFS= read -r file ; do +grep -l --exclude-dir=project_repos --exclude=\*.pm --exclude=\*.pl --exclude=\*.sh --exclude=\*~ --exclude=template -r "=pod" . | while IFS= read -r file ; do perl -Mstrict -Mdiagnostics -cw "$file" done # Don't run perlcritic yet. diff --git a/framework/test/test_tutorial.sh b/framework/test/test_tutorial.sh index 81007047b..49ab773b6 100755 --- a/framework/test/test_tutorial.sh +++ b/framework/test/test_tutorial.sh @@ -5,7 +5,7 @@ # ################################################################################ -HERE="$(cd "$(dirname "$0")" && pwd)" || (echo "cannot cd to $(dirname "$0")" && exit 1) +HERE="$(cd "$(dirname "$0")" && pwd)" || { echo "cannot cd to $(dirname "$0")" && exit 2; } # Import helper subroutines and variables, and init Defects4J source "$HERE/test.include" || exit 1 @@ -31,7 +31,7 @@ defects4j checkout -p $pid -v $vid -w "$work_dir" || die "checkout program versi grep -q "pid=$pid" "$work_dir"/.defects4j.config || die "verify pid in config file" grep -q "vid=$vid" "$work_dir"/.defects4j.config || die "verify vid in config file" -cd "$work_dir" || (echo "cannot cd to $work_dir" && exit 1) +cd "$work_dir" || { echo "cannot cd to $work_dir" && exit 2; } # Compile buggy version defects4j compile || die "compile program version $pid-$vid" diff --git a/framework/test/test_verify_bugs.sh b/framework/test/test_verify_bugs.sh index c84bdc4c0..744babea6 100755 --- a/framework/test/test_verify_bugs.sh +++ b/framework/test/test_verify_bugs.sh @@ -17,7 +17,7 @@ # ################################################################################ -HERE="$(cd "$(dirname "$0")" && pwd)" || (echo "cannot cd to $(dirname "$0")" && exit 1) +HERE="$(cd "$(dirname "$0")" && pwd)" || { echo "cannot cd to $(dirname "$0")" && exit 2; } # Import helper subroutines and variables, and init Defects4J source "$HERE/test.include" || exit 1