diff options
author | Evan Welsh <contact@evanwelsh.com> | 2021-02-28 22:16:00 -0800 |
---|---|---|
committer | Evan Welsh <contact@evanwelsh.com> | 2021-02-28 22:45:49 -0800 |
commit | 94441de45b8a17e3e6d3f1dc8c4c2937455ebf6b (patch) | |
tree | 70e9e1fcf852e44539333ad85f658d0106cb2cf0 | |
parent | 091c25b47d3f42578a01bddcb7e39fda165c272f (diff) | |
download | gjs-94441de45b8a17e3e6d3f1dc8c4c2937455ebf6b.tar.gz |
Add tests for System.exit in a signal callback.ewlsh/fix-callback-exit
-rwxr-xr-x | installed-tests/scripts/testCommandLine.sh | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/installed-tests/scripts/testCommandLine.sh b/installed-tests/scripts/testCommandLine.sh index f3bb9c9f..10eaea26 100755 --- a/installed-tests/scripts/testCommandLine.sh +++ b/installed-tests/scripts/testCommandLine.sh @@ -75,6 +75,34 @@ else System.exit(1); EOF +# this JS script is used to test correct exiting from signal callbacks +cat <<EOF >signalexit.js +import GLib from 'gi://GLib'; +import GObject from 'gi://GObject'; +import { exit } from 'system'; + +const Button = GObject.registerClass({ + Signals: { + 'clicked': {}, + }, +}, class Button extends GObject.Object { + go() { + this.emit('clicked'); + } +}); + +const button = new Button(); +button.connect('clicked', () => exit(15)); +let n = 1; +GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, 2, () => { + print(\`click \${n++}\`); + button.go(); + return GLib.SOURCE_CONTINUE; +}); +const loop = new GLib.MainLoop(null, false); +loop.run(); +EOF + total=0 report () { @@ -279,6 +307,22 @@ rm -f coverage.lcov $gjs -m doublegi.js 2>&1 | grep -q 'already loaded' report "avoid statically importing two versions of the same module" -rm -f exit.js help.js promise.js awaitcatch.js doublegi.js argv.js +# https://gitlab.gnome.org/GNOME/gjs/-/issues/19 +echo "# VALGRIND = $VALGRIND" +if test -z $VALGRIND; then + ASAN_OPTIONS=detect_leaks=0 output=$($gjs -m signalexit.js) + test $? -eq 15 + report "exit with correct code from a signal callback" + test -n "$output" -a -z "${output##*click 1*}" + report "avoid asserting when System.exit is called from a signal callback" + test -n "${output##*click 2*}" + report "exit after first System.exit call in a signal callback" +else + skip "exit with correct code from a signal callback" "running under valgrind" + skip "avoid asserting when System.exit is called from a signal callback" "running under valgrind" + skip "exit after first System.exit call in a signal callback" "running under valgrind" +fi + +rm -f exit.js help.js promise.js awaitcatch.js doublegi.js argv.js signalexit.js echo "1..$total" |