|
1 | 1 | #!/usr/bin/env sh |
2 | | - |
3 | 2 | # Synopsis: |
4 | 3 | # Run the test runner on a solution. |
5 | | - |
6 | 4 | # Arguments: |
7 | 5 | # $1: exercise slug |
8 | 6 | # $2: path to solution folder |
@@ -33,28 +31,24 @@ echo "${slug}: testing..." |
33 | 31 |
|
34 | 32 | # Run the tests for the provided implementation file and redirect stdout and |
35 | 33 | # stderr to capture it |
36 | | -test_output=$(false) |
37 | | -# TODO: substitute "false" with the actual command to run the test: |
38 | | -# test_output=$(command_to_run_tests 2>&1) |
| 34 | +test_output="$(nu "$solution_dir/tests.nu" 2>&1)" |
39 | 35 |
|
40 | 36 | # Write the results.json file based on the exit code of the command that was |
41 | 37 | # just executed that tested the implementation file |
42 | 38 | if [ $? -eq 0 ]; then |
43 | | - jq -n '{version: 1, status: "pass"}' > ${results_file} |
| 39 | + jq -n '{version: 1, status: "pass"}' > "${results_file}" |
44 | 40 | else |
45 | | - # OPTIONAL: Sanitize the output |
46 | | - # In some cases, the test output might be overly verbose, in which case stripping |
47 | | - # the unneeded information can be very helpful to the student |
48 | | - # sanitized_test_output=$(printf "${test_output}" | sed -n '/Test results:/,$p') |
49 | | - |
50 | | - # OPTIONAL: Manually add colors to the output to help scanning the output for errors |
51 | | - # If the test output does not contain colors to help identify failing (or passing) |
52 | | - # tests, it can be helpful to manually add colors to the output |
53 | | - # colorized_test_output=$(echo "${test_output}" \ |
54 | | - # | GREP_COLOR='01;31' grep --color=always -E -e '^(ERROR:.*|.*failed)$|$' \ |
55 | | - # | GREP_COLOR='01;32' grep --color=always -E -e '^.*passed$|$') |
56 | | - |
57 | | - jq -n --arg output "${test_output}" '{version: 1, status: "fail", message: $output}' > ${results_file} |
| 41 | + status="error" |
| 42 | + case "$test_output" in |
| 43 | + *"Assertion failed"*) |
| 44 | + status="fail" |
| 45 | + ;; |
| 46 | + esac |
| 47 | + |
| 48 | + # Remove file paths specific to the local machine from the output |
| 49 | + test_output=$(echo "$test_output" | sed 's|[^ ]*/\([^ ]*\)|\1|g') |
| 50 | + |
| 51 | + jq -n --arg output "$test_output" --arg status "$status" '{version: 1, status: $status, message: $output}' > "${results_file}" |
58 | 52 | fi |
59 | 53 |
|
60 | 54 | echo "${slug}: done" |
0 commit comments