[gnome-js-common] Simplify tests a little
- From: Robert Carr <racarr src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnome-js-common] Simplify tests a little
- Date: Thu, 28 May 2009 18:49:34 -0400 (EDT)
commit 19e1a71b2821232b02bc55efcfad462a060bec4d
Author: Robert Carr <racarr svn gnome org>
Date: Thu May 28 18:49:27 2009 -0400
Simplify tests a little
---
tests/assert.js | 26 ++++----------
tests/everything.js | 2 +
tests/run-tests-seed.c | 87 ++++++++++++++++++++---------------------------
tests/run-tests.c | 44 +++++++++++++-----------
4 files changed, 69 insertions(+), 90 deletions(-)
diff --git a/tests/assert.js b/tests/assert.js
index 266ca64..24d6218 100644
--- a/tests/assert.js
+++ b/tests/assert.js
@@ -1,21 +1,9 @@
-var flag = 0;
+assert = function(val){
+ AssertionError = function(string){
+ this.name = "AssertionError"
+ this.message = string;
+ }
-try
-{
- assert(1 == 2);
+ if (!val)
+ throw new AssertionError("Assertion failed");
}
-catch(e)
-{
- flag++;
-}
-
-try
-{
- assert(0);
-}
-catch(e)
-{
- flag++;
-}
-
-assert(flag == 2);
diff --git a/tests/everything.js b/tests/everything.js
index 15c17f3..c745654 100644
--- a/tests/everything.js
+++ b/tests/everything.js
@@ -3,6 +3,8 @@ GObject = imports.gi.GObject;
JSON = imports.JSON;
+assert = imports.assert.assert
+
with(Everything)
{
assert(test_boolean(true) == true);
diff --git a/tests/run-tests-seed.c b/tests/run-tests-seed.c
index 23d3b0c..b52e31d 100644
--- a/tests/run-tests-seed.c
+++ b/tests/run-tests-seed.c
@@ -10,64 +10,51 @@
SeedEngine * eng = NULL;
extern gboolean failure_flag;
-SeedValue js_assert(SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
-{
- if(!seed_value_to_boolean(ctx, arguments[0], NULL))
- seed_make_exception(ctx, exception, "AssertionError", "Assertion failed");
-}
-
gboolean test_exec(gchar * filename)
{
- SeedObject global;
- SeedScript * script;
- SeedException e;
- gchar * buffer;
+ SeedObject global;
+ SeedScript * script;
+ SeedException e;
+ gchar * buffer;
- if(!eng)
- eng = seed_init(NULL, NULL);
-
- g_file_get_contents(filename, &buffer, 0, 0);
-
- if(!buffer)
- {
- g_critical("File %s not found!", filename);
- exit(1);
- }
-
- if(*buffer == '#')
- {
- while(*buffer != '\n')
- buffer++;
- buffer++;
- }
-
- script = seed_make_script(eng->context, buffer, filename, 1);
- global = seed_context_get_global_object(eng->context);
- seed_importer_add_global(global, filename);
+ if(!eng)
+ eng = seed_init(NULL, NULL);
+
+ g_file_get_contents(filename, &buffer, 0, 0);
+
+ if(!buffer)
+ {
+ g_critical("File %s not found!", filename);
+ exit(1);
+ }
+
+ if(*buffer == '#')
+ {
+ while(*buffer != '\n')
+ buffer++;
+ buffer++;
+ }
+
+ script = seed_make_script(eng->context, buffer, filename, 1);
+ global = seed_context_get_global_object(eng->context);
+ seed_importer_add_global(global, filename);
- seed_create_function(eng->context, "assert", js_assert, global);
-
- seed_evaluate(eng->context, script, 0);
+ seed_evaluate(eng->context, script, 0);
- if((e = seed_script_exception(script)))
- {
- printf("%s... FAIL (%s: line %d)\n",
- filename,
- seed_exception_get_name(eng->context, e),
- seed_exception_get_line(eng->context, e));
+ if((e = seed_script_exception(script)))
+ {
+ printf("%s... FAIL (%s: line %d)\n",
+ filename,
+ seed_exception_get_name(eng->context, e),
+ seed_exception_get_line(eng->context, e));
- failure_flag = TRUE;
+ failure_flag = TRUE;
- return FALSE;
- }
+ return FALSE;
+ }
- g_free(script);
+ g_free(script);
- return TRUE;
+ return TRUE;
}
diff --git a/tests/run-tests.c b/tests/run-tests.c
index 061f1e8..c6f30c0 100644
--- a/tests/run-tests.c
+++ b/tests/run-tests.c
@@ -10,36 +10,38 @@ gboolean failure_flag = FALSE;
void run_tests(gchar * tests_dir_name)
{
- GDir * tests_dir;
- const gchar * test_name;
- const gchar * test_path;
+ GDir * tests_dir;
+ const gchar * test_name;
+ const gchar * test_path;
- tests_dir = g_dir_open(tests_dir_name, 0, NULL);
- while((test_name = g_dir_read_name(tests_dir)) != NULL)
- {
- if(!g_str_has_suffix(test_name, ".js")) // TODO: casing problem
- continue;
+ tests_dir = g_dir_open(tests_dir_name, 0, NULL);
+ while((test_name = g_dir_read_name(tests_dir)) != NULL)
+ {
+ if(!g_str_has_suffix(test_name, ".js")) // TODO: casing problem
+ continue;
- test_path = g_build_filename(tests_dir_name, test_name, NULL);
+ test_path = g_build_filename(tests_dir_name, test_name, NULL);
- if(test_exec((char*)test_path))
- printf("%s... OK\n", test_path);
- }
+ if (!strcmp (test_path, "./assert.js"))
+ continue;
+ if(test_exec((char*)test_path))
+ printf("%s... OK\n", test_path);
+ }
}
int main(int argc, char ** argv)
{
- if(argc == 1)
- run_tests(".");
- else
- {
- int i;
+ if(argc == 1)
+ run_tests(".");
+ else
+ {
+ int i;
- for(i = 1; i < argc; i++)
- run_tests(argv[i]);
- }
+ for(i = 1; i < argc; i++)
+ run_tests(argv[i]);
+ }
- return failure_flag;
+ return failure_flag;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]