Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update handling of result files #21

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
10 changes: 5 additions & 5 deletions .gitpod.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ FROM gitpod/workspace-full
# Install custom tools, runtime, etc.
RUN sudo apt-get update && sudo apt-get install -y gfortran && sudo apt-get clean && sudo rm -rf /var/cache/apt/* && sudo rm -rf /var/lib/apt/lists/* && sudo rm -rf /tmp/*

WORKDIR /opt/test-runner/testlib
RUN curl -R -O https://raw.githubusercontent.com/pclausen/fortran/main/testlib/CMakeLists.txt
RUN curl -R -O https://raw.githubusercontent.com/pclausen/fortran/main/testlib/TesterMain.f90
WORKDIR /workspace/fortran-test-runner/testlib
RUN curl -R -O https://raw.githubusercontent.com/exercism/fortran/main/testlib/CMakeLists.txt
RUN curl -R -O https://raw.githubusercontent.com/exercism/fortran/main/testlib/TesterMain.f90

WORKDIR /opt/test-runner
RUN curl -R -O https://raw.githubusercontent.com/pclausen/fortran/main/config/CMakeLists.txt
WORKDIR /workspace/fortran-test-runner
RUN curl -R -O https://raw.githubusercontent.com/exercism/fortran/main/config/CMakeLists.txt
4 changes: 2 additions & 2 deletions .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ ports:
onOpen: open-preview

# List the start up tasks. You can start them in parallel in multiple terminals. See https://www.gitpod.io/docs/config-start-tasks/
tasks:
- command: echo 'Create build directory and run build and test' && mkdir build && cd build && cmake .. && make && ctest -V && cd ..
#tasks:
# - command: echo 'Create build directory and run build and test' && mkdir -p build && cd build && cmake .. && make && ctest -V && cd ..
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ FROM alpine:3.11
RUN apk add --no-cache coreutils curl jq gfortran libc-dev cmake make python3 git

WORKDIR /opt/test-runner/testlib
RUN curl -R -O https://raw.githubusercontent.com/pclausen/fortran/main/testlib/CMakeLists.txt
RUN curl -R -O https://raw.githubusercontent.com/pclausen/fortran/main/testlib/TesterMain.f90
RUN curl -R -O https://raw.githubusercontent.com/exercism/fortran/main/testlib/CMakeLists.txt
RUN curl -R -O https://raw.githubusercontent.com/exercism/fortran/main/testlib/TesterMain.f90

WORKDIR /opt/test-runner
RUN curl -R -O https://raw.githubusercontent.com/pclausen/fortran/main/config/CMakeLists.txt
RUN curl -R -O https://raw.githubusercontent.com/exercism/fortran/main/config/CMakeLists.txt


COPY . .
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ Since the test runners are deployed as Docker images the [related specification]
To run tests:

1. Open project's root in terminal
2. Run `./test.sh`
2. Run `./bin/run-tests.sh`

This will compile and run tests for all exercises in the `tests` folder, it will fail if the output file `result.json` is different from the expected one for the exercise.

If you want to run specific tests:

1. Open project's root in terminal
2. Run `./test.sh <EXERCISE_SLUG_1> <EXERCISE_SLUG_2>`
2. Run `./bin/run.sh <EXERCISE_SLUG_1> <EXERCISE_SLUG_2>`

In both cases you can show more informations, like Docker output, by using the flag `-v` or `--verbose`.

Expand Down
9 changes: 9 additions & 0 deletions bin/diff_expected_results.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

for exp_res in $(find . -name expected_results.json); do
res=$(echo $exp_res | sed 's/expected_//')
cmd="diff $res $exp_res"
echo $cmd
$cmd
echo
done
10 changes: 10 additions & 0 deletions bin/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ for test_dir in tests/*; do
# -e "s~${test_dir_path}~/solution~g" \
# "${results_file_path}"

# Remove line numbers because they are different in Docker build vs local build
# also remove quotation marks (’‘ vs '') because they may be different on docker vs local linux
# But only on build error ("Makefile")
grep -q "Makefile" "${results_file_path}"
if [ $? -eq 0 ] ; then
message_norm=$(jq '.message' ${results_file_path} | sed 's/[0-9]*//g' | sed -e 's/["'\''’‘]//g' | sed 's/\\n//g' )
jq --arg message_norm "$message_norm" '(.message |= $message_norm )' ${results_file_path} > ${results_file_path}_norm
cp ${results_file_path}_norm ${results_file_path}
rm ${results_file_path}_norm
fi
echo "${test_dir_name}: comparing results.json to expected_results.json"
diff "${results_file_path}" "${expected_results_file_path}"

Expand Down
4 changes: 1 addition & 3 deletions bin/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ cmake --build . 2> "${compilation_errors_file_name}" 1>> "${compilation_stdout_f
ret=$?

if [ $ret -ne 0 ]; then
# remove line numbers because they are diffrent in Docker build vs local build
# also remove quotation marks (’‘ vs '') because they may be different on docker vs local linux
message=$(cat "${compilation_errors_file_name}" | sed 's/[0-9]*//g' | sed -e 's/["'\''’‘]//g' | tr \\n \; | sed 's/;/\\\\n/g')
message=$(cat "${compilation_errors_file_name}")
jq -n --arg m "${message}" '{version: 2, status: "error", tests: [], message: $m}' > "${build_results_file}"
else
# build successful, now run test
Expand Down
8 changes: 8 additions & 0 deletions bin/update_expected_results.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

for exp_res in $(find . -name expected_results.json); do
res=$(echo $exp_res | sed 's/expected_//')
cmd="cp $res $exp_res"
echo $cmd
$cmd
done
216 changes: 147 additions & 69 deletions tests/example-all-fail/expected_results.json
Original file line number Diff line number Diff line change
@@ -1,74 +1,152 @@
{
"tests": [
{ "name" : "Test 1: stating something",
"status": "fail" }
,
{ "name" : "Test 2: shouting",
"status": "pass" }
,
{ "name" : "Test 3: shouting gibberish",
"status": "pass" }
,
{ "name" : "Test 4: asking a question",
"status": "pass" }
,
{ "name" : "Test 5: asking a numeric question",
"status": "pass" }
,
{ "name" : "Test 6: asking gibberish",
"status": "pass" }
,
{ "name" : "Test 7: talking forcefully",
"status": "fail" }
,
{ "name" : "Test 8: using acronyms in regular speech",
"status": "fail" }
,
{ "name" : "Test 9: forceful question",
"status": "pass" }
,
{ "name" : "Test 10: shouting numbers",
"status": "pass" }
,
{ "name" : "Test 11: no letters",
"status": "fail" }
,
{ "name" : "Test 12: question with no letters",
"status": "pass" }
,
{ "name" : "Test 13: shouting with special characters",
"status": "pass" }
,
{ "name" : "Test 14: shouting with no exclamation mark",
"status": "pass" }
,
{ "name" : "Test 15: statement containing question mark",
"status": "fail" }
,
{ "name" : "Test 16: non-letters with question",
"status": "pass" }
,
{ "name" : "Test 17: prattling on",
"status": "pass" }
,
{ "name" : "Test 18: silence",
"status": "pass" }
,
{ "name" : "Test 19: prolonged silence",
"status": "pass" }
,
{ "name" : "Test 20: multiple line question",
"status": "fail" }
,
{ "name" : "Test 21: starting with whitespace",
"status": "fail" }
,
{ "name" : "Test 22: ending with whitespace",
"status": "pass" }
,
{ "name" : "Test 23: non-question ending with whitespace",
"status": "fail" }
{
"name" : "Test 1: stating something",
"test_code": "Test 1: stating something",
"status" : "fail",
"message" : "Expected < Whatever. > but got < Whatever. THIS IS A FAILING TEST >"
}
,
{
"name" : "Test 2: shouting",
"test_code": "Test 2: shouting",
"status" : "pass",
}
,
{
"name" : "Test 3: shouting gibberish",
"test_code": "Test 3: shouting gibberish",
"status" : "pass",
}
,
{
"name" : "Test 4: asking a question",
"test_code": "Test 4: asking a question",
"status" : "pass",
}
,
{
"name" : "Test 5: asking a numeric question",
"test_code": "Test 5: asking a numeric question",
"status" : "pass",
}
,
{
"name" : "Test 6: asking gibberish",
"test_code": "Test 6: asking gibberish",
"status" : "pass",
}
,
{
"name" : "Test 7: talking forcefully",
"test_code": "Test 7: talking forcefully",
"status" : "fail",
"message" : "Expected < Whatever. > but got < Whatever. THIS IS A FAILING TEST >"
}
,
{
"name" : "Test 8: using acronyms in regular speech",
"test_code": "Test 8: using acronyms in regular speech",
"status" : "fail",
"message" : "Expected < Whatever. > but got < Whatever. THIS IS A FAILING TEST >"
}
,
{
"name" : "Test 9: forceful question",
"test_code": "Test 9: forceful question",
"status" : "pass",
}
,
{
"name" : "Test 10: shouting numbers",
"test_code": "Test 10: shouting numbers",
"status" : "pass",
}
,
{
"name" : "Test 11: no letters",
"test_code": "Test 11: no letters",
"status" : "fail",
"message" : "Expected < Whatever. > but got < Whatever. THIS IS A FAILING TEST >"
}
,
{
"name" : "Test 12: question with no letters",
"test_code": "Test 12: question with no letters",
"status" : "pass",
}
,
{
"name" : "Test 13: shouting with special characters",
"test_code": "Test 13: shouting with special characters",
"status" : "pass",
}
,
{
"name" : "Test 14: shouting with no exclamation mark",
"test_code": "Test 14: shouting with no exclamation mark",
"status" : "pass",
}
,
{
"name" : "Test 15: statement containing question mark",
"test_code": "Test 15: statement containing question mark",
"status" : "fail",
"message" : "Expected < Whatever. > but got < Whatever. THIS IS A FAILING TEST >"
}
,
{
"name" : "Test 16: non-letters with question",
"test_code": "Test 16: non-letters with question",
"status" : "pass",
}
,
{
"name" : "Test 17: prattling on",
"test_code": "Test 17: prattling on",
"status" : "pass",
}
,
{
"name" : "Test 18: silence",
"test_code": "Test 18: silence",
"status" : "pass",
}
,
{
"name" : "Test 19: prolonged silence",
"test_code": "Test 19: prolonged silence",
"status" : "pass",
}
,
{
"name" : "Test 20: multiple line question",
"test_code": "Test 20: multiple line question",
"status" : "fail",
"message" : "Expected < Whatever. > but got < Whatever. THIS IS A FAILING TEST >"
}
,
{
"name" : "Test 21: starting with whitespace",
"test_code": "Test 21: starting with whitespace",
"status" : "fail",
"message" : "Expected < Whatever. > but got < Whatever. THIS IS A FAILING TEST >"
}
,
{
"name" : "Test 22: ending with whitespace",
"test_code": "Test 22: ending with whitespace",
"status" : "pass",
}
,
{
"name" : "Test 23: non-question ending with whitespace",
"test_code": "Test 23: non-question ending with whitespace",
"status" : "fail",
"message" : "Expected < Whatever. > but got < Whatever. THIS IS A FAILING TEST >"
}
],
"version": 2,
"status": "fail"
"status" : "fail"
"message": "Test summary: 8 of 23 tests failed",
}
2 changes: 1 addition & 1 deletion tests/example-empty-file/expected_results.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"version": 2,
"status": "error",
"tests": [],
"message": "/tmp/example-empty-file/example_empty_file_test.f:::\\\\n\\\\n | use bob\\\\n | \\\\nFatal Error: Cannot open module file bob.mod for reading at (): No such file or directory\\\\ncompilation terminated.\\\\nmake[]: *** [CMakeFiles/example-empty-file.dir/build.make:: CMakeFiles/example-empty-file.dir/example_empty_file_test.f.o] Error \\\\nmake[]: *** [CMakeFiles/Makefile:: CMakeFiles/example-empty-file.dir/all] Error \\\\nmake: *** [Makefile:: all] Error \\\\n"
"message": "/tmp/example-empty-file/example_empty_file_test.f::: | use bob | Fatal Error: Cannot open module file bob.mod for reading at (): No such file or directorycompilation terminated.make[]: *** [CMakeFiles/example-empty-file.dir/build.make:: CMakeFiles/example-empty-file.dir/example_empty_file_test.f.o] Error make[]: *** [CMakeFiles/Makefile:: CMakeFiles/example-empty-file.dir/all] Error make: *** [Makefile:: all] Error "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you've now stripped the newlines entirely, which is not what we want I think :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, only for the test case. I moved the the "stripping" of newlines etc from run.sh to run-test.sh. Thus, for the "real" case using "run.sh" we will have newlines and line numbers etc.

Maybe this whole stripping of the json file makes the test meaningless, but my problem is that the errors are different within docker vs local execution. If you have a suggestion for a better solution I would be very happy to implement it if its within my ability.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. The main concern I have with that is that the expected result files no longer exactly indicate what is shown to the student. We'd thus never know for certain whether what's displayed to the student is the correct value.

If you'd like me to take a look, I'd be happy to of course.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ErikSchierboom I agree and i would like if you could have a look. My main problem is that I do not know docker well enough to know if there is a way to make it behave more like the "normal" linux system. If the two systems behaved the same, these stripping of results would not be necessary.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docker should actually behave lik a normal linux system. I'll take a look.

}
Loading