[gjs/ewlsh/fix-callback-exit] Add tests for System.exit in a signal callback.



commit 57625f29afebe494b7d2564400e5b6962e7dd528
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 | 39 +++++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)
---
diff --git a/installed-tests/scripts/testCommandLine.sh b/installed-tests/scripts/testCommandLine.sh
index f3bb9c9f..f4fb49c1 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,15 @@ 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
+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"
+
+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]