[gnome-js-common] Tests: Work on GJS test.



commit ff4c0a17f05b53bbf05237d510492b46e08ec944
Author: Tim Horton <hortont424 gmail com>
Date:   Wed May 27 10:08:36 2009 -0400

    Tests: Work on GJS test.
---
 tests/assert.js       |    2 --
 tests/everything.js   |    2 --
 tests/run-tests-gjs.c |   44 ++++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 42 insertions(+), 6 deletions(-)

diff --git a/tests/assert.js b/tests/assert.js
index 59d8e9d..266ca64 100644
--- a/tests/assert.js
+++ b/tests/assert.js
@@ -1,5 +1,3 @@
-#!/usr/bin/env seed
-
 var flag = 0;
 
 try
diff --git a/tests/everything.js b/tests/everything.js
index 1db1ced..15c17f3 100644
--- a/tests/everything.js
+++ b/tests/everything.js
@@ -1,5 +1,3 @@
-#!/usr/bin/env seed
-
 Everything = imports.gi.Everything;
 GObject = imports.gi.GObject;
 
diff --git a/tests/run-tests-gjs.c b/tests/run-tests-gjs.c
index bc916f8..7a763b3 100644
--- a/tests/run-tests-gjs.c
+++ b/tests/run-tests-gjs.c
@@ -21,17 +21,57 @@ extern gboolean failure_flag;
 		seed_make_exception(ctx, exception, "AssertionError", "Assertion failed");
 }*/
 
+static JSBool js_assert(JSContext *context,
+                        JSObject * obj,
+                        uintN argc,
+                        jsval * argv,
+                        jsval * retval)
+{
+    gboolean success;
+
+    if(!JSVAL_TO_BOOLEAN(argv[0]))
+    {
+        gjs_throw(context, "Assertion failed");
+        return JS_FALSE;
+    }
+
+    return JS_TRUE;
+}
+
 gboolean test_exec(gchar * filename)
 {
 	gchar * buffer;
+	GError *error = NULL;
+	gboolean success;
+	int code;
+	char *search_path[1];
+    search_path[0] = NULL;
+    GjsContext * context;
 	
 	if(!initialized)
 	{
-		// init gjs
+		gjs_crash_after_timeout(60*7); /* give the unit tests 7 minutes to complete */
+		gjs_init_sleep_on_crash();
+		
+		g_type_init();
 		initialized = TRUE;
 	}
 
-	// eval filename in a new context, discard context, check errors etc.
+	context = gjs_context_new_with_search_path(search_path);
+	
+	if (!JS_DefineFunction(context, JS_GetGlobalObject(context),
+                           "assert",
+                           js_assert,
+                           1, GJS_MODULE_PROP_FLAGS))
+        return FALSE;
+    
+	success = gjs_context_eval_file(context, filename, &code, &error);
+	
+	if (!success)
+	{
+		g_error("%s", error->message);
+		return FALSE;
+	}
 	
 	return TRUE;
 }



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