diff --git a/bin/run-tests.sh b/bin/run-tests.sh index 204542d..b760867 100755 --- a/bin/run-tests.sh +++ b/bin/run-tests.sh @@ -22,26 +22,18 @@ for test_dir in tests/*; do bin/run.sh "${test_dir_name}" "${test_dir_path}" "${test_dir_path}" - # OPTIONAL: Normalize the results file - # If the results.json file contains information that changes between - # different test runs (e.g. timing information or paths), you should normalize - # the results file to allow the diff comparison below to work as expected - # sed -i -E \ - # -e 's/Elapsed time: [0-9]+\.[0-9]+ seconds//g' \ - # -e "s~${test_dir_path}~/solution~g" \ - # "${results_file_path}" - # Add trailing newlines. Ignore line numbers. for i in "${results_file_path}" "${expected_results_file_path}"; do - sed 's/:\d\+:/:NN:/g' "${i}" "${i}" > "${i}.cleaned" + sed \ + -e 's/:[0-9]\{1,\}:/:NN:/g' \ + -e '/^{"version": 3, "status": "error"/ s/"message": ".*"}$/"message": ""}/' \ + "${i}" "${i}" > "${i}.cleaned" done echo "${test_dir_name}: comparing results.json to expected_results.json" - diff "${results_file_path}.cleaned" "${expected_results_file_path}.cleaned" - rm "${results_file_path}.cleaned" "${expected_results_file_path}.cleaned" - - if [ $? -ne 0 ]; then + if ! diff "${results_file_path}.cleaned" "${expected_results_file_path}.cleaned"; then exit_code=1 fi + rm "${results_file_path}.cleaned" "${expected_results_file_path}.cleaned" done exit ${exit_code} diff --git a/bin/run.sh b/bin/run.sh index 5db936b..b420940 100755 --- a/bin/run.sh +++ b/bin/run.sh @@ -29,7 +29,7 @@ compilation_errors_file_name="compilation-errors" test_output_file_name="test-output.xml" results_file="${output_dir}/results.json" binary_file="${build_dir}/${slug}" -test_file_path="${build_dir}/${slug//-/_}_test.cpp" +test_file_path="${build_dir}/$(echo "${slug}" | tr - _)_test.cpp" # Create the output directory if it doesn't exist mkdir -p "${output_dir}" @@ -47,7 +47,7 @@ cmake -DEXERCISM_TEST_SUITE=1 -DEXERCISM_RUN_ALL_TESTS=1 . make 2> "${compilation_errors_file_name}" # In case of compilation errors the executable will not be created -[[ -f "./${slug}" ]] && chmod +x "./${slug}" && "./${slug}" -r xml -o "${test_output_file_name}" +[ -f "./${slug}" ] && chmod +x "./${slug}" && "./${slug}" -r xml -o "${test_output_file_name}" /opt/test-runner/bin/exercism_parser "${build_dir}/${test_output_file_name}" "${results_file}" "${build_dir}/${compilation_errors_file_name}" "${test_file_path}" cd - diff --git a/include/helpers.h b/include/helpers.h index c8924bb..6243fae 100644 --- a/include/helpers.h +++ b/include/helpers.h @@ -9,15 +9,15 @@ // trim from start (in place) static inline void ltrim(std::string &s) { - s.erase(s.begin(), std::find_if(s.begin(), s.end(), - std::not1(std::ptr_fun(std::isspace)))); + s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) + { return !std::isspace(ch); })); } // trim from end (in place) static inline void rtrim(std::string &s) { - s.erase(std::find_if(s.rbegin(), s.rend(), - std::not1(std::ptr_fun(std::isspace))) + s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) + { return !std::isspace(ch); }) .base(), s.end()); }