[gjs] tests: Reinstate importer test
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs] tests: Reinstate importer test
- Date: Sat, 22 Oct 2016 05:08:34 +0000 (UTC)
commit 6a80c321128d0a2a94a4b02b58b793a25b952c35
Author: Philip Chimento <philip endlessm com>
Date: Fri Oct 21 17:12:00 2016 -0700
tests: Reinstate importer test
Now that it's possible to import modules from resource:// URIs, we can
reinstate the importer test that got removed when the test suite was
converted to an installed test suite.
The resulting file is slightly different from the one that got removed in
[54538f3da91b25ed20c9deaeda00d57fb252227c]. In the intervening time,
importer objects have lost the ability to enumerate their properties, so
we remove the corresponding tests.
The importer test's data files were still hanging around in the source
tree anyway, so they get added to the jsunit GResource and EXTRA_DIST. We
remove a few that were only used in the importer enumeration tests.
https://bugzilla.gnome.org/show_bug.cgi?id=773335
Makefile-insttest.am | 3 +-
installed-tests/js/jsunit.gresources.xml | 8 ++
installed-tests/js/testImporter.js | 115 +++++++++++++++++++++
3 files changed, 125 insertions(+), 1 deletions(-)
---
diff --git a/Makefile-insttest.am b/Makefile-insttest.am
index 4bc1165..bb13b6b 100644
--- a/Makefile-insttest.am
+++ b/Makefile-insttest.am
@@ -2,7 +2,6 @@ EXTRA_DIST += \
installed-tests/jsunit.test.in \
installed-tests/script.test.in \
installed-tests/js/jsunit.gresources.xml \
- installed-tests/js/complex.ui \
$(NULL)
installedtestmetadir = $(datadir)/installed-tests/gjs
@@ -47,6 +46,7 @@ jsunit-resources.c: $(srcdir)/installed-tests/js/jsunit.gresources.xml $(jsunit_
BUILT_SOURCES += jsunit-resources.h jsunit-resources.c
CLEANFILES += jsunit-resources.h jsunit-resources.c
+EXTRA_DIST += $(jsunit_resources_files)
common_test_ldflags = -avoid-version
common_test_libadd = $(GJS_LIBS)
@@ -158,6 +158,7 @@ common_jstests_files = \
installed-tests/js/testGObjectClass.js \
installed-tests/js/testGObjectInterface.js \
installed-tests/js/testGTypeClass.js \
+ installed-tests/js/testImporter.js \
installed-tests/js/testInterface.js \
installed-tests/js/testJS1_8.js \
installed-tests/js/testLang.js \
diff --git a/installed-tests/js/jsunit.gresources.xml b/installed-tests/js/jsunit.gresources.xml
index 1086841..944626b 100644
--- a/installed-tests/js/jsunit.gresources.xml
+++ b/installed-tests/js/jsunit.gresources.xml
@@ -2,5 +2,13 @@
<gresources>
<gresource prefix="/org/gjs/jsunit">
<file preprocess="xml-stripblanks">complex.ui</file>
+ <file>modules/alwaysThrows.js</file>
+ <file>modules/foobar.js</file>
+ <file>modules/modunicode.js</file>
+ <file>modules/mutualImport/a.js</file>
+ <file>modules/mutualImport/b.js</file>
+ <file>modules/subA/subB/__init__.js</file>
+ <file>modules/subA/subB/baz.js</file>
+ <file>modules/subA/subB/foobar.js</file>
</gresource>
</gresources>
diff --git a/installed-tests/js/testImporter.js b/installed-tests/js/testImporter.js
new file mode 100644
index 0000000..ee91160
--- /dev/null
+++ b/installed-tests/js/testImporter.js
@@ -0,0 +1,115 @@
+const JSUnit = imports.jsUnit;
+
+function testImporter() {
+ JSUnit.assertNotUndefined(imports);
+
+ JSUnit.assertRaises(() => imports.nonexistentModuleName);
+ JSUnit.assertRaises(() => imports.alwaysThrows);
+
+ // Try again to make sure that we properly discarded the module object
+ JSUnit.assertRaises(() => imports.alwaysThrows);
+
+ // Import a non-broken module
+ const foobar = imports.foobar;
+ JSUnit.assertNotUndefined(foobar);
+ JSUnit.assertNotUndefined(foobar.foo);
+ JSUnit.assertNotUndefined(foobar.bar);
+ JSUnit.assertEquals(foobar.foo, "This is foo");
+ JSUnit.assertEquals(foobar.bar, "This is bar");
+
+ // Check that deleting the import is a no-op (imported properties are
+ // permanent)
+ JSUnit.assertFalse(delete imports.foobar);
+ JSUnit.assert(imports.foobar == foobar);
+
+ // check that importing a second time gets the same object
+ foobar.somethingElse = "Should remain";
+ const foobar2 = imports.foobar;
+ JSUnit.assertNotUndefined(foobar2.somethingElse);
+ JSUnit.assertEquals(foobar2.somethingElse, "Should remain");
+
+ // Try a sub-module
+ const subB = imports.subA.subB;
+ JSUnit.assertNotUndefined(subB);
+ const subFoobar = subB.foobar;
+ JSUnit.assertNotUndefined(subFoobar);
+ JSUnit.assertNotUndefined(subFoobar.foo);
+ JSUnit.assertNotUndefined(subFoobar.bar);
+ JSUnit.assertEquals(subFoobar.foo, "This is foo");
+ JSUnit.assertEquals(subFoobar.bar, "This is bar");
+ // subFoobar should not be the same as foobar, even though
+ // they have the same basename.
+ JSUnit.assertUndefined(subFoobar.somethingElse);
+ // importing subFoobar a second time should get the same module
+ subFoobar.someProp = "Should be here";
+ const subFoobar2 = imports.subA.subB.foobar;
+ JSUnit.assertNotUndefined(subFoobar2.someProp);
+ JSUnit.assertEquals(subFoobar2.someProp, "Should be here");
+}
+
+function testImporterMetaProps() {
+ const subA = imports.subA;
+ const subB = imports.subA.subB;
+
+ JSUnit.assertNull('imports module name', imports.__moduleName__);
+ JSUnit.assertNull('imports has no parent', imports.__parentModule__);
+ JSUnit.assertEquals('imports.subA module name', 'subA', subA.__moduleName__);
+ JSUnit.assertEquals('imports.subA parent module', imports, subA.__parentModule__);
+ JSUnit.assertEquals('imports.subA.subB module name', 'subB', subB.__moduleName__);
+ JSUnit.assertEquals('imports.subA.subB parent module', subA, subB.__parentModule__);
+}
+
+function testMutualImport() {
+ // We want to check that the copy of the 'a' module imported directly
+ // is the same as the copy that 'b' imports, and that we don't have two
+ // copies because of the A imports B imports A loop.
+
+ let A = imports.mutualImport.a;
+ A.incrementCount();
+ JSUnit.assertEquals(1, A.getCount());
+ JSUnit.assertEquals(1, A.getCountViaB());
+}
+
+function testImporterFunctionFromInitFile() {
+ const subB = imports.subA.subB;
+
+ JSUnit.assertNotUndefined(subB.testImporterFunction);
+
+ let result = subB.testImporterFunction();
+
+ JSUnit.assertEquals(result, "__init__ function tested");
+}
+
+function testImporterClassFromInitFile() {
+ const subB = imports.subA.subB;
+
+ JSUnit.assertNotUndefined(subB.ImporterClass);
+
+ let o = new subB.ImporterClass();
+
+ JSUnit.assertNotNull(o);
+
+ let result = o.testMethod();
+
+ JSUnit.assertEquals(result, "__init__ class tested");
+}
+
+function testImporterUTF8() {
+ const ModUnicode = imports.modunicode;
+ JSUnit.assertEquals(ModUnicode.uval, "const \u2665 utf8");
+}
+
+let oldSearchPath;
+
+function setUp() {
+ JSUnit.setUp();
+ oldSearchPath = imports.searchPath.slice();
+ imports.searchPath = ['resource:///org/gjs/jsunit/modules'];
+}
+
+function tearDown() {
+ JSUnit.tearDown();
+ imports.searchPath = oldSearchPath;
+}
+
+JSUnit.gjstestRun(this, setUp, tearDown);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]