Skip to content

Commit

Permalink
Fix FAIL and QUIT exit status, add CI Tests
Browse files Browse the repository at this point in the history
Due to changes related to merging DO and IMPORT for the
module system, scripts which were failing or running QUIT with a nonzero
exit code were still giving zero at exit.  This was meaning there was
no alert to the GitHub Action regarding failure.

This tries to workaround the problem by adding to the clearly unfinished
feature of QUIT handling for the common code path for import.  But also
adds in tests designed to fail for the CI to make sure they give the
right failing exit codes.
  • Loading branch information
hostilefork committed Nov 21, 2021
1 parent cf62668 commit 01fd1c2
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 5 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/linux-gcc-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,59 @@ jobs:
run: |
"$R3BUILT" --do "print {hi}"
# Besides just testing success cases, it's important to make sure failures
# actually report bad exit codes, or a lot of the GitHub Actions intended
# for testing will be useless.
#
# Note we can't run the command and check the special `$?` shell variable
# after the fact, because the default is to run `bash -e` for the shell...
# which would immediately fail the step if a nonzero exit is returned. We
# extract the exit status using the $(...)$? pattern:
#
# https://unix.stackexchange.com/a/606751

- name: FAIL Test (from code on command line)
run: |
retval=$("$R3BUILT" --do "fail {The Error Message}")$? # see above
if [ $retval -eq 1 ]; then
echo "FAIL Properly Gave Exit Status 1"
else
echo "Expected Exit Status 1, But Got $retval"
exit 1
fi
- name: FAIL Test (from running a script)
run: |
retval=$("$R3BUILT" tests/misc/fail-script.r)$? # see above
if [ $retval -eq 1 ]; then
echo "FAIL Properly Gave Exit Status 1"
else
echo "Expected Exit Status 1, But Got $retval"
exit 1
fi
- name: QUIT Test (from code on command line)
run: |
retval=$("$R3BUILT" --do "quit 3")$? # see above
if [ $retval -eq 3 ]; then
echo "QUIT Properly Gave Exit Status 3"
else
echo "Expected Exit Status 3, But Got $retval"
exit 1
fi
- name: QUIT Test (from running a script)
run: |
retval=$("$R3BUILT" tests/misc/quit-script.r)$? # see above
if [ $retval -eq 3 ]; then
echo "QUIT Properly Gave Exit Status 3"
else
echo "Expected Exit Status 3, But Got $retval"
exit 1
fi
- name: Check Time Matches
shell: r3built --fragment {0} # See README: Ren-C Code As Step
run: |
Expand Down Expand Up @@ -292,6 +345,7 @@ jobs:
fail "Times Did Not Match"
- name: HTTPS Read Test (If This Works, A Lot Of Things Are Working)
shell: r3built --fragment {0} # See README: Ren-C Code As Step
run: |
Expand Down
52 changes: 52 additions & 0 deletions .github/workflows/windows-msvc-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,58 @@ jobs:
"$R3BUILT" --do "print {hi}"
# Besides just testing success cases, it's important to make sure failures
# actually report bad exit codes, or a lot of the GitHub Actions intended
# for testing will be useless.
#
# Note we can't run the command and check the special `$?` shell variable
# after the fact, because the default is to run `bash -e` for the shell...
# which would immediately fail the step if a nonzero exit is returned. We
# extract the exit status using the $(...)$? pattern:
#
# https://unix.stackexchange.com/a/606751

- name: FAIL Test (from code on command line)
run: |
retval=$("$R3BUILT" --do "fail {The Error Message}")$? # see above
if [ $retval -eq 1 ]; then
echo "FAIL Properly Gave Exit Status 1"
else
echo "Expected Exit Status 1, But Got $retval"
exit 1
fi
- name: FAIL Test (from running a script)
run: |
retval=$("$R3BUILT" tests/misc/fail-script.r)$? # see above
if [ $retval -eq 1 ]; then
echo "FAIL Properly Gave Exit Status 1"
else
echo "Expected Exit Status 1, But Got $retval"
exit 1
fi
- name: QUIT Test (from code on command line)
run: |
retval=$("$R3BUILT" --do "quit 3")$? # see above
if [ $retval -eq 3 ]; then
echo "QUIT Properly Gave Exit Status 3"
else
echo "Expected Exit Status 3, But Got $retval"
exit 1
fi
- name: QUIT Test (from running a script)
run: |
retval=$("$R3BUILT" tests/misc/quit-script.r)$? # see above
if [ $retval -eq 3 ]; then
echo "QUIT Properly Gave Exit Status 3"
else
echo "Expected Exit Status 3, But Got $retval"
exit 1
fi
- name: HTTPS Read Test (If This Works, A Lot Of Things Are Working)
shell: r3built --fragment {0} # See README: Ren-C Code As Step
run: |
Expand Down
13 changes: 11 additions & 2 deletions src/mezz/sys-base.r
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ module: func [
return: [module!]
product: "The result of running the body (~quit~ isotope if it ran QUIT)"
[<opt> any-value!]
quitting: "If requested and quitting, when true PRODUCT is QUIT's argument"
[logic!]

spec "The header block of the module (modified)"
[blank! block! object!]
Expand Down Expand Up @@ -159,11 +161,18 @@ module: func [
; if that module's init code decided to QUIT to end processing prematurely.
; (QUIT is not a failure when running scripts.)
;
product: default [#]
catch/quit [
set (product: default [#]) do body
set product do body
if quitting [set quitting false]
]
then ^arg-to-quit -> [
set product unmeta arg-to-quit
if quitting [
set quitting true
set product unmeta arg-to-quit
] else [
set product ~quit~ ; don't give distinction in result
]
]

return mod
Expand Down
4 changes: 1 addition & 3 deletions src/mezz/sys-load.r
Original file line number Diff line number Diff line change
Expand Up @@ -533,9 +533,7 @@ import*: func [
; from the unfinished R3-Alpha module system, and its decade of atrophy
; that happened after that...

let quitting: false

let [mod '(product)]: module/into/file/line try hdr code into file line
let [mod '(product) quitting]: module/into/file/line try hdr code into file line

ensure module! mod

Expand Down
9 changes: 9 additions & 0 deletions tests/misc/fail-script.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Rebol [
Title: {FAIL with an error}
Description: {
Used by GitHub Actions to make sure FAIL gives a nonzero exit code.
}
]

print "FAILing with a message (should give exit code 1)"
fail {The Error Message}
9 changes: 9 additions & 0 deletions tests/misc/quit-script.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Rebol [
Title: {Quit With Exit Code 3}
Description: {
Used by GitHub Actions to make sure QUIT with exit code is honored.
}
]

print "Quitting With Exit Code 3"
quit 3

0 comments on commit 01fd1c2

Please sign in to comment.