Skip to content

GitHub Actions Testing Files and Bug Fixes #97

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 18 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from 16 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
45 changes: 45 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# This workflow will do a clean install of the dependencies and run tests across different versions
#
# Replace <track> with the track name
# Replace <image-name> with an image to run the jobs on
# Replace <action to setup tooling> with a github action to setup tooling on the image
# Replace <install dependencies> with a cli command to install the dependencies
#
# Find Github Actions to setup tooling here:
# - https://github.com/actions/?q=setup&type=&language=
# - https://github.com/actions/starter-workflows/tree/main/ci
# - https://github.com/marketplace?type=actions&query=setup
#
# Requires scripts:
# - bin/test

name: J / Test

on:
push:
branches: [main]
pull_request:
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-22.04

steps:
- name: Checkout repository
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633

- name: Install project dependencies
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends wget ca-certificates

- name: Install J
run: |
wget https://www.jsoftware.com/download/j9.5/install/j9.5_linux64.tar.gz
tar -xvf j9.5_linux64.tar.gz
mv j9.5 /opt/j9.5
rm -rf j9.5_linux64.tar.gz

- name: Verify all exercises
run: bin/verify-exercises.sh
Empty file added bin/test_all_exercises.ijs
Empty file.
39 changes: 39 additions & 0 deletions bin/test_exercise.ijs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#! /opt/j9.5/bin/jconsole

try_error=: 3 : 0
for_i. y do.
test_name =. > i
error_expected =. ( 5 }. test_name , '_expect')~
try.
0!:100 fputs test_name , (quote'')
catch.
errname=. > (<: 13!:11'') { 9!:8''
if. errname -.@-: error_expected do.
0 return.
end.
end.
end.
1 return.
)

main=: monad define
exercise_dir=. _1 { ARGV
1!:44 >exercise_dir
tests=. ('[a-zA-Z0-9[-]*]*[.]ijs'; '.meta/example.ijs') rxrplc 1!:1 <'test.ijs' NB. Replace load directive for the tests
0!:0 tests NB. load to put the tests in `nl`
before_all '' NB. tests verbs depends on values setted at `before_all`
tests=. 'test_' nl 3 NB. get defined tests from `nl`
errors=. ('test_'&,)each (_7&}.)each '_expect*' nl 0

if. 0-.@-:#errors do.
'expect_value expect_error'=. (tests e. errors) </. tests
test_values=. 0!:3 fputs (,&(quote''))every expect_value
test_errors=. try_error expect_error
exit -.(test_values *. test_errors)
else.
exit -. 0!:3 fputs (,&(quote''))every tests
end.

)

main''
43 changes: 43 additions & 0 deletions bin/verify-exercises.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash

# Synopsis:
# Test the track's exercises.
#
# At a minimum, this file must check if the example/exemplar solution of each
# Practice/Concept Exercise passes the exercise's tests.
#
# To check this, you usually have to (temporarily) replace the exercise's solution files
# with its exemplar/example files.
#
# If your track uses skipped tests, make sure to (temporarily) enable these tests
# before running the tests.
#
# The path to the solution/example/exemplar files can be found in the exercise's
# .meta/config.json file, or possibly inferred from the exercise's directory name.

# Example:
# ./bin/test

exit_code=0

# Verify the Concept Exercises
# for concept_exercise_dir in ./exercises/concept/*/; do
# if [ -d $concept_exercise_dir ]; then
# echo "Checking $(basename "${concept_exercise_dir}") exercise..."
# # TODO: run command to verify that the exemplar solution passes the tests
# fi
# done

# Verify the Practice Exercises
for practice_exercise_dir in ./exercises/practice/*/; do
if [ -d $practice_exercise_dir ]; then
echo "Checking $(basename "${practice_exercise_dir}") exercise..."
res=$(/opt/j9.5/bin/jconsole bin/test_exercise.ijs "$practice_exercise_dir/")
if [ $? -ne 0 ]; then
echo "Error in ${practice_exercise_dir}"
((exit_code++))
fi
fi
done

exit $exit_code
Loading