@@ -31,30 +31,30 @@ mkdir -p "${output_dir}"
3131
3232echo " ${slug} : testing..."
3333
34+ # Copy solution to a writable temp directory (lake needs to write build files)
35+ tmp_dir=$( mktemp -d)
36+ cp -r " ${solution_dir} /." " ${tmp_dir} "
37+ cd " ${tmp_dir} "
38+
3439# Run the tests for the provided implementation file and redirect stdout and
3540# 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)
41+ test_output=$( lake test 2>&1 )
42+ exit_code=$?
43+
44+ # Clean up temp directory
45+ rm -rf " ${tmp_dir} "
3946
40- # Write the results.json file based on the exit code of the command that was
47+ # Write the results.json file based on the exit code of the command that was
4148# just executed that tested the implementation file
42- if [ $? -eq 0 ]; then
49+ if [ ${exit_code} -eq 0 ]; then
4350 jq -n ' {version: 1, status: "pass"}' > ${results_file}
4451else
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}
52+ # Check if this is a compilation/syntax error vs test failure
53+ if echo " ${test_output} " | grep -q " error:" ; then
54+ jq -n --arg output " ${test_output} " ' {version: 1, status: "error", message: $output}' > ${results_file}
55+ else
56+ jq -n --arg output " ${test_output} " ' {version: 1, status: "fail", message: $output}' > ${results_file}
57+ fi
5858fi
5959
6060echo " ${slug} : done"
0 commit comments