[pypy-svn] r39155 - in pypy/dist/pypy/lang/js: . test/ecma

santagada at codespeak.net santagada at codespeak.net
Sun Feb 18 14:57:32 CET 2007


Author: santagada
Date: Sun Feb 18 14:57:31 2007
New Revision: 39155

Added:
   pypy/dist/pypy/lang/js/conftest.py
   pypy/dist/pypy/lang/js/test/ecma/conftest.py
Modified:
   pypy/dist/pypy/lang/js/jsobj.py
   pypy/dist/pypy/lang/js/test/ecma/shell.js
Log:
new mozilla test suite integration with py.test

Added: pypy/dist/pypy/lang/js/conftest.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/lang/js/conftest.py	Sun Feb 18 14:57:31 2007
@@ -0,0 +1,9 @@
+import py
+
+Option = py.test.config.Option
+option = py.test.config.addoptions("ecma compatibility tests",
+        Option('', '--ecma',
+               action="store_true", dest="ecma", default=False,
+               help="run js interpreter ecma tests"
+        ),
+)

Modified: pypy/dist/pypy/lang/js/jsobj.py
==============================================================================
--- pypy/dist/pypy/lang/js/jsobj.py	(original)
+++ pypy/dist/pypy/lang/js/jsobj.py	Sun Feb 18 14:57:31 2007
@@ -286,7 +286,6 @@
         self.array = []
         self.set_builtin_call(arraycallbi)
     
-    
     def Put(self, P, V):
         try:
             x = int(P)

Added: pypy/dist/pypy/lang/js/test/ecma/conftest.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/lang/js/test/ecma/conftest.py	Sun Feb 18 14:57:31 2007
@@ -0,0 +1,66 @@
+import py
+from pypy.lang.js.interpreter import *
+from pypy.lang.js.jsobj import W_Array
+from pypy.lang.js.conftest import option
+
+rootdir = py.magic.autopath().dirpath()
+exclusionlist = ['shell.js', 'browser.js']
+
+class JSDirectory(py.test.collect.Directory):
+
+    def filefilter(self, path): 
+        if path.check(file=1):
+            return (path.basename not in exclusionlist)  and (path.ext == '.js')
+
+    def join(self, name):
+        if not name.endswith('.js'):
+            return super(Directory, self).join(name)
+        p = self.fspath.join(name)
+        if p.check(file=1):
+            return JSTestFile(p, parent=self)
+
+
+
+class JSTestFile(py.test.collect.Collector):
+    def __init__(self, filepath, parent=None):
+        super(JSTestFile, self).__init__(filepath, parent)
+        self.name = filepath.purebasename + " JSFILE"
+        self.filepath = filepath
+    
+    def run(self):
+        #actually run the file :)
+        t = load_source(self.filepath.read())
+        try:
+            t.execute(interp.global_context)
+        except:
+            py.test.fail("Could not load js file")
+        testcases = interp.global_context.resolve_identifier('testcases')
+        values = testcases.GetValue().array
+        testcases.PutValue(W_Array(), interp.global_context)
+        return values
+
+    def join(self, name):
+        return JSTestItem(name, parent = self)
+
+class JSTestItem(py.__.test.item.Item):        
+    def __init__(self, name, parent=None):
+        #super(JSTestItem, self).__init__(filepath, parent)
+        self.name = name
+         
+    def run():
+        ctx = interp.global_context
+        r3 = ctx.resolve_identifier('run_test').GetValue()
+        result = r3.Call(ctx=ctx, args=[name,]).ToNumber()
+        if result == 0:
+            py.test.fail()
+        elif result == -1:
+            py.test.skip()
+
+if option.ecma:
+    global interp
+    interp = Interpreter()
+    ctx = interp.global_context
+    shellpath = rootdir/'shell.js'
+    t = load_source(shellpath.read())
+    t.execute(ctx)
+    Directory = JSDirectory
\ No newline at end of file

Modified: pypy/dist/pypy/lang/js/test/ecma/shell.js
==============================================================================
--- pypy/dist/pypy/lang/js/test/ecma/shell.js	(original)
+++ pypy/dist/pypy/lang/js/test/ecma/shell.js	Sun Feb 18 14:57:31 2007
@@ -124,23 +124,23 @@
 }
 
 function test() {
-  for ( tc=0; tc < testcases.length; tc++ ) {
-    // temporary hack to work around some unknown issue in 1.7
-    try
-    {
-    testcases[tc].passed = writeTestCaseResult(
-      testcases[tc].expect,
-      testcases[tc].actual,
-      testcases[tc].description +" = "+ testcases[tc].actual );
-    testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
-    }
-    catch(e)
-    {
-      print('test(): empty testcase for tc = ' + tc + ' ' + e);
-    }
-  }
-  stopTest();
-  return ( testcases );
+  // for ( tc=0; tc < testcases.length; tc++ ) {
+  //    // temporary hack to work around some unknown issue in 1.7
+  //    try
+  //    {
+  //    testcases[tc].passed = writeTestCaseResult(
+  //      testcases[tc].expect,
+  //      testcases[tc].actual,
+  //      testcases[tc].description +" = "+ testcases[tc].actual );
+  //    testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
+  //    }
+  //    catch(e)
+  //    {
+  //      print('test(): empty testcase for tc = ' + tc + ' ' + e);
+  //    }
+  //  }
+  //  stopTest();
+    return ( testcases );
 }
 
 /*
@@ -193,6 +193,18 @@
  * document.write.
  */
 
+function run_test(testnr) {
+     try
+     {
+     getTestCaseResult(testcases[tc].expect, testcases[tc].actual)
+     testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
+     return testcases[tc].passed? 1:0;
+     }
+     catch(e)
+     {
+        return -1
+     }
+}
 function writeTestCaseResult( expect, actual, string ) {
   var passed = getTestCaseResult( expect, actual );
   writeFormattedResult( expect, actual, string, passed );



More information about the Pypy-commit mailing list