seed r372 - in trunk: libseed tests
- From: hortont svn gnome org
- To: svn-commits-list gnome org
- Subject: seed r372 - in trunk: libseed tests
- Date: Sun, 30 Nov 2008 05:09:09 +0000 (UTC)
Author: hortont
Date: Sun Nov 30 05:09:09 2008
New Revision: 372
URL: http://svn.gnome.org/viewvc/seed?rev=372&view=rev
Log:
Tests now check return value! Added more builtin tests... removed
setTimeout completely. Look in examples/glib for a example of how to do
timeouts with GLib yourself...
Added:
trunk/tests/check-syntax.js (contents, props changed)
trunk/tests/fork.js (contents, props changed)
trunk/tests/quit.js (contents, props changed)
Modified:
trunk/libseed/seed-builtins.c
trunk/tests/run-tests.py
trunk/tests/syntax-test.js
Modified: trunk/libseed/seed-builtins.c
==============================================================================
--- trunk/libseed/seed-builtins.c (original)
+++ trunk/libseed/seed-builtins.c Sun Nov 30 05:09:09 2008
@@ -303,50 +303,6 @@
return seed_value_from_int(ctx, child, exception);
}
-static gboolean seed_timeout_function(gpointer user_data)
-{
- // Evaluate timeout script
-
- timeout_privates * priv = (timeout_privates *)user_data;
- JSEvaluateScript(priv->context, priv->script, NULL, NULL, 0, NULL);
- JSStringRelease(priv->script);
- g_slice_free1(sizeof(timeout_privates), priv);
-
- return FALSE; // remove timeout from main loop
-}
-
-static JSValueRef
-seed_set_timeout(JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef this_object,
- size_t argumentCount,
- const JSValueRef arguments[], JSValueRef * exception)
-{
- if (argumentCount != 2)
- {
- gchar *mes =
- g_strdup_printf("Seed.setTimeout expected 2 arguments, "
- "got %d", argumentCount);
- seed_make_exception(ctx, exception, "ArgumentError", mes);
- g_free(mes);
- return JSValueMakeBoolean(ctx, 0);
- }
-
- JSStringRef jsstr = JSValueToStringCopy(ctx,
- arguments[0],
- exception);
-
- guint interval = seed_value_to_uint(ctx, arguments[1], exception);
-
- timeout_privates * priv = g_slice_alloc0(sizeof(timeout_privates));
- priv->context = ctx;
- priv->script = jsstr;
-
- g_timeout_add(interval, &seed_timeout_function, priv);
-
- return JSValueMakeBoolean(ctx, 1);
-}
-
static JSValueRef
seed_closure(JSContextRef ctx,
JSObjectRef function,
@@ -458,8 +414,6 @@
seed_create_function(local_eng->context,
"closure", &seed_closure, obj);
seed_create_function(local_eng->context,
- "setTimeout", &seed_set_timeout, obj);
- seed_create_function(local_eng->context,
"closure_native", &seed_closure_native, obj);
seed_create_function(local_eng->context,
"quit", &seed_quit, obj);
Added: trunk/tests/check-syntax.js
==============================================================================
--- (empty file)
+++ trunk/tests/check-syntax.js Sun Nov 30 05:09:09 2008
@@ -0,0 +1,12 @@
+#!/usr/bin/env seed
+// Returns: 0
+// STDIN:
+// STDOUT:ONE\n\[null\]\nTWO\n\[null\]\nTHREE
+// STDERR:\n\*\* \(seed:[0-9]+\): CRITICAL \*\*: SyntaxError\. Parse error in \[null\] at line 1
+
+Seed.print("ONE");
+Seed.print(Seed.check_syntax("5+5;"));
+Seed.print("TWO");
+Seed.print(Seed.check_syntax("asdfasdf.jsdf()"));
+Seed.print("THREE");
+Seed.print(Seed.check_syntax("one[)"));
Added: trunk/tests/fork.js
==============================================================================
--- (empty file)
+++ trunk/tests/fork.js Sun Nov 30 05:09:09 2008
@@ -0,0 +1,16 @@
+#!/usr/bin/env seed
+// Returns: 0
+// STDIN:
+// STDOUT:[AB]\n[AB]
+// STDERR:
+
+var a = Seed.fork();
+
+if(a)
+{
+ Seed.print("A");
+}
+else
+{
+ Seed.print("B");
+}
Added: trunk/tests/quit.js
==============================================================================
--- (empty file)
+++ trunk/tests/quit.js Sun Nov 30 05:09:09 2008
@@ -0,0 +1,7 @@
+#!/usr/bin/env seed
+// Returns: 1
+// STDIN:
+// STDOUT:
+// STDERR:
+
+Seed.quit(1);
Modified: trunk/tests/run-tests.py
==============================================================================
--- trunk/tests/run-tests.py (original)
+++ trunk/tests/run-tests.py Sun Nov 30 05:09:09 2008
@@ -26,6 +26,7 @@
import os
import re
import sys
+import subprocess
passed = []
failed = []
@@ -34,18 +35,20 @@
if f.endswith(".js") and not f.endswith("_.js"):
rfile = open(f, "r")
test_code = rfile.readlines()
+ test_retval = int(test_code[1].replace("// Returns:","").rstrip().replace("\\n","\n"));
test_in = test_code[2].replace("// STDIN:","").rstrip().replace("\\n","\n");
test_out = "^" + test_code[3].replace("// STDOUT:","").rstrip().replace("\\n","\n") + "$";
test_err = "^" + test_code[4].replace("// STDERR:","").rstrip().replace("\\n","\n") + "$";
- (n,out,err) = os.popen3("./" + f)
+ p = subprocess.Popen("./"+f, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
+ (out,err)=(p.stdout, p.stderr)
- if(test_in != ""):
- n.write(test_in + "\004")
- n.close()
+ (run_out,run_err)=p.communicate(test_in + "\004")
+ run_out = run_out.rstrip()
+ run_err = run_err.rstrip()
- run_out = "".join(out.readlines()).rstrip()
- run_err = "".join(err.readlines()).rstrip()
+ out.close()
+ err.close()
if not re.match(test_out,run_out):
failed.append([f,test_out,run_out,0,run_err])
@@ -53,6 +56,9 @@
elif not re.match(test_err,run_err):
failed.append([f,test_err,run_err,1])
sys.stdout.write("x")
+ elif p.returncode != test_retval:
+ failed.append([f,test_retval,p.returncode,2]);
+ sys.stdout.write("x")
else:
passed.append([f,test_out,run_out])
sys.stdout.write(".")
@@ -67,12 +73,15 @@
for fail in failed:
print "-------------FAILED TEST---------------"
print "Name: %s" % fail[0]
- if fail[3]:
+ if fail[3] == 1:
print " Expected Error:\t" + fail[1]
print " Actual Error:\t" + fail[2]
- else:
+ elif fail[3] == 0:
print " Expected Output:\t" + fail[1]
print " Actual Output:\t" + fail[2]
- print " STDERR:\t\t" + fail[4]
+ print " Error Output:\t\t" + fail[4]
+ elif fail[3] == 2:
+ print " Expected Retval:\t%d" % fail[1]
+ print " Actual Retval:\t%d" % fail[2]
if len(failed):
print "---------------------------------------"
Modified: trunk/tests/syntax-test.js
==============================================================================
--- trunk/tests/syntax-test.js (original)
+++ trunk/tests/syntax-test.js Sun Nov 30 05:09:09 2008
@@ -1,18 +1,7 @@
#!/usr/bin/env seed
-// Returns: 0
+// Returns: 1
// STDIN:
// STDOUT:
// STDERR:\n\*\* \(seed:[0-9]+\): CRITICAL \*\*: SyntaxError\. Parse error in \.\/syntax-test\.js at line 6
new = 3
-
-
-#!/usr/bin/env seed
-// Returns: 0
-// STDIN:
-// STDOUT:
-// STDERR:\n\*\* \(seed:[0-9]+\): CRITICAL \*\*: SyntaxError\. Parse error in \.\/syntax-test\.js at line 6
-
-new = 3
-
-
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]