Skip to content

Commit

Permalink
Run shellcheck in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
mernst committed May 28, 2024
1 parent 4d1479e commit aeac31f
Show file tree
Hide file tree
Showing 17 changed files with 204 additions and 167 deletions.
16 changes: 8 additions & 8 deletions framework/lib/test_generation/bin/_tool.template
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,25 @@ if [ -z "$D4J_DIR_TESTGEN_BIN" ]; then
fi

# General helper functions
source $D4J_DIR_TESTGEN_BIN/_tool.source
. "$D4J_DIR_TESTGEN_BIN"/_tool.source

# The classpath to compile and run the project
project_cp=$(get_project_cp)
project_cp="$(get_project_cp)"

# Read all additional configuration parameters
add_config=$(parse_config $D4J_DIR_TESTGEN_BIN/<generator id>.config)
add_config=$(parse_config "$D4J_DIR_TESTGEN_BIN"/<generator id>.config)

# Make sure the provided test mode is supported
if [ $D4J_TEST_MODE == "regression" ]; then
...
elif [ $D4J_TEST_MODE == "error-revealing" ]; then
...
if [ "$D4J_TEST_MODE" = "regression" ]; then
: # TODO ...
elif [ "$D4J_TEST_MODE" = "error-revealing" ]; then
: # TODO ...
else
die "Unsupported test mode: $D4J_TEST_MODE"
fi

# The command that invokes the test generator
cmd="... $add_config"
cmd="... $add_config ... $project_cp ..."

# Run the test-generation command
if ! exec_cmd "$cmd"; then
Expand Down
13 changes: 7 additions & 6 deletions framework/lib/test_generation/bin/evosuite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ if [ -z "$D4J_DIR_TESTGEN_BIN" ]; then
fi

# General helper functions
source $D4J_DIR_TESTGEN_BIN/_tool.source
source "$D4J_DIR_TESTGEN_BIN"/_tool.source

# The classpath to compile and run the project
project_cp=$(get_project_cp)

# Read all additional configuration parameters
add_config=$(parse_config $D4J_DIR_TESTGEN_BIN/evosuite.config)
add_config=$(parse_config "$D4J_DIR_TESTGEN_BIN"/evosuite.config)

# Make sure the provided test mode is supported
if [ $D4J_TEST_MODE != "regression" ]; then
if [ "$D4J_TEST_MODE" != "regression" ]; then
die "Unsupported test mode: $D4J_TEST_MODE"
fi

Expand All @@ -47,10 +47,11 @@ if [[ $(tail -c1 "$D4J_FILE_TARGET_CLASSES" | wc -l) -eq 0 ]]; then
fi

# Compute the budget per target class; evenly split the time for search and assertions
num_classes=$(cat $D4J_FILE_TARGET_CLASSES | wc -l)
num_classes=$(wc -l "$D4J_FILE_TARGET_CLASSES")
budget=$(echo "$D4J_TOTAL_BUDGET/2/$num_classes" | bc)

for class in $(cat $D4J_FILE_TARGET_CLASSES); do
while IFS= read -r class ; do
#shellcheck disable=SC2153 # D4J_DIR_TESTGEN_LIB is not a typo of D4J_DIR_TESTGEN_BIN
cmd="java -cp $D4J_DIR_TESTGEN_LIB/evosuite-current.jar org.evosuite.EvoSuite \
-class $class \
-projectCP $project_cp \
Expand All @@ -64,4 +65,4 @@ for class in $(cat $D4J_FILE_TARGET_CLASSES); do
if ! exec_cmd "$cmd"; then
exit 1
fi
done
done < "$D4J_FILE_TARGET_CLASSES"
3 changes: 2 additions & 1 deletion framework/lib/test_generation/bin/randoop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ REG_BASE_NAME=RegressionTest
ERR_BASE_NAME=ErrorTest

# Print Randoop version
#shellcheck disable=SC2153 # D4J_DIR_TESTGEN_LIB is not a typo of D4J_DIR_TESTGEN_BIN
version=$(java -cp "$D4J_DIR_TESTGEN_LIB/randoop-current.jar" randoop.main.Main | head -1)
printf "\n(%s)" "$version" >&2
printf ".%.0s" {1..expr 73 - length "$version"} >&2
printf ".%.0s" \{1..expr 73 - length "$version"\} >&2
printf " " >&2

# The most common package in file $D4J_FILE_TARGET_CLASSES.
Expand Down
6 changes: 3 additions & 3 deletions framework/projects/Mockito/chooseDepedencyVersion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
# $1 = workDir
# $2 = D4J_HOME

cd $1
cd "$1" || (echo "cannot cd to workdir $1" && exit 1)
./gradlew dependencies >> tmpDepend.txt
if grep -q buddy tmpDepend.txt; then
version=`cat tmpDepend.txt | grep buddy | cut -d: -f 3 | head -1`
cp $2/framework/projects/Mockito/byte-buddy/byte-buddy-$version.jar $1/compileLib/
version=$(grep buddy tmpDepend.txt | cut -d: -f 3 | head -1)
cp "$2/framework/projects/Mockito/byte-buddy/byte-buddy-$version.jar" "$1"/compileLib/
fi
rm tmpDepend.txt
12 changes: 7 additions & 5 deletions framework/projects/Mockito/setMutationCompiler.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
# $1 = working directory
# $2 = location of Defects4J (D4J_HOME)

WORK_DIR=$1
D4J_HOME=$2
WORK_DIR="$1"
D4J_HOME="$2"

BUILD_FILE="build.gradle"

echo >> $WORK_DIR/$BUILD_FILE
echo "compileJava.options.fork = true" >> $WORK_DIR/$BUILD_FILE
echo "compileJava.options.forkOptions.executable = '$D4J_HOME/major/bin/major'" >> $WORK_DIR/$BUILD_FILE
{
echo;
echo "compileJava.options.fork = true";
echo "compileJava.options.forkOptions.executable = '$D4J_HOME/major/bin/major'";
} >> "$WORK_DIR/$BUILD_FILE"
15 changes: 9 additions & 6 deletions framework/test/get_klocs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
################################################################################

# Must use Java version 8.
JAVA_VERSION_STRING=`java -version 2>&1 | head -1`
JAVA_RELEASE_NUMBER=`echo $JAVA_VERSION_STRING | sed 's/^.*1\.\(.\).*/\1/'`
JAVA_VERSION_STRING=$(java -version 2>&1 | head -1)
# shellcheck disable=SC2001 # variable substitution does not suffice; need sed.
JAVA_RELEASE_NUMBER=$(echo "$JAVA_VERSION_STRING" | sed 's/^.*1\.\(.\).*/\1/')
if [[ "$JAVA_RELEASE_NUMBER" != "8" ]]; then
echo Must use Java version 8
exit
Expand Down Expand Up @@ -37,18 +38,20 @@ if [ -z "$1" ] ; then
bids=( 1 2 3 4 5 )
else
# Generate tests for supplied project list
# shellcheck disable=SC2206
projects=( $1 )
if [ -z "$2" ] ; then
# Generate tests for all bids
bids=( 1 2 3 4 5 )
else
# Generate tests for supplied bid list
# shellcheck disable=SC2206
bids=( $2 )
fi
fi

echo "Projects: ${projects[@]}"
echo "Bug ids: ${bids[@]}"
echo "Projects: " "${projects[@]}"
echo "Bug ids: " "${bids[@]}"

# We want the 'fixed' version of the sample.
type=f
Expand All @@ -57,9 +60,9 @@ for pid in "${projects[@]}"; do
for bid in "${bids[@]}"; do
vid=${bid}$type

run_klocs.pl -p $pid -v $vid -n 1 -o $randoop_dir || die "run klocs on $pid-$vid"
run_klocs.pl -p "$pid" -v "$vid" -n 1 -o "$randoop_dir" || die "run klocs on $pid-$vid"
done
done

# delete tmp file directory
rm -rf $randoop_dir
rm -rf "$randoop_dir"
77 changes: 38 additions & 39 deletions framework/test/test_bug_mining.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

set -e

HERE=$(cd `dirname $0` && pwd)
HERE=$(cd "$(dirname "$0")" && pwd) || (echo "cannot cd to $(dirname "$0")" && exit 1)

# Import helper subroutines and variables, and init Defects4J
source "$HERE/test.include" || exit 1
Expand All @@ -31,8 +31,7 @@ _check_output() {
sort "$actual" > "$actual.sorted"
sort "$expected" > "$expected.sorted"

cmp --silent "$expected.sorted" "$actual.sorted"
if [ $? -ne 0 ]; then
if ! cmp --silent "$expected.sorted" "$actual.sorted" ; then
rm -f "$actual.sorted" "$expected.sorted"
die "'$actual' is not equal to '$expected'!"
fi
Expand All @@ -49,11 +48,11 @@ fi
# remote resource is newer. Works around connections that hang. Takes a
# single command-line argument, a URL.
download_url() {
BASENAME=`basename ${@: -1}`
BASENAME=$(basename "${@: -1}")
if [ "$(uname)" = "Darwin" ] ; then
wget -nv -N "$@"
else
timeout 300 curl -s -S -R -L -O -z "$BASENAME" "$@" || (echo "retrying curl $@" && rm -f "$BASENAME" && curl -R -L -O -z "$BASENAME" "$@")
timeout 300 curl -s -S -R -L -O -z "$BASENAME" "$@" || (echo "retrying curl $*" && rm -f "$BASENAME" && curl -R -L -O -z "$BASENAME" "$@")
fi
}

Expand All @@ -69,8 +68,8 @@ test_create_project() {
local repository_url="$4"

pushd . > /dev/null 2>&1
cd $BUG_MINING_FRAMEWORK_DIR
./create-project.pl -p $project_id -n $project_name -w $work_dir -r $repository_url || die "Create project script has failed"
cd "$BUG_MINING_FRAMEWORK_DIR"
./create-project.pl -p "$project_id" -n "$project_name" -w "$work_dir" -r "$repository_url" || die "Create project script has failed"
popd > /dev/null 2>&1

# Check whether expected directories exist
Expand Down Expand Up @@ -115,8 +114,8 @@ test_download_issues() {
local issues_file="$work_dir/issues.txt"

pushd . > /dev/null 2>&1
cd $BUG_MINING_FRAMEWORK_DIR
./download-issues.pl -g $issue_tracker_name -t $issue_tracker_project_id -o $issues_dir -f $issues_file || die "Download of all issues from the issue tracker has failed"
cd "$BUG_MINING_FRAMEWORK_DIR"
./download-issues.pl -g "$issue_tracker_name" -t "$issue_tracker_project_id" -o "$issues_dir" -f "$issues_file" || die "Download of all issues from the issue tracker has failed"
popd > /dev/null 2>&1

# Check whether expected files exist
Expand All @@ -139,11 +138,11 @@ test_crossref_commmit_issue() {
local issues_file="$work_dir/issues.txt"
local commit_db_file="$work_dir/framework/projects/$project_id/$BUGS_CSV_ACTIVE"

git --git-dir=$repository_dir log --reverse > $git_log_file || die "Git log has failed"
git --git-dir="$repository_dir" log --reverse > "$git_log_file" || die "Git log has failed"

pushd . > /dev/null 2>&1
cd $BUG_MINING_FRAMEWORK_DIR
./vcs-log-xref.pl -e $regex -l $git_log_file -r $repository_dir -i $issues_file -f $commit_db_file || die "Crossreference of commits and issues ids has failed"
cd "$BUG_MINING_FRAMEWORK_DIR"
./vcs-log-xref.pl -e "$regex" -l "$git_log_file" -r "$repository_dir" -i "$issues_file" -f "$commit_db_file" || die "Crossreference of commits and issues ids has failed"
popd > /dev/null 2>&1

# Check whether expected files exist
Expand Down Expand Up @@ -172,16 +171,16 @@ test_initialize_revisions() {
mkdir -p "$lib_dir"

mkdir -p "$lib_dir/junit/junit/4.12"
(cd "$lib_dir/junit/junit/4.12" && download_url https://repo1.maven.org/maven2/junit/junit/4.12/junit-4.12.jar || die "Failed to download junit-4.12.jar")
(cd "$lib_dir/junit/junit/4.12" && download_url https://repo1.maven.org/maven2/junit/junit/4.12/junit-4.12.jar) || die "Failed to download junit-4.12.jar"
mkdir -p "$lib_dir/org/apache/commons/commons-lang3/3.4"
(cd "$lib_dir/org/apache/commons/commons-lang3/3.4" && download_url https://repo1.maven.org/maven2/org/apache/commons/commons-lang3/3.4/commons-lang3-3.4.jar || die "Failed to download commons-lang3-3.4.jar")
(cd "$lib_dir/org/apache/commons/commons-lang3/3.4" && download_url https://repo1.maven.org/maven2/org/apache/commons/commons-lang3/3.4/commons-lang3-3.4.jar) || die "Failed to download commons-lang3-3.4.jar"
mkdir -p "$lib_dir/org/hamcrest/hamcrest-core/1.3"
(cd "$lib_dir/org/hamcrest/hamcrest-core/1.3" && download_url https://repo1.maven.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar || die "Failed to download hamcrest-core-1.3.jar")
(cd "$lib_dir/org/hamcrest/hamcrest-core/1.3" && download_url https://repo1.maven.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar) || die "Failed to download hamcrest-core-1.3.jar"
# End of fix for Java-7

pushd . > /dev/null 2>&1
cd $BUG_MINING_FRAMEWORK_DIR
./initialize-revisions.pl -p $project_id -w $work_dir -b $bug_id || die "Initialize revisions script has failed"
cd "$BUG_MINING_FRAMEWORK_DIR"
./initialize-revisions.pl -p "$project_id" -w "$work_dir" -b "$bug_id" || die "Initialize revisions script has failed"
popd > /dev/null 2>&1

local analyzer_output_dir="framework/projects/$project_id/analyzer_output/$bug_id"
Expand All @@ -192,10 +191,10 @@ test_initialize_revisions() {
_check_output "$work_dir/$analyzer_output_dir/info" "$RESOURCES_OUTPUT_DIR/$analyzer_output_dir/info"

local commit_db_file="$work_dir/framework/projects/$project_id/$BUGS_CSV_ACTIVE"
local rev_v1=$(grep "^$bug_id," "$commit_db_file" | cut -f2 -d',')
local rev_v2=$(grep "^$bug_id," "$commit_db_file" | cut -f3 -d',')
local rev_v1_build_dir="$work_dir/framework/projects/$project_id/build_files/$rev_v1"
local rev_v2_build_dir="$work_dir/framework/projects/$project_id/build_files/$rev_v2"
local rev_v1; rev_v1=$(grep "^$bug_id," "$commit_db_file" | cut -f2 -d',')
local rev_v2; rev_v2=$(grep "^$bug_id," "$commit_db_file" | cut -f3 -d',')
local rev_v1_build_dir; rev_v1_build_dir="$work_dir/framework/projects/$project_id/build_files/$rev_v1"
local rev_v2_build_dir; rev_v2_build_dir="$work_dir/framework/projects/$project_id/build_files/$rev_v2"
[ -s "$rev_v1_build_dir/build.xml" ] || die "$rev_v1_build_dir/build.xml does not exist or it is empty"
[ -s "$rev_v1_build_dir/maven-build.properties" ] || die "$rev_v1_build_dir/maven-build.properties does not exist or it is empty"
[ -s "$rev_v1_build_dir/maven-build.xml" ] || die "$rev_v1_build_dir/maven-build.xml does not exist or it is empty"
Expand Down Expand Up @@ -225,18 +224,18 @@ test_analyze_project() {
local bug_id="$5"

pushd . > /dev/null 2>&1
cd $BUG_MINING_FRAMEWORK_DIR
./analyze-project.pl -p $project_id -w $work_dir -g $issue_tracker_name -t $issue_tracker_project_id -b $bug_id || die "Analyze project script has failed"
cd "$BUG_MINING_FRAMEWORK_DIR"
./analyze-project.pl -p "$project_id" -w "$work_dir" -g "$issue_tracker_name" -t "$issue_tracker_project_id" -b "$bug_id" || die "Analyze project script has failed"
popd > /dev/null 2>&1

local commit_db_file="$work_dir/framework/projects/$project_id/$BUGS_CSV_ACTIVE"
local rev_v2=$(grep "^$bug_id," "$commit_db_file" | cut -f3 -d',')
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"
[ -s "$work_dir/$failing_tests" ] || die "No failing test cases has been reported"

# Same number of failing tests
local actual_num_failing_tests=$(grep -a "^--- " "$work_dir/$failing_tests" | wc -l)
local expected_num_failing_tests=$(grep -a "^--- " "$RESOURCES_OUTPUT_DIR/$failing_tests" | wc -l)
local actual_num_failing_tests; actual_num_failing_tests=$(grep -c -a "^--- " "$work_dir/$failing_tests")
local expected_num_failing_tests; expected_num_failing_tests=$(grep -c -a "^--- " "$RESOURCES_OUTPUT_DIR/$failing_tests")
[ "$actual_num_failing_tests" -eq "$expected_num_failing_tests" ] || die "Expected $expected_num_failing_tests failing tests and got $actual_num_failing_tests"

# Same failing tests
Expand All @@ -256,16 +255,16 @@ test_get_trigger() {
local bug_id="$3"

pushd . > /dev/null 2>&1
cd $BUG_MINING_FRAMEWORK_DIR
./get-trigger.pl -p $project_id -w $work_dir -b $bug_id || die "Get list of triggering test cases has failed"
cd "$BUG_MINING_FRAMEWORK_DIR"
./get-trigger.pl -p "$project_id" -w "$work_dir" -b "$bug_id" || die "Get list of triggering test cases has failed"
popd > /dev/null 2>&1

local trigger_tests="framework/projects/$project_id/trigger_tests/$bug_id"
[ -s "$work_dir/$trigger_tests" ] || die "List of triggering test cases is empty or does not exist"

# Same number of trigger tests
local actual_num_trigger_tests=$(grep -a "^--- " "$work_dir/$trigger_tests" | wc -l)
local expected_num_trigger_tests=$(grep -a "^--- " "$RESOURCES_OUTPUT_DIR/$trigger_tests" | wc -l)
local actual_num_trigger_tests; actual_num_trigger_tests=$(grep -c -a "^--- " "$work_dir/$trigger_tests")
local expected_num_trigger_tests; expected_num_trigger_tests=$(grep -c -a "^--- " "$RESOURCES_OUTPUT_DIR/$trigger_tests")
[ "$actual_num_trigger_tests" -eq "$expected_num_trigger_tests" ] || die "Expected $expected_num_trigger_tests trigger tests and got $actual_num_trigger_tests"

# Same trigger tests
Expand All @@ -285,8 +284,8 @@ test_get_metadata() {
local bug_id="$3"

pushd . > /dev/null 2>&1
cd $BUG_MINING_FRAMEWORK_DIR
./get-metadata.pl -p $project_id -w $work_dir -b $bug_id || die "Metadata extraction has failed"
cd "$BUG_MINING_FRAMEWORK_DIR"
./get-metadata.pl -p "$project_id" -w "$work_dir" -b "$bug_id" || die "Metadata extraction has failed"
popd > /dev/null 2>&1

local relevant_tests="framework/projects/$project_id/relevant_tests/$bug_id"
Expand Down Expand Up @@ -317,26 +316,26 @@ test_promote_to_db() {
local repository_dir="$work_dir/project_repos/$project_name.git"

pushd . > /dev/null 2>&1
cd $BUG_MINING_FRAMEWORK_DIR
./promote-to-db.pl -p $project_id -w $work_dir -r $repository_dir -b $bug_id || die "Promotion of $project_id-$bug_id has failed"
cd "$BUG_MINING_FRAMEWORK_DIR"
./promote-to-db.pl -p "$project_id" -w "$work_dir" -r "$repository_dir" -b "$bug_id" || die "Promotion of $project_id-$bug_id has failed"
popd > /dev/null 2>&1

_check_output "$HERE/../core/Project/$project_id.pm" "$work_dir/framework/core/Project/$project_id.pm"

[ -d "$HERE/../projects/$project_id" ] || die "Project directory does not exist"

local commit_db_file="$work_dir/framework/projects/$project_id/$BUGS_CSV_ACTIVE"
local rev_v1=$(grep "^$bug_id," "$commit_db_file" | cut -f2 -d',')
local rev_v2=$(grep "^$bug_id," "$commit_db_file" | cut -f3 -d',')
local rev_v1; rev_v1=$(grep "^$bug_id," "$commit_db_file" | cut -f2 -d',')
local rev_v2; rev_v2=$(grep "^$bug_id," "$commit_db_file" | cut -f3 -d',')

local failing_tests="projects/$project_id/failing_tests/$rev_v2"
_check_output "$HERE/../$failing_tests" "$work_dir/framework/$failing_tests"

for dir in "build_files/$rev_v1" "build_files/$rev_v2"; do
while read -r f; do
f_name=$(basename $f)
f_name=$(basename "$f")
_check_output "$HERE/../projects/$project_id/$dir/$f_name" "$f"
done < <(find "$(cd $work_dir/framework/projects/$project_id/$dir; pwd)" -type f)
done < <(find "$(cd "$work_dir/framework/projects/$project_id/$dir"; pwd)" -type f)
done

local loaded_classes="projects/$project_id/loaded_classes"
Expand Down Expand Up @@ -420,7 +419,7 @@ if [ "$ERROR" -ne "0" ]; then
printf '=%.s' $(seq 1 80) 1>&2
echo 1>&2
echo "The following errors occurred:" 1>&2
cat $LOG 1>&2
cat "$LOG" 1>&2
fi

# Indicate whether an error occurred
Expand Down
Loading

0 comments on commit aeac31f

Please sign in to comment.