Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 6 additions & 14 deletions bin/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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": "<compiler output>"}/' \
"${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}
4 changes: 2 additions & 2 deletions bin/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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 -
Expand Down
8 changes: 4 additions & 4 deletions include/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, int>(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<int, int>(std::isspace)))
s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch)
{ return !std::isspace(ch); })
.base(),
s.end());
}
Expand Down