[gjs/ewlsh/fix-callback-exit] Add tests for System.exit in a signal callback.
- From: Evan Welsh <ewlsh src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/ewlsh/fix-callback-exit] Add tests for System.exit in a signal callback.
- Date: Mon, 1 Mar 2021 06:39:55 +0000 (UTC)
commit 564f350a91a506b3b143c14b6e27e3b7195f1718
Author: Evan Welsh <contact evanwelsh com>
Date: Sun Feb 28 22:16:00 2021 -0800
Add tests for System.exit in a signal callback.
installed-tests/scripts/testCommandLine.sh | 46 +++++++++++++++++++++++++++++-
1 file changed, 45 insertions(+), 1 deletion(-)
---
diff --git a/installed-tests/scripts/testCommandLine.sh b/installed-tests/scripts/testCommandLine.sh
index f3bb9c9f..914cbc8f 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
+ 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"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]