-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathrun.sh
executable file
·66 lines (47 loc) · 2.08 KB
/
run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env bash
# Synopsis:
# Run the test runner on a solution.
# Arguments:
# $1: exercise slug
# $2: absolute path to solution folder
# $3: absolute path to output directory
# Output:
# Writes the test results to a results.json file in the passed-in output directory.
# The test results are formatted according to the specifications at https://github.com/exercism/docs/blob/main/building/tooling/test-runners/interface.md
# Example:
# ./bin/run.sh two-fer /absolute/path/to/two-fer/solution/folder/ /absolute/path/to/output/directory/
# If any required arguments is missing, print the usage and exit
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
echo "usage: ./bin/run.sh exercise-slug /absolute/path/to/two-fer/solution/folder/ /absolute/path/to/output/directory/"
exit 1
fi
slug="$1"
input_dir="${2%/}"
output_dir="${3%/}"
test_runner_jar=/opt/test-runner/target/scala-3.4.2/TestRunner-assembly-0.1.0-SNAPSHOT.jar
workdir=/tmp/exercise
workdir_target="${workdir}/target"
tests_reports_folder="${workdir}/test-reports"
results_file="${output_dir}/results.json"
build_log_file="${output_dir}/build.log"
runner_log_file="${output_dir}/runner.log"
# Create the output directory if it doesn't exist
mkdir -p "${output_dir}"
# ensure a clean workdir
rm -rf "${workdir}"
mkdir -p "${workdir}"
mkdir -p "${workdir_target}"
echo
echo "${slug}: testing..."
cp -R "${input_dir}"/src "${workdir}"
# Enable all pending tests
sed -i 's/pending//g' "${workdir}"/src/test/scala/*
# compile source and tests
scalac -classpath "${test_runner_jar}" -d "${workdir_target}" "${workdir}"/src/main/scala/* "${workdir}"/src/test/scala/* &> "${build_log_file}"
# run tests
scala -classpath "${test_runner_jar}" org.scalatest.tools.Runner -R "${workdir_target}" -u "${workdir}"/test-reports
# Write the results.json file in the exercism format
java -jar "${test_runner_jar}" "${build_log_file}" "${tests_reports_folder}" "${results_file}" &> "${runner_log_file}"
# change workdir back to the original input_dir in the final results file
sed -i "s~${workdir}~${input_dir}~g" "${results_file}"
echo "${slug}: done"