Permalink
Browse files

added test cases for require() and friends

   https://issues.apache.org/jira/browse/CB-267

Added the commonjs test suite from:

   https://github.com/commonjs/commonjs

Those tests are now in

   thirdparty/commonjs-tests

Test scaffolding has been added to

   test/commonjs

See the README.txt file in that directory for
instructions on running the tests.

In addition, the LICENSE was modified to include
information on the commonjs tests and existing
jasmine usage.  A NOTICE file was also added,
since it was not available before.
  • Loading branch information...
1 parent 8513d59 commit d7341998e657598a8419aa421d84e5bebbb26494 @pmuellr pmuellr committed Feb 20, 2012
Showing with 777 additions and 3 deletions.
  1. +93 −3 LICENSE
  2. +5 −0 NOTICE
  3. +1 −0 test/commonjs/.gitignore
  4. +11 −0 test/commonjs/README.txt
  5. +196 −0 test/commonjs/build-tests.py
  6. +73 −0 test/commonjs/launcher-in-iframe.template.html
  7. +74 −0 test/commonjs/launcher-main.template.html
  8. +43 −0 test/commonjs/test.css
  9. +9 −0 thirdparty/commonjs-tests/README.txt
  10. +1 −0 thirdparty/commonjs-tests/modules/1.0/absolute/b.js
  11. +5 −0 thirdparty/commonjs-tests/modules/1.0/absolute/program.js
  12. +3 −0 thirdparty/commonjs-tests/modules/1.0/absolute/submodule/a.js
  13. +15 −0 thirdparty/commonjs-tests/modules/1.0/absolute/test.js
  14. +4 −0 thirdparty/commonjs-tests/modules/1.0/cyclic/a.js
  15. +4 −0 thirdparty/commonjs-tests/modules/1.0/cyclic/b.js
  16. +10 −0 thirdparty/commonjs-tests/modules/1.0/cyclic/program.js
  17. +15 −0 thirdparty/commonjs-tests/modules/1.0/cyclic/test.js
  18. +3 −0 thirdparty/commonjs-tests/modules/1.0/determinism/program.js
  19. +9 −0 thirdparty/commonjs-tests/modules/1.0/determinism/submodule/a.js
  20. +2 −0 thirdparty/commonjs-tests/modules/1.0/determinism/submodule/b.js
  21. +15 −0 thirdparty/commonjs-tests/modules/1.0/determinism/test.js
  22. +3 −0 thirdparty/commonjs-tests/modules/1.0/exactExports/a.js
  23. +4 −0 thirdparty/commonjs-tests/modules/1.0/exactExports/program.js
  24. +15 −0 thirdparty/commonjs-tests/modules/1.0/exactExports/test.js
  25. 0 thirdparty/commonjs-tests/modules/1.0/hasOwnProperty/hasOwnProperty.js
  26. +4 −0 thirdparty/commonjs-tests/modules/1.0/hasOwnProperty/program.js
  27. +15 −0 thirdparty/commonjs-tests/modules/1.0/hasOwnProperty/test.js
  28. 0 thirdparty/commonjs-tests/modules/1.0/hasOwnProperty/toString.js
  29. +12 −0 thirdparty/commonjs-tests/modules/1.0/method/a.js
  30. +8 −0 thirdparty/commonjs-tests/modules/1.0/method/program.js
  31. +15 −0 thirdparty/commonjs-tests/modules/1.0/method/test.js
  32. +8 −0 thirdparty/commonjs-tests/modules/1.0/missing/program.js
  33. +15 −0 thirdparty/commonjs-tests/modules/1.0/missing/test.js
  34. +1 −0 thirdparty/commonjs-tests/modules/1.0/monkeys/a.js
  35. +4 −0 thirdparty/commonjs-tests/modules/1.0/monkeys/program.js
  36. +15 −0 thirdparty/commonjs-tests/modules/1.0/monkeys/test.js
  37. +3 −0 thirdparty/commonjs-tests/modules/1.0/nested/a/b/c/d.js
  38. +3 −0 thirdparty/commonjs-tests/modules/1.0/nested/program.js
  39. +15 −0 thirdparty/commonjs-tests/modules/1.0/nested/test.js
  40. +5 −0 thirdparty/commonjs-tests/modules/1.0/relative/program.js
  41. +1 −0 thirdparty/commonjs-tests/modules/1.0/relative/submodule/a.js
  42. +2 −0 thirdparty/commonjs-tests/modules/1.0/relative/submodule/b.js
  43. +15 −0 thirdparty/commonjs-tests/modules/1.0/relative/test.js
  44. +1 −0 thirdparty/commonjs-tests/modules/1.0/transitive/a.js
  45. +1 −0 thirdparty/commonjs-tests/modules/1.0/transitive/b.js
  46. +3 −0 thirdparty/commonjs-tests/modules/1.0/transitive/c.js
  47. +3 −0 thirdparty/commonjs-tests/modules/1.0/transitive/program.js
  48. +15 −0 thirdparty/commonjs-tests/modules/1.0/transitive/test.js
View
96 LICENSE
@@ -187,9 +187,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.
- Copyright 2011 Adobe
- Copyright 2011 IBM Corporation
- Copyright 2011 RIM
+ Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -203,3 +201,95 @@
See the License for the specific language governing permissions and
limitations under the License.
+==============================================================
+This product also include the following software:
+==============================================================
+
+--------------------------------------------------------------
+jasmine from GitHub
+
+ https://github.com/pivotal/jasmine
+
+MIT-style license
+
+license available from:
+
+ https://github.com/pivotal/jasmine/blob/master/MIT.LICENSE
+
+-----------------------------
+
+Copyright (c) 2008-2011 Pivotal Labs
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+
+--------------------------------------------------------------
+commonjs tests from the commonjs organization at GitHub
+
+ https://github.com/commonjs/commonjs
+
+MIT-style license
+
+license available from:
+
+ https://github.com/commonjs/commonjs/blob/master/docs/license.html.markdown
+
+contributor list available from:
+
+ https://github.com/commonjs/commonjs/blob/master/docs/contributors.html.markdown
+
+-----------------------------
+
+Copyright 2009 Kevin Dangoor
+Copyright 2009 Ihab Awad
+Copyright 2009 Ash Berlin
+Copyright 2009 Aristid Breitkreuz
+Copyright 2009 Kevin Dangoor
+Copyright 2009 Daniel Friesen
+Copyright 2009 Wes Garland
+Copyright 2009 Kris Kowal
+Copyright 2009 Dean Landolt
+Copyright 2009 Peter Michaux
+Copyright 2009 George Moschovitis
+Copyright 2009 Michael O'Brien
+Copyright 2009 Tom Robinson
+Copyright 2009 Hannes Wallnoefer
+Copyright 2009 Mike Wilson
+Copyright 2009 Ondrej Zara
+Copyright 2009 Chris Zumbrunn
+Copyright 2009 Kris Zyp
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
View
5 NOTICE
@@ -0,0 +1,5 @@
+Apache Cordova weinre
+Copyright 2012 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
View
1 test/commonjs/.gitignore
@@ -0,0 +1 @@
+out
View
11 test/commonjs/README.txt
@@ -0,0 +1,11 @@
+This directory contains tests for the CommonJS functionality in Cordova.
+
+The tests come from the GitHub project https://github.com/commonjs/commonjs
+
+To run the tests, first you need to build them.
+
+Open a shell, cd into this directory, and run `python build-tests.py`.
+
+This will generate a set of HTML files which will run the tests within
+a browser. More instructions on how to run the tests are printed
+after the tests are built.
View
196 test/commonjs/build-tests.py
@@ -0,0 +1,196 @@
+#!/usr/bin/env python
+
+# ---
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# ---
+
+import os
+import re
+import sys
+import shutil
+import datetime
+import subprocess
+
+PROGRAM = sys.argv[0]
+
+#-------------------------------------------------------------------------------
+#
+#-------------------------------------------------------------------------------
+def main():
+
+ # all work done in directory of this program
+ baseDir = os.path.dirname(PROGRAM)
+ os.chdir(baseDir)
+
+ testsDir = os.path.abspath("../../thirdparty/commonjs-tests")
+ outDir = os.path.abspath("out")
+
+ # validate testsDir
+ if not os.path.exists(testsDir):
+ error("tests dir does not exist: %s" % testsDir)
+
+ if not os.path.isdir(testsDir):
+ error("tests dir is not a directory: %s" % testsDir)
+
+ # validate and reset outDir
+ if os.path.exists(outDir):
+ if not os.path.isdir(outDir):
+ error("out dir is not a directory: %s" % outDir)
+
+ shutil.rmtree(outDir)
+
+ os.makedirs(outDir)
+
+ tests = getTests(testsDir)
+
+ # now all work done in outDir
+ os.chdir("out")
+
+ # build the individual tests
+ iframes = []
+ for test in tests:
+ testName = test.replace('/', '-')
+ htmlFile = buildTest(os.path.join(testsDir, test), testName)
+ iframes.append("<iframe width='100%%' height='30' src='%s'></iframe>" % htmlFile)
+
+ iframesLines = "\n".join(iframes)
+
+ # build the browser launcher
+ html = fileContents("../launcher-main.template.html")
+
+ html = html.replace("@iframes@", iframesLines)
+ html = html.replace("@date@", getDate())
+
+ oFileName = "launcher-all.html"
+ oFile = file(oFileName, "w")
+ oFile.write(html)
+ oFile.close()
+
+ print
+ print "Generated browser test: %s" % os.path.abspath(oFileName)
+ print
+ print "You can run the test as a local file under Safari but not Chrome."
+ print "To test under Chrome, access the files via http://"
+
+#-------------------------------------------------------------------------------
+#
+#-------------------------------------------------------------------------------
+def buildTest(testDir, testName):
+
+ log("generating tests for %s" % (testName))
+
+ html = fileContents("../launcher-in-iframe.template.html")
+
+ # get the list of modules
+ modules = getModules(testDir)
+
+ modulesSource = []
+
+ modulesSource.append("try {")
+
+ for module in modules:
+ source = fileContents("%s.js" % os.path.join(testDir, module))
+
+ modulesSource.append("//----------------------------------------------")
+ modulesSource.append("define('%s', function(require,exports,module) {" % module)
+ modulesSource.append(source.strip())
+ modulesSource.append("});")
+ modulesSource.append("")
+
+ modulesSource.append("}")
+ modulesSource.append("catch(e) {")
+ modulesSource.append(" console.log('exception thrown loading modules: ' + e)")
+ modulesSource.append("}")
+
+ modulesLines = "\n".join(modulesSource)
+
+ html = html.replace("@modules@", modulesLines)
+ html = html.replace("@title@", testName)
+ html = html.replace("@date@", getDate())
+
+ # build HTML launcher for iframe
+ oFileName = "%s.html" % testName
+ oFile = file(oFileName, "w")
+ oFile.write(html)
+ oFile.close()
+
+ return oFileName
+
+#-------------------------------------------------------------------------------
+#
+#-------------------------------------------------------------------------------
+def getModules(testDir):
+ modules = []
+ for root, dirs, files in os.walk(testDir):
+ for file in files:
+ if not file.endswith(".js"): continue
+
+ moduleSource = os.path.relpath(os.path.join(root, file), testDir)
+ moduleName = os.path.splitext(moduleSource)[0]
+ modules.append(moduleName)
+
+ return modules
+
+#-------------------------------------------------------------------------------
+#
+#-------------------------------------------------------------------------------
+def getTests(testDir):
+ tests = []
+ for root, dirs, files in os.walk(testDir):
+ if "program.js" in files:
+ tests.append(os.path.relpath(root, testDir))
+
+ return tests
+
+#-------------------------------------------------------------------------------
+#
+#-------------------------------------------------------------------------------
+def run(cmdArgs):
+ result = subprocess.Popen(cmdArgs, stdout=subprocess.PIPE).communicate()[0]
+ if not re.match(r"\s*", result):
+ print result
+
+#-------------------------------------------------------------------------------
+#
+#-------------------------------------------------------------------------------
+def fileContents(iFileName):
+ iFile = file(iFileName)
+ contents = iFile.read()
+ iFile.close()
+
+ return contents
+
+def getDate():
+ return datetime.datetime.today().isoformat(" ")
+#-------------------------------------------------------------------------------
+#
+#-------------------------------------------------------------------------------
+def log(message):
+ print "%s: %s" % (PROGRAM, message)
+
+#-------------------------------------------------------------------------------
+#
+#-------------------------------------------------------------------------------
+def error(message):
+ log(message)
+ exit(1)
+
+#-------------------------------------------------------------------------------
+#
+#-------------------------------------------------------------------------------
+main()
View
73 test/commonjs/launcher-in-iframe.template.html
@@ -0,0 +1,73 @@
+<!doctype html>
+
+<!--
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+-->
+
+<html>
+<head>
+<title>@title@</title>
+<script src='../../../lib/require.js'></script>
+<script>
+@modules@
+
+//----------------------------------------------------------------------------
+var outputPre
+
+window.addEventListener("load", onLoad, false)
+
+//----------------------------------------------------------------------------
+function onLoad() {
+ outputPre = document.getElementById("output")
+
+ if (window.parent !== window) {
+ window.parent.testsStarting("@title@")
+ }
+
+ try {
+ require("program")
+ }
+ catch (e) {
+ print ("FAIL exception thrown: " + e)
+ }
+}
+
+//----------------------------------------------------------------------------
+function print(message, status) {
+
+ var className
+
+ if (/^PASS/.exec(message)) className = "pass"
+ else if (/^FAIL/.exec(message)) className = "fail"
+ else className = "info"
+
+ var line = "<div class='" + className + "'>" + message + "</div>"
+ outputPre.innerHTML += line
+
+ if (window.parent !== window) {
+ window.parent.oneTestComplete(className, message)
+ }
+
+}
+</script>
+</head>
+<body>
+<p>Tests generated on @date@
+<pre id="output"></pre>
+</body>
+</html>
View
74 test/commonjs/launcher-main.template.html
@@ -0,0 +1,74 @@
+<!doctype html>
+
+<!--
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+-->
+
+<html>
+<head>
+<link href="../test.css" rel="stylesheet" type="text/css">
+<script>
+var outputDiv
+var queue = []
+
+window.addEventListener("load", onLoad, false)
+
+//----------------------------------------------------------------------------
+function onLoad() {
+ outputDiv = document.getElementById("output")
+
+ if (queue.length > 0) {
+ outputDiv.innerHTML += queue.join("\n")
+ queue = []
+ }
+
+}
+
+//----------------------------------------------------------------------------
+function testsStarting(url) {
+ output = "<div class='test'>" + url + "</div>"
+
+ if (!outputDiv) {
+ queue.push(output)
+ }
+ else {
+ outputDiv.innerHTML += output
+ }
+}
+
+//----------------------------------------------------------------------------
+function oneTestComplete(status, message) {
+ output = "<div class='" + status + "'>" + message + "</div>"
+
+ if (!outputDiv) {
+ queue.push(output)
+ }
+ else {
+ outputDiv.innerHTML += output
+ }
+}
+</script>
+</head>
+<body>
+<p>Tests generated on @date@
+<div id="output"></div>
+<div style="display:none" id="iframes">
+@iframes@
+</div>
+</body>
+</html>
View
43 test/commonjs/test.css
@@ -0,0 +1,43 @@
+/*
+# ---
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# ---
+*/
+
+.pass, .fail, .info {
+ font-family: monospace;
+ margin-left: 1em;
+}
+
+.pass {
+ background-color: #DFD;
+}
+
+.fail {
+ background-color: #F88;
+}
+
+.info {
+ background-color: #DDF;
+}
+
+.test {
+ margin-top: 1em;
+ font-weight: bold;
+ font-size: 120%;
+}
View
9 thirdparty/commonjs-tests/README.txt
@@ -0,0 +1,9 @@
+The test cases contained in this directory were obtained from the
+commonjs project at GitHub:
+
+ https://github.com/commonjs/commonjs
+
+Specifically, the directories in the 'tests' subdirectory.
+
+See the file test/commonjs/README.txt off the root directory of this
+project for more information.
View
1 thirdparty/commonjs-tests/modules/1.0/absolute/b.js
@@ -0,0 +1 @@
+exports.foo = function() {};
View
5 thirdparty/commonjs-tests/modules/1.0/absolute/program.js
@@ -0,0 +1,5 @@
+var test = require('test');
+var a = require('submodule/a');
+var b = require('b');
+test.assert(a.foo().foo === b.foo, 'require works with absolute identifiers');
+test.print('DONE', 'info');
View
3 thirdparty/commonjs-tests/modules/1.0/absolute/submodule/a.js
@@ -0,0 +1,3 @@
+exports.foo = function () {
+ return require('b');
+};
View
15 thirdparty/commonjs-tests/modules/1.0/absolute/test.js
@@ -0,0 +1,15 @@
+
+exports.print = typeof print !== "undefined" ? print : function () {
+ var system = require("system");
+ var stdio = system.stdio;
+ stdio.print.apply(stdio, arguments);
+};
+
+exports.assert = function (guard, message) {
+ if (guard) {
+ exports.print('PASS ' + message, 'pass');
+ } else {
+ exports.print('FAIL ' + message, 'fail');
+ }
+};
+
View
4 thirdparty/commonjs-tests/modules/1.0/cyclic/a.js
@@ -0,0 +1,4 @@
+exports.a = function () {
+ return b;
+};
+var b = require('b');
View
4 thirdparty/commonjs-tests/modules/1.0/cyclic/b.js
@@ -0,0 +1,4 @@
+var a = require('a');
+exports.b = function () {
+ return a;
+};
View
10 thirdparty/commonjs-tests/modules/1.0/cyclic/program.js
@@ -0,0 +1,10 @@
+var test = require('test');
+var a = require('a');
+var b = require('b');
+
+test.assert(a.a, 'a exists');
+test.assert(b.b, 'b exists')
+test.assert(a.a().b === b.b, 'a gets b');
+test.assert(b.b().a === a.a, 'b gets a');
+
+test.print('DONE', 'info');
View
15 thirdparty/commonjs-tests/modules/1.0/cyclic/test.js
@@ -0,0 +1,15 @@
+
+exports.print = typeof print !== "undefined" ? print : function () {
+ var system = require("system");
+ var stdio = system.stdio;
+ stdio.print.apply(stdio, arguments);
+};
+
+exports.assert = function (guard, message) {
+ if (guard) {
+ exports.print('PASS ' + message, 'pass');
+ } else {
+ exports.print('FAIL ' + message, 'fail');
+ }
+};
+
View
3 thirdparty/commonjs-tests/modules/1.0/determinism/program.js
@@ -0,0 +1,3 @@
+var test = require('test');
+require('submodule/a');
+test.print('DONE', 'info');
View
9 thirdparty/commonjs-tests/modules/1.0/determinism/submodule/a.js
@@ -0,0 +1,9 @@
+var test = require('test');
+var pass = false;
+var test = require('test');
+try {
+ require('a');
+} catch (exception) {
+ pass = true;
+}
+test.assert(pass, 'require does not fall back to relative modules when absolutes are not available.')
View
2 thirdparty/commonjs-tests/modules/1.0/determinism/submodule/b.js
@@ -0,0 +1,2 @@
+
+
View
15 thirdparty/commonjs-tests/modules/1.0/determinism/test.js
@@ -0,0 +1,15 @@
+
+exports.print = typeof print !== "undefined" ? print : function () {
+ var system = require("system");
+ var stdio = system.stdio;
+ stdio.print.apply(stdio, arguments);
+};
+
+exports.assert = function (guard, message) {
+ if (guard) {
+ exports.print('PASS ' + message, 'pass');
+ } else {
+ exports.print('FAIL ' + message, 'fail');
+ }
+};
+
View
3 thirdparty/commonjs-tests/modules/1.0/exactExports/a.js
@@ -0,0 +1,3 @@
+exports.program = function () {
+ return require('program');
+};
View
4 thirdparty/commonjs-tests/modules/1.0/exactExports/program.js
@@ -0,0 +1,4 @@
+var test = require('test');
+var a = require('a');
+test.assert(a.program() === exports, 'exact exports');
+test.print('DONE', 'info');
View
15 thirdparty/commonjs-tests/modules/1.0/exactExports/test.js
@@ -0,0 +1,15 @@
+
+exports.print = typeof print !== "undefined" ? print : function () {
+ var system = require("system");
+ var stdio = system.stdio;
+ stdio.print.apply(stdio, arguments);
+};
+
+exports.assert = function (guard, message) {
+ if (guard) {
+ exports.print('PASS ' + message, 'pass');
+ } else {
+ exports.print('FAIL ' + message, 'fail');
+ }
+};
+
View
0 thirdparty/commonjs-tests/modules/1.0/hasOwnProperty/hasOwnProperty.js
No changes.
View
4 thirdparty/commonjs-tests/modules/1.0/hasOwnProperty/program.js
@@ -0,0 +1,4 @@
+var hasOwnProperty = require('hasOwnProperty');
+var toString = require('toString');
+var test = require('test');
+test.print('DONE', 'info');
View
15 thirdparty/commonjs-tests/modules/1.0/hasOwnProperty/test.js
@@ -0,0 +1,15 @@
+
+exports.print = typeof print !== "undefined" ? print : function () {
+ var system = require("system");
+ var stdio = system.stdio;
+ stdio.print.apply(stdio, arguments);
+};
+
+exports.assert = function (guard, message) {
+ if (guard) {
+ exports.print('PASS ' + message, 'pass');
+ } else {
+ exports.print('FAIL ' + message, 'fail');
+ }
+};
+
View
0 thirdparty/commonjs-tests/modules/1.0/hasOwnProperty/toString.js
No changes.
View
12 thirdparty/commonjs-tests/modules/1.0/method/a.js
@@ -0,0 +1,12 @@
+exports.foo = function () {
+ return this;
+};
+exports.set = function (x) {
+ this.x = x;
+};
+exports.get = function () {
+ return this.x;
+};
+exports.getClosed = function () {
+ return exports.x;
+};
View
8 thirdparty/commonjs-tests/modules/1.0/method/program.js
@@ -0,0 +1,8 @@
+var test = require('test');
+var a = require('a');
+var foo = a.foo;
+test.assert(a.foo() == a, 'calling a module member');
+test.assert(foo() == (function (){return this})(), 'members not implicitly bound');
+a.set(10);
+test.assert(a.get() == 10, 'get and set')
+test.print('DONE', 'info');
View
15 thirdparty/commonjs-tests/modules/1.0/method/test.js
@@ -0,0 +1,15 @@
+
+exports.print = typeof print !== "undefined" ? print : function () {
+ var system = require("system");
+ var stdio = system.stdio;
+ stdio.print.apply(stdio, arguments);
+};
+
+exports.assert = function (guard, message) {
+ if (guard) {
+ exports.print('PASS ' + message, 'pass');
+ } else {
+ exports.print('FAIL ' + message, 'fail');
+ }
+};
+
View
8 thirdparty/commonjs-tests/modules/1.0/missing/program.js
@@ -0,0 +1,8 @@
+var test = require('test');
+try {
+ require('bogus');
+ test.print('FAIL require throws error when module missing', 'fail');
+} catch (exception) {
+ test.print('PASS require throws error when module missing', 'pass');
+}
+test.print('DONE', 'info');
View
15 thirdparty/commonjs-tests/modules/1.0/missing/test.js
@@ -0,0 +1,15 @@
+
+exports.print = typeof print !== "undefined" ? print : function () {
+ var system = require("system");
+ var stdio = system.stdio;
+ stdio.print.apply(stdio, arguments);
+};
+
+exports.assert = function (guard, message) {
+ if (guard) {
+ exports.print('PASS ' + message, 'pass');
+ } else {
+ exports.print('FAIL ' + message, 'fail');
+ }
+};
+
View
1 thirdparty/commonjs-tests/modules/1.0/monkeys/a.js
@@ -0,0 +1 @@
+require('program').monkey = 10;
View
4 thirdparty/commonjs-tests/modules/1.0/monkeys/program.js
@@ -0,0 +1,4 @@
+var a = require('a');
+var test = require('test');
+test.assert(exports.monkey == 10, 'monkeys permitted');
+test.print('DONE', 'info');
View
15 thirdparty/commonjs-tests/modules/1.0/monkeys/test.js
@@ -0,0 +1,15 @@
+
+exports.print = typeof print !== "undefined" ? print : function () {
+ var system = require("system");
+ var stdio = system.stdio;
+ stdio.print.apply(stdio, arguments);
+};
+
+exports.assert = function (guard, message) {
+ if (guard) {
+ exports.print('PASS ' + message, 'pass');
+ } else {
+ exports.print('FAIL ' + message, 'fail');
+ }
+};
+
View
3 thirdparty/commonjs-tests/modules/1.0/nested/a/b/c/d.js
@@ -0,0 +1,3 @@
+exports.foo = function () {
+ return 1;
+};
View
3 thirdparty/commonjs-tests/modules/1.0/nested/program.js
@@ -0,0 +1,3 @@
+var test = require('test');
+test.assert(require('a/b/c/d').foo() == 1, 'nested module identifier');
+test.print('DONE', 'info');
View
15 thirdparty/commonjs-tests/modules/1.0/nested/test.js
@@ -0,0 +1,15 @@
+
+exports.print = typeof print !== "undefined" ? print : function () {
+ var system = require("system");
+ var stdio = system.stdio;
+ stdio.print.apply(stdio, arguments);
+};
+
+exports.assert = function (guard, message) {
+ if (guard) {
+ exports.print('PASS ' + message, 'pass');
+ } else {
+ exports.print('FAIL ' + message, 'fail');
+ }
+};
+
View
5 thirdparty/commonjs-tests/modules/1.0/relative/program.js
@@ -0,0 +1,5 @@
+var test = require('test');
+var a = require('submodule/a');
+var b = require('submodule/b');
+test.assert(a.foo == b.foo, 'a and b share foo through a relative require');
+test.print('DONE', 'info');
View
1 thirdparty/commonjs-tests/modules/1.0/relative/submodule/a.js
@@ -0,0 +1 @@
+exports.foo = require('./b').foo;
View
2 thirdparty/commonjs-tests/modules/1.0/relative/submodule/b.js
@@ -0,0 +1,2 @@
+exports.foo = function () {
+};
View
15 thirdparty/commonjs-tests/modules/1.0/relative/test.js
@@ -0,0 +1,15 @@
+
+exports.print = typeof print !== "undefined" ? print : function () {
+ var system = require("system");
+ var stdio = system.stdio;
+ stdio.print.apply(stdio, arguments);
+};
+
+exports.assert = function (guard, message) {
+ if (guard) {
+ exports.print('PASS ' + message, 'pass');
+ } else {
+ exports.print('FAIL ' + message, 'fail');
+ }
+};
+
View
1 thirdparty/commonjs-tests/modules/1.0/transitive/a.js
@@ -0,0 +1 @@
+exports.foo = require('b').foo;
View
1 thirdparty/commonjs-tests/modules/1.0/transitive/b.js
@@ -0,0 +1 @@
+exports.foo = require('c').foo;
View
3 thirdparty/commonjs-tests/modules/1.0/transitive/c.js
@@ -0,0 +1,3 @@
+exports.foo = function () {
+ return 1;
+};
View
3 thirdparty/commonjs-tests/modules/1.0/transitive/program.js
@@ -0,0 +1,3 @@
+var test = require('test');
+test.assert(require('a').foo() == 1, 'transitive');
+test.print('DONE', 'info');
View
15 thirdparty/commonjs-tests/modules/1.0/transitive/test.js
@@ -0,0 +1,15 @@
+
+exports.print = typeof print !== "undefined" ? print : function () {
+ var system = require("system");
+ var stdio = system.stdio;
+ stdio.print.apply(stdio, arguments);
+};
+
+exports.assert = function (guard, message) {
+ if (guard) {
+ exports.print('PASS ' + message, 'pass');
+ } else {
+ exports.print('FAIL ' + message, 'fail');
+ }
+};
+

0 comments on commit d734199

Please sign in to comment.