-
-
Notifications
You must be signed in to change notification settings - Fork 2
initial test-runner, with tests #5
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 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0a5f11b
initial test-runner, with tests
glennj 59f619c
add script to validate moonscript track in docker
glennj 844038a
Ryan's review comments
glennj 3277c93
additional cleanup
glennj 1efa1e4
bin/run.sh not needed
glennj f5fac46
typo
glennj 40491e0
updating the verify scripts in the moonscript track; found a missing …
glennj 0161280
shrink the test-runner image size
glennj 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 |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| /tests/**/*/results.json | ||
| track/ |
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,40 @@ | ||
| FROM alpine:3.18 | ||
| FROM ubuntu:24.04 | ||
|
|
||
| # install packages required to run the tests | ||
| RUN apk add --no-cache jq coreutils | ||
| ENV LUA_VER="5.4.8" | ||
| ENV LUA_CHECKSUM="4f18ddae154e793e46eeab727c59ef1c0c0c2b744e7b94219710d76f530629ae" | ||
| ENV LUAROCKS_VER="3.12.0" | ||
| ENV LUAROCKS_GPG_KEY="3FD8F43C2BB3C478" | ||
|
Check warning on line 6 in Dockerfile
|
||
|
|
||
| RUN apt-get update && \ | ||
| apt-get install -y curl gcc jq make unzip gnupg git && \ | ||
| rm -rf /var/lib/apt/lists/* && \ | ||
| apt-get purge --auto-remove && \ | ||
| apt-get clean | ||
|
|
||
| RUN curl -R -O -L http://www.lua.org/ftp/lua-${LUA_VER}.tar.gz && \ | ||
| [ "$(sha256sum lua-${LUA_VER}.tar.gz | cut -d' ' -f1)" = "${LUA_CHECKSUM}" ] && \ | ||
| tar -zxf lua-${LUA_VER}.tar.gz && \ | ||
| cd lua-${LUA_VER} && \ | ||
| make all install && \ | ||
| cd .. && \ | ||
| rm lua-${LUA_VER}.tar.gz && \ | ||
| rm -rf lua-${LUA_VER} | ||
|
|
||
| RUN curl -R -O -L https://luarocks.org/releases/luarocks-${LUAROCKS_VER}.tar.gz && \ | ||
| curl -R -O -L https://luarocks.org/releases/luarocks-${LUAROCKS_VER}.tar.gz.asc && \ | ||
| gpg --keyserver keyserver.ubuntu.com --recv-keys ${LUAROCKS_GPG_KEY} && \ | ||
| gpg --verify luarocks-${LUAROCKS_VER}.tar.gz.asc luarocks-${LUAROCKS_VER}.tar.gz && \ | ||
| tar -zxpf luarocks-${LUAROCKS_VER}.tar.gz && \ | ||
| cd luarocks-${LUAROCKS_VER} && \ | ||
| ./configure && make && make install && \ | ||
| cd .. && \ | ||
| rm luarocks-${LUAROCKS_VER}.tar.gz.asc && \ | ||
| rm luarocks-${LUAROCKS_VER}.tar.gz && \ | ||
| rm -rf luarocks-${LUAROCKS_VER} | ||
|
|
||
| RUN luarocks install busted | ||
| RUN luarocks install moonscript | ||
|
|
||
| COPY . /opt/test-runner | ||
| WORKDIR /opt/test-runner | ||
| COPY . . | ||
| ENTRYPOINT ["/opt/test-runner/bin/run.sh"] | ||
| ENTRYPOINT ["/opt/test-runner/bin/run.moon"] | ||
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,192 @@ | ||
| #! /usr/bin/env moon | ||
|
|
||
| require 'moonscript' | ||
| lfs = require 'lfs' | ||
| json = (require 'dkjson').use_lpeg! | ||
| getopt = require 'alt_getopt' | ||
| local verbose | ||
|
|
||
| import p from require 'moon' | ||
|
|
||
|
|
||
| -- ----------------------------------------------------------- | ||
| show_help = (args) -> | ||
| print "Usage: #{args[0]} [-h] [-v] slug solution-dir output-dir" | ||
| print "Where: -h show this help" | ||
| print " -v verbose: show the output JSON" | ||
| os.exit! | ||
|
|
||
|
|
||
| -- ----------------------------------------------------------- | ||
| file_exists = (path) -> | ||
| attrs = lfs.attributes path | ||
| not not attrs | ||
|
|
||
| is_directory = (path) -> | ||
| attrs = lfs.attributes path | ||
| attrs and attrs.mode == 'directory' | ||
|
|
||
| realpath = (path) -> | ||
| fh = io.popen "realpath #{path}" | ||
| dir = fh\read! | ||
| fh\close! | ||
| dir | ||
|
|
||
| validate = (args) -> | ||
| show_help args unless #args == 3 | ||
| {slug, src_dir, dest_dir} = args | ||
| assert slug != '', 'First arg, the slug, cannot be empty' | ||
| assert is_directory(src_dir), 'Second arg, the solution directory, must be a directory' | ||
| assert is_directory(dest_dir), 'Second arg, the output directory, must be a directory' | ||
|
|
||
| slug, realpath(src_dir), realpath(dest_dir) | ||
|
|
||
|
|
||
| -- ----------------------------------------------------------- | ||
| run_tests = (slug, dir) -> | ||
| ok, err = lfs.chdir dir | ||
| assert ok, err | ||
|
|
||
| -- unskip tests | ||
| cmd = "perl -i.bak -pe 's{^\\s*\\Kpending\\b}{it}' *_spec.moon" | ||
| ok, result_type, status = os.execute cmd | ||
| assert ok | ||
|
|
||
| -- launch `busted` | ||
| fh = io.popen 'busted -o json', 'r' | ||
| json_output = fh\read 'a' | ||
| ok, exit_type, exit_status = fh\close! | ||
|
|
||
| if exit_type == 'signal' | ||
| return { | ||
| status: 'error', | ||
| message: json_output | ||
| } | ||
|
|
||
| data = json.decode json_output | ||
|
|
||
| if not data | ||
| return { | ||
| status: 'error', | ||
| message: json_output | ||
| } | ||
|
|
||
| if exit_status != 0 and #data.successes == 0 and #data.failures == 0 and #data.errors > 0 | ||
| return { | ||
| status: 'error', | ||
| message: data.errors[1].message | ||
| } | ||
|
|
||
| results = {} | ||
|
|
||
| for test in *data.successes | ||
| results[test.element.name] = { | ||
| status: 'pass', | ||
| name: test.element.name, | ||
| } | ||
|
|
||
| for test in *data.failures | ||
| results[test.element.name] = { | ||
| status: 'fail', | ||
| name: test.element.name, | ||
| message: test.trace.message, | ||
| } | ||
|
|
||
| results | ||
|
|
||
|
|
||
| -- ----------------------------------------------------------- | ||
| get_test_bodies = (slug, dir) -> | ||
| ok, err = lfs.chdir dir | ||
| assert ok, err | ||
|
|
||
| order = {} | ||
| bodies = {} | ||
|
|
||
| test_file = "#{slug\gsub('-', '_')}_spec.moon" | ||
| return unless file_exists test_file -- let `busted` handle the error messaging | ||
|
|
||
| fh = io.open test_file, 'r' | ||
|
|
||
| pattern = (word) -> '^%s+' .. word .. '%s+[\'"](.+)[\'"],%s+->' | ||
| patterns = it: pattern('it'), pending: pattern('pending') | ||
|
|
||
| local test_name | ||
| test_body = {} | ||
| in_test = false | ||
|
|
||
| for line in fh\lines! | ||
| if line\match '^%s+describe ' | ||
| if test_name | ||
| bodies[test_name] = table.concat test_body, '\n' | ||
| test_body = {} | ||
| test_name = nil | ||
| in_test = false | ||
|
|
||
| m = line\match(patterns.it) or line\match(patterns.pending) | ||
| if not m | ||
| if in_test | ||
| table.insert test_body, line | ||
| else | ||
| table.insert order, m | ||
| if in_test | ||
| bodies[test_name] = table.concat test_body, '\n' | ||
| test_body = {} | ||
| test_name = m | ||
| in_test = true | ||
|
|
||
| fh\close! | ||
| bodies[test_name] = table.concat test_body, '\n' | ||
| order, bodies | ||
|
|
||
|
|
||
| -- ----------------------------------------------------------- | ||
| write_results = (slug, test_results, names, bodies, dir) -> | ||
| ok, err = lfs.chdir dir | ||
| assert ok, "#{err}: #{dir}" | ||
|
|
||
| results = version: 2, status: nil, tests: {} | ||
|
|
||
| if test_results.status | ||
| -- this was an error result | ||
| results.status = test_results.status | ||
| results.message = test_results.message | ||
|
|
||
| else | ||
| status = 'pass' | ||
| for name in *names | ||
| test = test_results[name] | ||
| assert test, "no test result for #{name}" | ||
| status = 'fail' if test.status == 'fail' | ||
| test.test_code = bodies[name] | ||
| table.insert results.tests, test | ||
| results.status = status | ||
|
|
||
| fh = io.open 'results.json', 'w' | ||
| fh\write (json.encode results) .. '\n' | ||
| fh\close! | ||
|
|
||
| os.execute "jq . results.json" if verbose | ||
|
|
||
|
|
||
| -- ----------------------------------------------------------- | ||
| main = (args) -> | ||
| opts,optind = getopt.get_opts args, 'hv', {} | ||
|
glennj marked this conversation as resolved.
Outdated
|
||
|
|
||
| show_help args if opts.h | ||
| verbose = not not opts.v | ||
| table.remove args, 1 for _ = 1, optind - 1 | ||
|
|
||
| slug, src_dir, dest_dir = validate args | ||
|
|
||
| print "#{slug}: testing ..." | ||
|
|
||
| test_names_ordered, test_code = get_test_bodies slug, src_dir | ||
|
|
||
| test_results = run_tests slug, src_dir | ||
|
|
||
| write_results slug, test_results, test_names_ordered, test_code, dest_dir | ||
|
|
||
| print "#{slug}: ... done" | ||
|
|
||
| main arg | ||
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,25 @@ | ||
| #!/usr/bin/env lua | ||
|
|
||
| local json = require('dkjson') | ||
| local tablex = require('pl.tablex') | ||
| local pretty = require('pl.pretty') | ||
|
|
||
| local function load_json(file) | ||
| local fd <close> = io.open(file) | ||
| return json.decode(fd:read('a')) | ||
| end | ||
|
|
||
| local result = load_json(arg[1]) | ||
| local expected = load_json(arg[2]) | ||
|
|
||
| if not tablex.deepcompare(result, expected) then | ||
| print('\n========[ RESULT ]========\n') | ||
| print(pretty.write(result)) | ||
|
|
||
| print('\n========[ EXPECTED ]========\n') | ||
| print(pretty.write(expected)) | ||
|
|
||
| os.exit(1) | ||
| end | ||
|
|
||
| os.exit(0) |
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.
Uh oh!
There was an error while loading. Please reload this page.