Repository navigation
Update to v2 #43
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
Update to v2 #43
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2282bf5
Pin Vader
BNAndras b7eb8cb
Add success tests
BNAndras ea25a72
Add error tests
BNAndras 7e73623
Add failure tests
BNAndras 1a6e24a
Delete v1 tests
BNAndras f751d3f
Remove sed normalization
BNAndras abd0871
Add v2 test runner
BNAndras 5023610
Use a tmpdir
BNAndras 9868d20
Simplify Dockerfile
BNAndras d276315
Use git clone instead of git init and fetch
BNAndras 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,3 @@ | ||
| .github/ | ||
| tests/ | ||
| .appends | ||
| .git | ||
| .gitignore | ||
| .gitattributes | ||
| .dockerignore | ||
| Dockerfile | ||
| * | ||
| !bin/ | ||
| !lib/ |
This file was deleted.
Oops, something went wrong.
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
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,120 @@ | ||
| " Orchestrates a Vader run and writes Exercism test-runner v2 JSON. | ||
| set nocompatible | ||
|
|
||
| let s:arguments = v:argv[index(v:argv, '--') + 1 :] | ||
| let s:solution_file = s:arguments[0] | ||
| let s:test_file = s:arguments[1] | ||
| let s:results_file = s:arguments[2] | ||
| let s:input_dir = s:arguments[3] | ||
| let s:vader_path = s:arguments[4] | ||
|
|
||
| function! s:run() abort | ||
| try | ||
| if !filereadable(s:solution_file) | ||
| call s:error('Solution file not found: '.s:solution_file) | ||
| return | ||
| endif | ||
| if !filereadable(s:test_file) | ||
| call s:error('Test file not found: '.s:test_file) | ||
| return | ||
| endif | ||
| if !isdirectory(s:vader_path) | ||
| call s:error('Vader test framework is not installed.') | ||
| return | ||
| endif | ||
|
|
||
| execute 'set runtimepath^='.fnameescape(s:vader_path) | ||
| runtime plugin/vader.vim | ||
|
|
||
| execute 'source '.fnameescape(s:solution_file) | ||
| try | ||
| let cases = vader#parser#parse(s:test_file, 1, 0) | ||
| catch | ||
| call s:error('Vader test file syntax error.') | ||
| return | ||
| endtry | ||
|
|
||
| execute 'silent Vader '.fnameescape(s:test_file) | ||
| let report = split(get(g:, 'vader_report', ''), "\n") | ||
| let errors_by_line = {} | ||
| for vader_error in get(g:, 'vader_errors', []) | ||
| let errors_by_line[string(vader_error.lnum)] = vader_error | ||
| endfor | ||
|
|
||
| let tests = [] | ||
| let all_errors = 1 | ||
| let failed = 0 | ||
| for case in cases | ||
| let test = { | ||
| \ 'name': s:case_name(case), | ||
| \ 'status': 'pass', | ||
| \ 'test_code': join(case.execute, "\n"), | ||
| \ } | ||
| let vader_error = get(errors_by_line, string(case.lnum), {}) | ||
| if !empty(vader_error) | ||
| let message = s:failure_message(vader_error, report) | ||
| let test.status = s:failure_status(message) | ||
| let test.message = s:clean_message(message) | ||
| endif | ||
| let all_errors = all_errors && test.status ==# 'error' | ||
| let failed = failed || test.status !=# 'pass' | ||
| call add(tests, test) | ||
| endfor | ||
|
|
||
| if empty(tests) | ||
| call s:error('No Vader test cases were executed.') | ||
| elseif all_errors | ||
| call s:error(get(tests[0], 'message', 'All Vader test cases errored.')) | ||
| else | ||
| call s:write({ | ||
| \ 'version': 2, | ||
| \ 'status': failed ? 'fail' : 'pass', | ||
| \ 'message': v:null, | ||
| \ 'tests': tests, | ||
| \ }) | ||
| endif | ||
| catch | ||
| call s:error(v:exception) | ||
| endtry | ||
| endfunction | ||
|
|
||
| function! s:write(document) abort | ||
| call writefile([json_encode(a:document)], s:results_file) | ||
| endfunction | ||
|
|
||
| function! s:clean_message(message) abort | ||
| if !empty(s:input_dir) | ||
| return substitute(a:message, '\V'.escape(s:input_dir, '\\').'\m', '<solution-dir>', 'g') | ||
| endif | ||
| return a:message | ||
| endfunction | ||
|
|
||
| function! s:error(message) abort | ||
| call s:write({ | ||
| \ 'version': 2, | ||
| \ 'status': 'error', | ||
| \ 'message': s:clean_message(a:message), | ||
| \ 'tests': [], | ||
| \ }) | ||
| endfunction | ||
|
|
||
| function! s:case_name(case) abort | ||
| let name = get(a:case.comment, 'execute', '') | ||
| return empty(name) ? printf('Test at line %d', a:case.lnum) : name | ||
| endfunction | ||
|
|
||
| function! s:failure_message(vader_error, report) abort | ||
| let report_line = matchstr(get(a:vader_error, 'text', ''), '(#\zs\d\+\ze)') | ||
| if !empty(report_line) && report_line >= 1 && report_line <= len(a:report) | ||
| let message = a:report[report_line - 1] | ||
| return substitute(message, '^\s*(\d\+/\d\+) \[[^]]*\] (X) ', '', '') | ||
| endif | ||
| return get(a:vader_error, 'text', 'Test failed.') | ||
| endfunction | ||
|
|
||
| function! s:failure_status(message) abort | ||
| return a:message =~# '^Vim\%(([^)]*)\)\?:' ? 'error' : 'fail' | ||
| endfunction | ||
|
|
||
| call s:run() | ||
| qa! |
5 changes: 5 additions & 0 deletions
5
tests/error-if-all-tests-raise-errors/error_if_all_tests_raise_errors.vader
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,5 @@ | ||
| Execute (first error): | ||
| call MissingFunctionOne() | ||
|
|
||
| Execute (second error): | ||
| call MissingFunctionTwo() |
3 changes: 3 additions & 0 deletions
3
tests/error-if-all-tests-raise-errors/error_if_all_tests_raise_errors.vim
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,3 @@ | ||
| function! Identity(value) abort | ||
| return a:value | ||
| endfunction |
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,6 @@ | ||
| { | ||
| "status": "error", | ||
| "version": 2, | ||
| "tests": [], | ||
| "message": "Vim(call):E117: Unknown function: MissingFunctionOne" | ||
| } |
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,2 @@ | ||
| Execute (returns 1): | ||
| AssertEqual 1, Identity(1) |
File renamed without changes.
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,6 @@ | ||
| { | ||
| "status": "error", | ||
| "version": 2, | ||
| "tests": [], | ||
| "message": "Vim(call):E117: Unknown function: Identity" | ||
| } |
2 changes: 2 additions & 0 deletions
2
tests/error-if-solution-syntax-error/error_if_solution_syntax_error.vader
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,2 @@ | ||
| Execute (returns 1): | ||
| AssertEqual 1, Identity(1) |
File renamed without changes.
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,6 @@ | ||
| { | ||
| "status": "error", | ||
| "version": 2, | ||
| "tests": [], | ||
| "message": "Vim:E492: Not an editor command: FUNCTIONNNNN @#@#!" | ||
| } |
5 changes: 5 additions & 0 deletions
5
tests/error-if-vader-syntax-error/error_if_vader_syntax_error.vader
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,5 @@ | ||
| Execute (returns 1): | ||
| AssertEqual 1, Identity(1) | ||
|
|
||
| Executte (returns 2): | ||
| AssertEqual 2, Identity(2) |
3 changes: 3 additions & 0 deletions
3
tests/error-if-vader-syntax-error/error_if_vader_syntax_error.vim
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,3 @@ | ||
| function! Identity(value) abort | ||
| return a:value | ||
| endfunction |
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,6 @@ | ||
| { | ||
| "status": "error", | ||
| "version": 2, | ||
| "tests": [], | ||
| "message": "Vader test file syntax error." | ||
| } |
2 changes: 2 additions & 0 deletions
2
tests/error-if-vim9script-has-no-header/error_if_vim9script_has_no_header.vader
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,2 @@ | ||
| Execute (returns a value): | ||
| AssertEqual 1, answer |
1 change: 1 addition & 0 deletions
1
tests/error-if-vim9script-has-no-header/error_if_vim9script_has_no_header.vim
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 @@ | ||
| var answer = 1 |
6 changes: 6 additions & 0 deletions
6
tests/error-if-vim9script-has-no-header/expected_results.json
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,6 @@ | ||
| { | ||
| "status": "error", | ||
| "version": 2, | ||
| "tests": [], | ||
| "message": "Vim(var):E1124: \":var\" cannot be used in legacy Vim script" | ||
| } |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of all the repos to have an editor config, this seems like it would be the most appropriate 😆
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nah, the runner currently skips
.vimrcloading when we invokeviminbin/run.sh. The file is a leftover from the v1 setup where we invokedvimand passed it in manually to load Vader. That's not needed since I moved loading Vader intolib/runner.vim.This avoids an issue where someone pulls the test runner into a Vim session but forgot to point Vim at the local
.vimrcfile first. I did a couple of times last week. The test runner will work without additional configuration. This also keeps the test runner configuration bits insiderunner.vimitself.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This however gave me an idea. Vader is only a couple of kilobytes. We could provide a copy and a
.vimrcin each exercise that loads Vader and the student code dynamically, running the tests. Students only need Vim installed sovim -N -u .vimrccould reliably run the tests from within the exercise folder. That means we can add Vim script toexercism test. If a student wants to use their own settings, they can just start Vim regularly and not use the local settings which are specific to running the tests with the Vader.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that'd be neat!
awk, bash, jq, gdscriptand more ship runner code. GDScript just got stub project files. Having a.vimrcfor the exercises would be cool.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would overlay existing configs though, right? It might be annoying to have my personal root
.vimrcignored.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It ignores the local
.vimrcunless you pass it in using-Uand just runs your personal.vimrc. So you could do that for when you're editing your solution and then still useexercism testto test the code in a separate Vim session. If you wanted to test the code in a different setup, then the local.vimrccould be a starting-off point for customization or you just install Vader in your personal.vimrcand then run the test code how you want.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd recommend not calling it ".vimrc" -- that's confusing for vim users. Something exercism-related perhaps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, probably
runner.vimorrun-tests.vim. We can discuss this further on the forums and brainstorm what all might be useful to include if we were to provide something to facilitate the testing workflow.