Permalink
Browse files

super-simple Harmony test harness

  • Loading branch information...
1 parent 4a68e11 commit 5ff324ef068299337cca5f05c15d971c66141f6f @dherman dherman committed Jan 24, 2011
Showing with 343 additions and 4 deletions.
  1. +17 −0 harmony-tests/README.txt
  2. +1 −0 harmony-tests/fail-execute/eval-export.js
  3. +1 −0 harmony-tests/fail-execute/eval-resolve1.js
  4. +1 −0 harmony-tests/fail-execute/eval-resolve2.js
  5. +8 −0 harmony-tests/fail-execute/module-uninit-read.js
  6. +3 −0 harmony-tests/fail-resolve/export-cycle1.js
  7. +7 −0 harmony-tests/fail-resolve/export-cycle2.js
  8. +7 −0 harmony-tests/fail-resolve/export-cycle3.js
  9. +15 −0 harmony-tests/fail-resolve/export-cycle4.js
  10. +1 −0 harmony-tests/fail-resolve/export-unbound-var.js
  11. +2 −0 harmony-tests/fail-resolve/import-eval1.js
  12. +2 −0 harmony-tests/fail-resolve/import-eval2.js
  13. +5 −0 harmony-tests/fail-resolve/module-rebind-assignment1.js
  14. +1 −0 harmony-tests/fail-resolve/unbound-read.js
  15. +1 −0 harmony-tests/fail-resolve/unbound-write.js
  16. +88 −0 harmony-tests/run.sh
  17. +5 −0 harmony-tests/succeed/eval-import1.js
  18. +5 −0 harmony-tests/succeed/eval-import2.js
  19. +9 −0 harmony-tests/succeed/eval-module1.js
  20. +4 −0 harmony-tests/succeed/eval-module2.js
  21. +5 −0 harmony-tests/succeed/eval-resolve1.js
  22. +3 −0 harmony-tests/succeed/eval-resolve2.js
  23. +12 −0 harmony-tests/succeed/export-bound-var.js
  24. +5 −0 harmony-tests/succeed/export-var.js
  25. +3 −0 harmony-tests/succeed/global-this.js
  26. +8 −0 harmony-tests/succeed/incomplete-module1.js
  27. +9 −0 harmony-tests/succeed/incomplete-module2.js
  28. +8 −0 harmony-tests/succeed/module-rebind1.js
  29. +10 −0 harmony-tests/succeed/module-rebind2.js
  30. +9 −0 harmony-tests/succeed/module-rebind3.js
  31. +8 −0 harmony-tests/succeed/module-this.js
  32. +18 −0 harmony-tests/succeed/re-export1.js
  33. +19 −0 harmony-tests/succeed/re-export2.js
  34. +7 −0 harmony-tests/succeed/uninitialized-module1.js
  35. +9 −0 harmony-tests/succeed/uninitialized-module2.js
  36. +14 −0 harmony-tests/succeed/uninitialized-module3.js
  37. +13 −4 njs
@@ -0,0 +1,17 @@
+This directory contains tests for experimental Harmony features.
+
+NOTE: Please don't fork this test suite without talking to me first!
+
+I purposefully created almost no test harness whatsoever -- just a stupid shell
+script that uses directory structure to figure out expected results. This is
+because:
+
+a) I don't want to write Yet Another Test Harness; and
+
+b) I'd like these tests to get eaten up by some other test suite eventually.
+
+So *please* talk to me first before forking; it's probably much better to
+adapt these tests directly.
+
+Dave Herman
+dherman@mozilla.com
@@ -0,0 +1 @@
+eval("var x = 42; export x;");
@@ -0,0 +1 @@
+eval("xyzzx")
@@ -0,0 +1 @@
+(function(x) { return eval("xyzzx") })("foo");
@@ -0,0 +1,8 @@
+module A {
+ import B.foo;
+ var x = foo;
+}
+
+module B {
+ export var foo = 12;
+}
@@ -0,0 +1,3 @@
+module M {
+ export M.foo;
+}
@@ -0,0 +1,7 @@
+module M {
+ export N.foo;
+}
+
+module N {
+ export M.foo;
+}
@@ -0,0 +1,7 @@
+module M {
+ export { foo: N.bar };
+}
+
+module N {
+ export { bar: M.foo };
+}
@@ -0,0 +1,15 @@
+module M {
+ export { foo: N.bar };
+}
+
+module N {
+ export { bar: O.baz };
+}
+
+module O {
+ export { baz: P.buz };
+}
+
+module P {
+ export { buz: M.foo };
+}
@@ -0,0 +1 @@
+module M { export x }
@@ -0,0 +1,2 @@
+eval("module M { export var foo = 42 }");
+import M.foo;
@@ -0,0 +1,2 @@
+eval("module M { export var foo = 42 }");
+var x = M.foo;
@@ -0,0 +1,5 @@
+module P { export module A { export var a = 12 } }
+
+module B = P.A
+
+B.a = 13;
@@ -0,0 +1 @@
+var foo = someUnboundVariable;
@@ -0,0 +1 @@
+someUnboundVariable = 12;
View
@@ -0,0 +1,88 @@
+#!/bin/sh
+
+HERE=`dirname $0`
+ROOT=$HERE/..
+
+cd $ROOT
+
+FAILURES=
+
+################################################################################
+
+echo Running harmony-tests/succeed...
+
+SUCCEED_PASS=0
+SUCCEED_FAIL=0
+
+for f in harmony-tests/succeed/*.js ; do
+ ./njs -H -f $f >/dev/null 2>&1
+ if [ $? -eq 0 ]; then
+ SUCCEED_PASS=$(($SUCCEED_PASS + 1))
+ else
+ SUCCEED_FAIL=$(($SUCCEED_FAIL + 1))
+ FAILURES="$FAILURES $f"
+ fi
+done
+
+echo "==> $SUCCEED_PASS passed, $SUCCEED_FAIL failed."
+
+################################################################################
+
+echo
+echo Running harmony-tests/fail-resolve...
+
+FAIL_RESOLVE_PASS=0
+FAIL_RESOLVE_FAIL=0
+
+for f in harmony-tests/fail-resolve/*.js ; do
+ ./njs -H -E "Narcissus.resolver.resolve(Narcissus.parser.parse(snarf('$f')),Narcissus.interpreter.globalStaticEnv)" >/dev/null 2>&1
+ if [ $? -eq 0 ]; then
+ FAIL_RESOLVE_FAIL=$((FAIL_RESOLVE_FAIL + 1))
+ FAILURES="$FAILURES $f"
+ else
+ FAIL_RESOLVE_PASS=$((FAIL_RESOLVE_PASS + 1))
+ fi
+done
+
+echo "==> $FAIL_RESOLVE_PASS passed, $FAIL_RESOLVE_FAIL failed."
+
+################################################################################
+
+echo
+echo Running harmony-tests/fail-execute...
+
+FAIL_EXECUTE_PASS=0
+FAIL_EXECUTE_FAIL=0
+
+for f in harmony-tests/fail-execute ; do
+ ./njs -H -f $f >/dev/null 2>&1
+ if [ $? -eq 0 ]; then
+ FAIL_EXECUTE_FAIL=$(($FAIL_EXECUTE_FAIL + 1))
+ FAILURES="$FAILURES $f"
+ else
+ FAIL_EXECUTE_PASS=$(($FAIL_EXECUTE_PASS + 1))
+ fi
+done
+
+echo "==> $FAIL_EXECUTE_PASS passed, $FAIL_EXECUTE_FAIL failed."
+
+################################################################################
+
+echo
+echo TOTAL:
+
+TOTAL_PASS=$(($SUCCEED_PASS + $FAIL_EXECUTE_PASS + $FAIL_RESOLVE_PASS))
+TOTAL_FAIL=$(($SUCCEED_FAIL + $FAIL_EXECUTE_FAIL + $FAIL_RESOLVE_FAIL))
+
+echo "==> $TOTAL_PASS passed, $TOTAL_FAIL failed."
+
+if [ $TOTAL_FAIL -gt 0 ]; then
+ echo
+ echo Failures:
+ for f in $FAILURES ; do
+ echo " $f"
+ done
+ exit 1
+else
+ exit 0
+fi
@@ -0,0 +1,5 @@
+module M {
+ export var foo = 42;
+}
+
+assertEq(eval("import M.foo; foo"), 42);
@@ -0,0 +1,5 @@
+module M {
+ export var foo = "foo";
+}
+
+assertEq(eval("module M { export var bar = 'bar' } import M.bar; bar"), "bar");
@@ -0,0 +1,9 @@
+module M {
+ export var foo = "foo";
+}
+
+var foo = M.foo;
+var bar = eval("module M { export var bar = 'bar'; } M.bar");
+
+assertEq(foo, "foo");
+assertEq(bar, "bar");
@@ -0,0 +1,4 @@
+var M1 = eval("module M { } M");
+var M2 = eval("module M { } M");
+
+assertEq(M1 === M2, false);
@@ -0,0 +1,5 @@
+var foo = 42;
+
+var myfoo = eval("foo");
+
+assertEq(foo, myfoo);
@@ -0,0 +1,3 @@
+var foo = (function(x) { return eval("x") })("foo");
+
+assertEq(foo, "foo");
@@ -0,0 +1,12 @@
+module M {
+ import N.x;
+ export x;
+}
+
+module N {
+ var x = 42;
+ export x;
+}
+
+assertEq(M.x, 42);
+assertEq(N.x, 42);
@@ -0,0 +1,5 @@
+module M {
+ export var foo = 42;
+}
+
+assertEq(M.foo, 42);
@@ -0,0 +1,3 @@
+var global = this;
+
+assertEq("global" in global, true);
@@ -0,0 +1,8 @@
+var saved;
+
+module M {
+ saved = M;
+ export var foo = 42;
+}
+
+assertEq("foo" in saved, true);
@@ -0,0 +1,9 @@
+var saved;
+
+module M {
+ export var foo = 42;
+ var tmp = M;
+ saved = tmp.foo;
+}
+
+assertEq(saved, 42);
@@ -0,0 +1,8 @@
+module P {
+ module A { export var a = 12 }
+ export A
+}
+
+module B = P.A
+
+assertEq(B.a, 12);
@@ -0,0 +1,10 @@
+module P {
+ module A { export var a = 12 }
+ export A
+}
+
+module B = P.A, C = P.A, D = P.A;
+
+assertEq(B.a, 12);
+assertEq(C.a, 12);
+assertEq(D.a, 12);
@@ -0,0 +1,9 @@
+module M {
+ export var foo = 42;
+ export module N {
+ module M;
+ export var foo = M.foo
+ }
+}
+
+assertEq(M.foo, M.N.foo);
@@ -0,0 +1,8 @@
+var saved;
+
+module M {
+ saved = this;
+ export var foo = 42;
+}
+
+assertEq("foo" in saved, true);
@@ -0,0 +1,18 @@
+module M {
+ export module N {
+ export var foo = 42;
+ export var bar = "hello world";
+ }
+}
+
+module Q {
+ export {
+ foo: M.N.bar,
+ bar: M.N.foo
+ }
+}
+
+assertEq(Q.foo, "hello world");
+assertEq(Q.bar, 42);
+assertEq(Q.foo, M.N.bar);
+assertEq(Q.bar, M.N.foo);
@@ -0,0 +1,19 @@
+module M {
+ export module N {
+ export var foo = 42;
+ export var bar = "hello world";
+ }
+}
+
+module Q {
+ module MN = M.N;
+ export {
+ foo: MN.bar,
+ bar: MN.foo
+ }
+}
+
+assertEq(Q.foo, "hello world");
+assertEq(Q.bar, 42);
+assertEq(Q.foo, M.N.bar);
+assertEq(Q.bar, M.N.foo);
@@ -0,0 +1,7 @@
+var saved = M;
+
+module M {
+ export var foo = 42;
+}
+
+assertEq(saved.foo, 42);
@@ -0,0 +1,9 @@
+var saved = M.N;
+
+module M {
+ export module N {
+ export var foo = 42;
+ }
+}
+
+assertEq(saved.foo, 42);
@@ -0,0 +1,14 @@
+var saved;
+
+module M {
+ module N {
+ saved = M.O.P;
+ }
+ export module O {
+ export module P {
+ export var foo = 42;
+ }
+ }
+}
+
+assertEq(saved.foo, 42);
Oops, something went wrong.

0 comments on commit 5ff324e

Please sign in to comment.