-
-
Notifications
You must be signed in to change notification settings - Fork 2
First Release #4
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
98a28d8
* first-release
jimmytty a6fc181
Update bin/results-generator.sh
jimmytty f17311c
Update bin/results-generator.sh
jimmytty af6ee2d
Update bin/results-generator.sh
jimmytty 1c3b225
Update bin/run-tests.sh
jimmytty 1300d7e
Update bin/run-tests.sh
jimmytty 985521d
* indentation
jimmytty 995ac4d
* changing condition to jq all() syntax
jimmytty 8ae16f0
* changing pushd/popd to subprocess
jimmytty 68aa23d
Update bin/results-generator.sh
jimmytty beb7bbc
Update bin/results-generator.sh
jimmytty 2c7a55d
* make sure tap-file is created
jimmytty b6b5ff9
* don't infuriate students!
jimmytty aa665b4
* improving associative array to json conversion
jimmytty 1a961e8
* don't cleanup buld directory
jimmytty 304e3c5
* clean target
jimmytty d60b4a4
* regex shell expansion
jimmytty 8c2a653
Update bin/run.sh
jimmytty a923ad4
Update bin/results-generator.sh
jimmytty 5d7f1dc
* append a linebreak
jimmytty 3c13170
* ansi-c regex
jimmytty db52caf
* buildir
jimmytty d891e20
* add tap.json
jimmytty 108cf44
* remove tojson
jimmytty 79f6d85
Update bin/results-generator.sh
jimmytty b2493a1
Update bin/results-generator.sh
jimmytty 41b167a
Update bin/results-generator.sh
jimmytty 0a2f1b5
Update bin/results-generator.sh
jimmytty File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| #!/bin/bash | ||
|
|
||
| declare -r test_file="$1" | ||
| declare -r tap_file="$2" | ||
| declare -A test_codes=() | ||
|
|
||
| extract_test_codes () { | ||
| local -r lf=$'\n' | ||
| local test_name | ||
| local state='out' | ||
| local proc_re='^procedure[[:blank:]]+[0-9A-Za-z_]+\.([0-9A-Za-z_]+);$' | ||
| local end_re='^end;$' | ||
| local assert_re='^[^\n]+\nbegin\n *(TapAssert.*);\nend;$' | ||
| local name | ||
| local body | ||
| while IFS= read -r line; do | ||
| if [[ "$state" == 'in' ]]; then | ||
| printf -v body $'%s\n%s' "$body" "$line" | ||
| if [[ "$line" =~ $end_re ]]; then | ||
| state='out' | ||
| shopt -s nocasematch | ||
| if [[ "$body" =~ ${assert_re//\\n/${lf}} ]]; then | ||
jimmytty marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| test_codes["$name"]="${BASH_REMATCH[1]//${lf}/\\n}" | ||
| else | ||
| echo 'parser error' | ||
| exit 1 | ||
| fi | ||
| shopt -u nocasematch | ||
| fi | ||
| elif [[ "$line" =~ $proc_re ]]; then | ||
| state='in' | ||
| name="${BASH_REMATCH[1]}" | ||
| body="$line" | ||
| fi | ||
| done < "$test_file" | ||
| } | ||
|
|
||
| tap_parser() { | ||
jimmytty marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| local -r json_test_codes="$( | ||
| for key in ${!test_codes[*]}; do | ||
jimmytty marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| printf '"%s"' "$key" | ||
| printf '"%s"' "${test_codes[$key]}" | ||
jimmytty marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| done | | ||
| jq -n 'reduce inputs as $i ({}; . + { ($i): input })' | ||
| )" | ||
| local -a tap_content | ||
| mapfile -d '' tap_content < "$tap_file" | ||
jimmytty marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| local -r status="$(jq -r ' | ||
| [ | ||
| .[] | | ||
| select(.[0] == "assert") | ||
| ] as $asserts | | ||
jimmytty marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if ($asserts | length) > 0 and | ||
| ($asserts | length) == | ||
| ([$asserts[] | select(.[1].ok == true)] | length) | ||
jimmytty marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| then | ||
| "pass" | ||
| else | ||
| "fail" | ||
| end | ||
| ' <<< "${tap_content[0]}" | ||
| )" | ||
|
|
||
| if [[ "$status" != "pass" ]] && \ | ||
| jq -e \ | ||
| '.[] | | ||
| select(.[0] == "plan" and .[1].comment == "no tests found") | | ||
| length > 0' <<< "${tap_content[0]}" &>/dev/null; | ||
| then | ||
| jq -r ' | ||
| { | ||
| "version": 3, | ||
jimmytty marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "status" : "error", | ||
| "message": ([.[] | select(.[0] == "extra") | .[1]] | join("")[0:65535]), | ||
jimmytty marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }' <<< "${tap_content[0]}" | ||
| else | ||
| local -i i=0 | ||
| local extra='' | ||
| local -a json_arrays | ||
| while IFS= read -r line; do | ||
| if jq -e '.[0] == "extra"' <<< "$line" &>/dev/null; then | ||
| printf -v extra '%s%s\n' "$extra" "$(jq -r '.[1]' <<< "$line")" | ||
jimmytty marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| continue | ||
| fi | ||
| if jq -e '.[0] == "assert"' <<< "$line" &>/dev/null; then | ||
jimmytty marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (( ${#extra} > 500 )); then | ||
| extra='Output was truncated. Please limit to 500 chars' | ||
jimmytty marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| fi | ||
| (( i++ )) | ||
| json_arrays+=("$( | ||
| jq -r --arg extra "$extra" \ | ||
| '[.[0], | ||
| (.[1] + | ||
| { "output": | ||
| if $extra == "" then null else $extra end })]' \ | ||
| <<< "$line" | ||
| )") | ||
| extra='' | ||
| else | ||
| json_arrays+=("$line") | ||
| fi | ||
| done < <(jq -r '.[] | tojson' <<< "${tap_content[0]}") | ||
jimmytty marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| local json_string | ||
| printf -v json_string '%s,' "${json_arrays[@]}" | ||
| json_string="${json_string%,}" | ||
| printf -v json_string '[%s]' "$json_string" | ||
| tap_content[0]="$(jq -r . <<< "$json_string")" | ||
|
|
||
| jq -r \ | ||
jimmytty marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| --arg status "$status" \ | ||
| --argjson test_codes "$json_test_codes" \ | ||
| ' | ||
| { | ||
| "version": 3, | ||
| "status" : $status, | ||
| "message": null, | ||
| } + { | ||
| "tests": [ | ||
| .[] | select(.[0] == "assert") | .[1] | | ||
| if .name == "Please implement your solution." then | ||
| { "name": .name, status: "error", test_code: "", message: .name } | ||
| elif .ok == true then | ||
| { "name": .name, status: "pass" } | ||
| else | ||
| { | ||
| "name": .diag.message, | ||
| "status": .diag.severity, | ||
| "output": .output, | ||
| "test_code": $test_codes[.name], | ||
| "message": "GOT:" + (.diag.data.got|tostring) + "\n" + | ||
| "EXPECTED:" + (.diag.data.expect|tostring), | ||
| } | ||
| end | ||
| ] | ||
| } | ||
| ' <<< "${tap_content[0]}" | ||
| fi | ||
| } | ||
|
|
||
| extract_test_codes | ||
| tap_parser | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| unit AllFail; | ||
|
|
||
| {$mode ObjFPC}{$H+} | ||
|
|
||
| interface | ||
|
|
||
| function abbreviate(const phrase: string) : string; | ||
|
|
||
| implementation | ||
|
|
||
| uses SysUtils; | ||
|
|
||
| function abbreviate(const phrase: string) : string; | ||
| begin | ||
|
|
||
| result := phrase; | ||
|
|
||
| end; | ||
|
|
||
| end. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| SHELL = /bin/bash | ||
| MAKEFLAGS += --no-print-directory | ||
| DESTDIR = build | ||
| EXECUTABLE = $(DESTDIR)/test | ||
| COMMAND = fpc -l- -v0 -Sehnw -Fu./lib test.pas -FE"./$(DESTDIR)" | ||
|
|
||
| .ONESHELL: | ||
|
|
||
| test: | ||
| @$(MAKE) clean | ||
| @mkdir -p "./$(DESTDIR)" | ||
| @cp -r ./lib "./$(DESTDIR)" | ||
| @$(COMMAND) && ./$(EXECUTABLE) $(test) || $(MAKE) clean | ||
| @$(MAKE) clean | ||
glennj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| clean: | ||
| @rm -fr "./$(DESTDIR)" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| unit TestCases; | ||
|
|
||
| {$mode ObjFPC}{$H+} | ||
|
|
||
| interface | ||
|
|
||
| uses Classes, SysUtils, FPCUnit, TestRegistry, FPCUnitTestUtils; | ||
|
|
||
| type | ||
| AllFailTest = class(TTestCase) | ||
| published | ||
| procedure basic; | ||
| procedure lowercase_words; | ||
| procedure punctuation; | ||
| procedure all_caps_word; | ||
| procedure punctuation_without_whitespace; | ||
| procedure very_long_abbreviation; | ||
| procedure consecutive_delimiters; | ||
| procedure apostrophes; | ||
| procedure underscore_emphasis; | ||
| end; | ||
|
|
||
| implementation | ||
|
|
||
| uses AllFail; | ||
|
|
||
| // 1e22cceb-c5e4-4562-9afe-aef07ad1eaf4 | ||
| procedure AllFailTest.basic; | ||
| begin | ||
| TapAssertTrue( | ||
| Self, | ||
| 'basic', | ||
| 'PNG', | ||
| AllFail.abbreviate('Portable Network Graphics') | ||
| ); | ||
| end; | ||
|
|
||
| // 79ae3889-a5c0-4b01-baf0-232d31180c08 | ||
| procedure AllFailTest.lowercase_words; | ||
| begin | ||
| TapAssertTrue(Self, 'lowercase words', 'ROR', AllFail.abbreviate('Ruby on Rails')); | ||
| end; | ||
|
|
||
| // ec7000a7-3931-4a17-890e-33ca2073a548 | ||
| procedure AllFailTest.punctuation; | ||
| begin | ||
| TapAssertTrue(Self, 'punctuation', 'FIFO', AllFail.abbreviate('First In, First Out')); | ||
| end; | ||
|
|
||
| // 32dd261c-0c92-469a-9c5c-b192e94a63b0 | ||
| procedure AllFailTest.all_caps_word; | ||
| begin | ||
| TapAssertTrue(Self, 'all caps word', 'GIMP', AllFail.abbreviate('GNU Image Manipulation Program')); | ||
| end; | ||
|
|
||
| // ae2ac9fa-a606-4d05-8244-3bcc4659c1d4 | ||
| procedure AllFailTest.punctuation_without_whitespace; | ||
| begin | ||
| TapAssertTrue(Self, 'punctuation without whitespace', 'CMOS', AllFail.abbreviate('Complementary metal-oxide semiconductor')); | ||
| end; | ||
|
|
||
| // 0e4b1e7c-1a6d-48fb-81a7-bf65eb9e69f9 | ||
| procedure AllFailTest.very_long_abbreviation; | ||
| begin | ||
| TapAssertTrue(Self, 'very long abbreviation', 'ROTFLSHTMDCOALM', AllFail.abbreviate('Rolling On The Floor Laughing So Hard That My Dogs Came Over And Licked Me')); | ||
| end; | ||
|
|
||
| // 6a078f49-c68d-4b7b-89af-33a1a98c28cc | ||
| procedure AllFailTest.consecutive_delimiters; | ||
| begin | ||
| TapAssertTrue(Self, 'consecutive delimiters', 'SIMUFTA', AllFail.abbreviate('Something - I made up from thin air')); | ||
| end; | ||
|
|
||
| // 5118b4b1-4572-434c-8d57-5b762e57973e | ||
| procedure AllFailTest.apostrophes; | ||
| begin | ||
| TapAssertTrue(Self, 'apostrophes', 'HC', AllFail.abbreviate('Halley''s Comet')); | ||
| end; | ||
|
|
||
| // adc12eab-ec2d-414f-b48c-66a4fc06cdef | ||
| procedure AllFailTest.underscore_emphasis; | ||
| begin | ||
| TapAssertTrue(Self, 'underscore emphasis', 'TRNT', AllFail.abbreviate('The Road _Not_ Taken')); | ||
| end; | ||
|
|
||
| initialization | ||
| RegisterTest(AllFailTest); | ||
|
|
||
| end. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.