gjs r58 - in trunk: . test test/js test/js/modules test/js/modules/subA test/js/modules/subA/subB



Author: jobi
Date: Fri Oct 24 15:17:25 2008
New Revision: 58
URL: http://svn.gnome.org/viewvc/gjs?rev=58&view=rev

Log:
Add testImporter.js

Unit test for the importer, and related test module files.
add test/js/modules to GJS_PATH

Added:
   trunk/test/js/modules/alwaysThrows.js
   trunk/test/js/modules/foobar.js
   trunk/test/js/modules/subA/
   trunk/test/js/modules/subA/foo
   trunk/test/js/modules/subA/subB/
   trunk/test/js/modules/subA/subB/baz.js
   trunk/test/js/modules/subA/subB/foobar.js
   trunk/test/js/testImporter.js
Modified:
   trunk/Makefile-test.am
   trunk/test/gjs-unit.c

Modified: trunk/Makefile-test.am
==============================================================================
--- trunk/Makefile-test.am	(original)
+++ trunk/Makefile-test.am	Fri Oct 24 15:17:25 2008
@@ -72,10 +72,18 @@
 check:	test
 
 
-EXTRA_DIST +=				\
-	test/js/modules/jsUnit.js	\
-	test/js/testself.js		\
-	test/js/testLang.js		\
-	test/js/testMainloop.js		\
-	test/js/testSignals.js		\
+EXTRA_DIST +=					\
+	test/js/modules/jsUnit.js		\
+	test/js/modules/alwaysThrows.js         \
+	test/js/modules/foobar.js               \
+	test/js/modules/subA/foo                \
+	test/js/modules/subA/subB/foobar.js     \
+	test/js/modules/subA/subB/baz.js        \
+	test/js/modules/jsUnit.js               \
+	test/js/modules/testUtil.js             \
+	test/js/testself.js			\
+	test/js/testImporter.js			\
+	test/js/testLang.js			\
+	test/js/testMainloop.js			\
+	test/js/testSignals.js			\
 	test/js/testTweener.js

Modified: trunk/test/gjs-unit.c
==============================================================================
--- trunk/test/gjs-unit.c	(original)
+++ trunk/test/gjs-unit.c	Fri Oct 24 15:17:25 2008
@@ -101,7 +101,7 @@
     g_setenv("TOP_SRCDIR", GJS_TOP_SRCDIR, FALSE);
     g_setenv("BUILDDIR", GJS_BUILDDIR, FALSE);
     g_setenv("XDG_DATA_HOME", GJS_BUILDDIR "/test_user_data", FALSE);
-    g_setenv("GJS_PATH", GJS_TOP_SRCDIR"/modules:"GJS_BUILDDIR"/.libs", FALSE);
+    g_setenv("GJS_PATH", GJS_TOP_SRCDIR"/modules:"GJS_TOP_SRCDIR"/test/js/modules:"GJS_BUILDDIR"/.libs:", FALSE);
 
     /* need ${top_srcdir} later */
     top_srcdir = g_getenv ("TOP_SRCDIR");

Added: trunk/test/js/modules/alwaysThrows.js
==============================================================================
--- (empty file)
+++ trunk/test/js/modules/alwaysThrows.js	Fri Oct 24 15:17:25 2008
@@ -0,0 +1,4 @@
+// line 0
+// line 1
+// line 2
+throw new Error("This is an error that always happens on line 3");

Added: trunk/test/js/modules/foobar.js
==============================================================================
--- (empty file)
+++ trunk/test/js/modules/foobar.js	Fri Oct 24 15:17:25 2008
@@ -0,0 +1,4 @@
+// simple test module (used by testImporter.js)
+
+var foo = "This is foo";
+var bar = "This is bar";

Added: trunk/test/js/modules/subA/foo
==============================================================================

Added: trunk/test/js/modules/subA/subB/baz.js
==============================================================================

Added: trunk/test/js/modules/subA/subB/foobar.js
==============================================================================
--- (empty file)
+++ trunk/test/js/modules/subA/subB/foobar.js	Fri Oct 24 15:17:25 2008
@@ -0,0 +1,4 @@
+// simple test module (used by testImporter.js)
+
+var foo = "This is foo";
+var bar = "This is bar";

Added: trunk/test/js/testImporter.js
==============================================================================
--- (empty file)
+++ trunk/test/js/testImporter.js	Fri Oct 24 15:17:25 2008
@@ -0,0 +1,74 @@
+function testImporter() {
+
+    assertNotUndefined(imports);
+
+    assertRaises(function() { const m = imports.nonexistentModuleName; });
+    assertRaises(function() { const m = imports.alwaysThrows; });
+
+    // Import a non-broken module
+    const foobar = imports.foobar;
+    assertNotUndefined(foobar);
+    assertNotUndefined(foobar.foo);
+    assertNotUndefined(foobar.bar);
+    assertEquals(foobar.foo, "This is foo");
+    assertEquals(foobar.bar, "This is bar");
+
+    // check that importing a second time gets the same object
+    foobar.somethingElse = "Should remain";
+    const foobar2 = imports.foobar;
+    assertNotUndefined(foobar2.somethingElse);
+    assertEquals(foobar2.somethingElse, "Should remain");
+
+    // Try a sub-module
+    const subB = imports.subA.subB;
+    assertNotUndefined(subB);
+    const subFoobar = subB.foobar;
+    assertNotUndefined(subFoobar);
+    assertNotUndefined(subFoobar.foo);
+    assertNotUndefined(subFoobar.bar);
+    assertEquals(subFoobar.foo, "This is foo");
+    assertEquals(subFoobar.bar, "This is bar");
+    // subFoobar should not be the same as foobar, even though
+    // they have the same basename.
+    assertUndefined(subFoobar.somethingElse);
+    // importing subFoobar a second time should get the same module
+    subFoobar.someProp = "Should be here";
+    const subFoobar2 = imports.subA.subB.foobar;
+    assertNotUndefined(subFoobar2.someProp);
+    assertEquals(subFoobar2.someProp, "Should be here");
+}
+
+function testImporterMetaProps() {
+    const subA = imports.subA;
+    const subB = imports.subA.subB;
+
+    assertNull('imports module name', imports.__moduleName__);
+    assertNull('imports has no parent', imports.__parentModule__);
+    assertEquals('imports.subA module name', 'subA', subA.__moduleName__);
+    assertEquals('imports.subA parent module', imports, subA.__parentModule__);
+    assertEquals('imports.subA.subB module name', 'subB', subB.__moduleName__);
+    assertEquals('imports.subA.subB parent module', subA, subB.__parentModule__);
+}
+
+function testImporterEnumerate() {
+    const subA = imports.subA;
+    const subB = imports.subA.subB;
+    let subModules = [];
+
+    for (let module in subA) {
+        subModules.push(module);
+    }
+
+    assertNotEquals(subModules.indexOf('subB'), -1);
+    assertEquals(subModules.indexOf('foo'), -1);
+
+    for (let module in subB) {
+        subModules.push(module);
+    }
+
+    assertNotEquals(subModules.indexOf('baz'), -1);
+    assertNotEquals(subModules.indexOf('foobar'), -1);
+
+}
+
+gjstestRun();



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]