diff options
Diffstat (limited to 'installed-tests')
-rw-r--r-- | installed-tests/js/jsunit.gresources.xml | 4 | ||||
-rw-r--r-- | installed-tests/js/meson.build | 1 | ||||
-rw-r--r-- | installed-tests/js/minijasmine.js | 1 | ||||
-rw-r--r-- | installed-tests/js/modules/badOverrides2/.eslintrc.yml | 8 | ||||
-rw-r--r-- | installed-tests/js/modules/badOverrides2/GIMarshallingTests.js | 5 | ||||
-rw-r--r-- | installed-tests/js/modules/badOverrides2/Gio.js | 5 | ||||
-rw-r--r-- | installed-tests/js/modules/badOverrides2/Regress.js | 5 | ||||
-rw-r--r-- | installed-tests/js/modules/badOverrides2/WarnLib.js | 3 | ||||
-rw-r--r-- | installed-tests/js/testESModules.js | 6 | ||||
-rw-r--r-- | installed-tests/js/testImporter.js | 2 | ||||
-rw-r--r-- | installed-tests/js/testImporter2.js | 39 | ||||
-rw-r--r-- | installed-tests/minijasmine.cpp | 1 |
12 files changed, 77 insertions, 3 deletions
diff --git a/installed-tests/js/jsunit.gresources.xml b/installed-tests/js/jsunit.gresources.xml index 209274fc..75c54c90 100644 --- a/installed-tests/js/jsunit.gresources.xml +++ b/installed-tests/js/jsunit.gresources.xml @@ -13,6 +13,10 @@ <file>modules/badOverrides/Gio.js</file> <file>modules/badOverrides/Regress.js</file> <file>modules/badOverrides/WarnLib.js</file> + <file>modules/badOverrides2/GIMarshallingTests.js</file> + <file>modules/badOverrides2/Gio.js</file> + <file>modules/badOverrides2/Regress.js</file> + <file>modules/badOverrides2/WarnLib.js</file> <file>modules/subBadInit/__init__.js</file> <file>modules/subErrorInit/__init__.js</file> <file>modules/data.txt</file> diff --git a/installed-tests/js/meson.build b/installed-tests/js/meson.build index 5520a19d..6db887d2 100644 --- a/installed-tests/js/meson.build +++ b/installed-tests/js/meson.build @@ -127,6 +127,7 @@ jasmine_tests = [ 'GObjectValue', 'GTypeClass', 'Importer', + 'Importer2', 'Introspection', 'Lang', 'LegacyByteArray', diff --git a/installed-tests/js/minijasmine.js b/installed-tests/js/minijasmine.js index 36f953bc..cd00f611 100644 --- a/installed-tests/js/minijasmine.js +++ b/installed-tests/js/minijasmine.js @@ -10,7 +10,6 @@ function _filterStack(stack) { return stack.split('\n') .filter(stackLine => stackLine.indexOf('resource:///org/gjs/jsunit') === -1) - .filter(stackLine => stackLine.indexOf('<jasmine-start>') === -1) .join('\n'); } diff --git a/installed-tests/js/modules/badOverrides2/.eslintrc.yml b/installed-tests/js/modules/badOverrides2/.eslintrc.yml new file mode 100644 index 00000000..b1c10f5d --- /dev/null +++ b/installed-tests/js/modules/badOverrides2/.eslintrc.yml @@ -0,0 +1,8 @@ +--- +# SPDX-License-Identifier: MIT OR LGPL-2.0-or-later +# SPDX-FileCopyrightText: 2018 Philip Chimento <philip.chimento@gmail.com> +rules: + no-throw-literal: 'off' # these are intended to be bad code + no-unused-vars: + - error + - varsIgnorePattern: ^_init$ diff --git a/installed-tests/js/modules/badOverrides2/GIMarshallingTests.js b/installed-tests/js/modules/badOverrides2/GIMarshallingTests.js new file mode 100644 index 00000000..6cf2dfa9 --- /dev/null +++ b/installed-tests/js/modules/badOverrides2/GIMarshallingTests.js @@ -0,0 +1,5 @@ +// Sabotage the import of imports.gi.GIMarshallingTests! +// SPDX-License-Identifier: MIT OR LGPL-2.0-or-later +// SPDX-FileCopyrightText: 2023 Philip Chimento <philip.chimento@gmail.com> + +var _init = {thingsThatThisObjectIsNot: ['callable']}; diff --git a/installed-tests/js/modules/badOverrides2/Gio.js b/installed-tests/js/modules/badOverrides2/Gio.js new file mode 100644 index 00000000..9758a7c0 --- /dev/null +++ b/installed-tests/js/modules/badOverrides2/Gio.js @@ -0,0 +1,5 @@ +// Sabotage the import of imports.gi.Gio! +// SPDX-License-Identifier: MIT OR LGPL-2.0-or-later +// SPDX-FileCopyrightText: 2023 Philip Chimento <philip.chimento@gmail.com> + +var _init = null; diff --git a/installed-tests/js/modules/badOverrides2/Regress.js b/installed-tests/js/modules/badOverrides2/Regress.js new file mode 100644 index 00000000..e4252f67 --- /dev/null +++ b/installed-tests/js/modules/badOverrides2/Regress.js @@ -0,0 +1,5 @@ +// Sabotage the import of imports.gi.Regress! +// SPDX-License-Identifier: MIT OR LGPL-2.0-or-later +// SPDX-FileCopyrightText: 2023 Philip Chimento <philip.chimento@gmail.com> + +var _init; diff --git a/installed-tests/js/modules/badOverrides2/WarnLib.js b/installed-tests/js/modules/badOverrides2/WarnLib.js new file mode 100644 index 00000000..b2c93b05 --- /dev/null +++ b/installed-tests/js/modules/badOverrides2/WarnLib.js @@ -0,0 +1,3 @@ +// Sabotage the import of imports.gi.WarnLib! +// SPDX-License-Identifier: MIT OR LGPL-2.0-or-later +// SPDX-FileCopyrightText: 2023 Philip Chimento <philip.chimento@gmail.com> diff --git a/installed-tests/js/testESModules.js b/installed-tests/js/testESModules.js index 30db17e4..e727c790 100644 --- a/installed-tests/js/testESModules.js +++ b/installed-tests/js/testESModules.js @@ -27,26 +27,32 @@ describe('ES module imports', function () { it('import with version parameter', function () { expect(gi.require('GObject', '2.0')).toBe(gi.require('GObject')); + expect(imports.gi.versions['GObject']).toBe('2.0'); }); it('import again with other version parameter', function () { expect(() => gi.require('GObject', '1.75')).toThrow(); + expect(imports.gi.versions['GObject']).toBe('2.0'); }); it('import for the first time with wrong version', function () { expect(() => gi.require('Gtk', '1.75')).toThrow(); + expect(imports.gi.versions['Gtk']).not.toBeDefined(); }); it('import with another version after a failed import', function () { expect(gi.require('Gtk', '3.0').toString()).toEqual('[object GIRepositoryNamespace]'); + expect(imports.gi.versions['Gtk']).toBe('3.0'); }); it('import nonexistent module', function () { expect(() => gi.require('PLib')).toThrow(); + expect(imports.gi.versions['PLib']).not.toBeDefined(); }); it('GObject introspection import via URL scheme', function () { expect(Gio.toString()).toEqual('[object GIRepositoryNamespace]'); + expect(imports.gi.versions['Gio']).toBe('2.0'); }); it('import.meta.url', function () { diff --git a/installed-tests/js/testImporter.js b/installed-tests/js/testImporter.js index 8380af20..f03bf634 100644 --- a/installed-tests/js/testImporter.js +++ b/installed-tests/js/testImporter.js @@ -32,7 +32,7 @@ describe('GI importer', function () { expect(() => imports.gi.Regress).toThrow('💩'); }); - it("throws an exception when the overrides _init isn't a function", function () { + it('throws an exception when the overrides _init is a primitive', function () { expect(() => imports.gi.Gio).toThrowError(/_init/); }); }); diff --git a/installed-tests/js/testImporter2.js b/installed-tests/js/testImporter2.js new file mode 100644 index 00000000..b4e71225 --- /dev/null +++ b/installed-tests/js/testImporter2.js @@ -0,0 +1,39 @@ +// SPDX-License-Identifier: MIT OR LGPL-2.0-or-later +// SPDX-FileCopyrightText: 2023 Philip Chimento <philip.chimento@gmail.com> + +// This test is in a separate file instead of testImporter.js, because it tests +// loading overrides for g-i modules, and in the original file we have literally +// run out of g-i modules to override -- at least, the ones that we can assume +// will be present on any system where GJS is compiled. + +describe('GI importer', function () { + describe('on failure', function () { + // For these tests, we provide special overrides files to sabotage the + // import, at the path resource:///org/gjs/jsunit/modules/badOverrides2. + let oldSearchPath; + beforeAll(function () { + oldSearchPath = imports.overrides.searchPath.slice(); + imports.overrides.searchPath = ['resource:///org/gjs/jsunit/modules/badOverrides2']; + }); + + afterAll(function () { + imports.overrides.searchPath = oldSearchPath; + }); + + it("throws an exception when the overrides _init isn't a function", function () { + expect(() => imports.gi.GIMarshallingTests).toThrowError(/_init/); + }); + + it('throws an exception when the overrides _init is null', function () { + expect(() => imports.gi.Gio).toThrowError(/_init/); + }); + + it('throws an exception when the overrides _init is undefined', function () { + expect(() => imports.gi.Regress).toThrowError(/_init/); + }); + + it('throws an exception when the overrides _init is missing', function () { + expect(() => imports.gi.WarnLib).toThrowError(/_init/); + }); + }); +}); diff --git a/installed-tests/minijasmine.cpp b/installed-tests/minijasmine.cpp index 9d1c65f9..3036fb87 100644 --- a/installed-tests/minijasmine.cpp +++ b/installed-tests/minijasmine.cpp @@ -33,7 +33,6 @@ main(int argc, char **argv) if (argc < 2) g_error("Need a test file"); - /* The fact that this isn't the default is kind of lame... */ g_setenv("GJS_DEBUG_OUTPUT", "stderr", false); setlocale(LC_ALL, ""); |