-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
run.sh
executable file
·52 lines (39 loc) · 1.57 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
#!/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%/}"
tests_file="test.sml"
results_file="${output_dir}/results.json"
# Create the output directory if it doesn't exist
mkdir -p "${output_dir}"
echo "${slug}: testing..."
pushd "${input_dir}" > /dev/null
# Run the tests for the provided implementation file and redirect stdout and
# stderr to capture it
test_output=$(cat "${tests_file}" | poly --error-exit -q 2>&1)
exit_code=$?
popd > /dev/null
# Write the results.json file based on the exit code of the command that was
# just executed that tested the implementation file
if [ $exit_code -eq 0 ]; then
jq -n '{version: 1, status: "pass"}' > ${results_file}
else
jq -n --arg output "${test_output}" '{version: 1, status: "fail", message: $output}' > ${results_file}
fi
echo "${slug}: done"