From c8889a7ca8c2c675678055282046818faa0a04cd Mon Sep 17 00:00:00 2001 From: Brian Guarraci Date: Sat, 23 Sep 2023 17:26:39 -0600 Subject: [PATCH] use klongpy to test klongpy --- .../db/test_array_modification_table_effects.kg | 7 ------- .../kgtests/db/test_array_update_table_effects.kg | 7 ------- tests/kgtests/db/test_create_empty_table.kg | 7 ------- tests/kgtests/db/test_create_multi_col_table.kg | 7 ------- tests/kgtests/db/test_create_one_col_table.kg | 7 ------- .../db/test_multi_col_insert_with_multi_index.kg | 11 ++--------- .../db/test_multi_col_insert_with_single_index.kg | 14 ++++---------- tests/kgtests/db/test_multi_insert_no_index.kg | 8 +------- tests/kgtests/db/test_multi_table_join.kg | 7 ------- tests/kgtests/db/test_rindex.kg | 7 ------- .../db/test_table_modification_array_effects.kg | 7 ------- tests/kgtests/db/test_table_via_dict_behavior.kg | 7 ------- tests/kgtests/interop/test_import.kg | 7 ------- .../interop/test_import_multiple_sub_modules.kg | 7 ------- tests/kgtests/interop/test_import_sub_module.kg | 7 ------- tests/kgtests/known_failure.kg | 1 + tests/kgtests/runner.kg | 9 +++++++++ tests/test_kgtests.py | 13 ++++++++++--- 18 files changed, 27 insertions(+), 113 deletions(-) create mode 100644 tests/kgtests/known_failure.kg create mode 100644 tests/kgtests/runner.kg diff --git a/tests/kgtests/db/test_array_modification_table_effects.kg b/tests/kgtests/db/test_array_modification_table_effects.kg index ae403d6..4e1e4c2 100644 --- a/tests/kgtests/db/test_array_modification_table_effects.kg +++ b/tests/kgtests/db/test_array_modification_table_effects.kg @@ -1,8 +1,3 @@ -err::0 -wl::{.w(x);.p("")} -fail::{err::1;.d("failed: ");.p(x);.d("expected: ");wl(z);.d("got: ");wl(y);[]} -t::{:[~y~z;fail(x;y;z);[]]} - .py("klongpy.db") a::[1 2 3] @@ -23,5 +18,3 @@ b::b,5 c::c,6 t("db(""select a from T"")"; db("select a from T"); [1 2 3]) - -:[err;[];.p("ok!")] diff --git a/tests/kgtests/db/test_array_update_table_effects.kg b/tests/kgtests/db/test_array_update_table_effects.kg index fae8d41..f0ea117 100644 --- a/tests/kgtests/db/test_array_update_table_effects.kg +++ b/tests/kgtests/db/test_array_update_table_effects.kg @@ -1,8 +1,3 @@ -err::0 -wl::{.w(x);.p("")} -fail::{err::1;.d("failed: ");.p(x);.d("expected: ");wl(z);.d("got: ");wl(y);[]} -t::{:[~y~z;fail(x;y;z);[]]} - .py("klongpy.db") a::[1 2 3] @@ -26,5 +21,3 @@ t("db(""select a from T"")"; db("select a from T"); [1 2 3]) T,"a",,a t("db(""select a from T"")"; db("select a from T"); [1 0 3]) - -:[err;[];.p("ok!")] diff --git a/tests/kgtests/db/test_create_empty_table.kg b/tests/kgtests/db/test_create_empty_table.kg index 92801d3..893dfd5 100644 --- a/tests/kgtests/db/test_create_empty_table.kg +++ b/tests/kgtests/db/test_create_empty_table.kg @@ -1,8 +1,3 @@ -err::0 -wl::{.w(x);.p("")} -fail::{err::1;.d("failed: ");.p(x);.d("expected: ");wl(z);.d("got: ");wl(y);[]} -t::{:[~y~z;fail(x;y;z);[]]} - .py("klongpy.db") T::.table([["a" []]]) @@ -12,5 +7,3 @@ t("db(""select * from T"")"; db("select * from T"); []) t("db(""select a from T"")"; db("select a from T"); []) t(".schema(T)"; .schema(T); ["a"]) - -:[err;[];.p("ok!")] diff --git a/tests/kgtests/db/test_create_multi_col_table.kg b/tests/kgtests/db/test_create_multi_col_table.kg index cf96f41..d3c3d10 100644 --- a/tests/kgtests/db/test_create_multi_col_table.kg +++ b/tests/kgtests/db/test_create_multi_col_table.kg @@ -1,8 +1,3 @@ -err::0 -wl::{.w(x);.p("")} -fail::{err::1;.d("failed: ");.p(x);.d("expected: ");wl(z);.d("got: ");wl(y);[]} -t::{:[~y~z;fail(x;y;z);[]]} - .py("klongpy.db") e::[] @@ -16,5 +11,3 @@ db::.db(:{},"T",,T) t("db(""select * from T"")"; db("select * from T"); [[1 2 3] [2 3 4] [3 4 5]]) t(".schema(T)"; .schema(T); ["a" "b" "c"]) - -:[err;[];.p("ok!")] diff --git a/tests/kgtests/db/test_create_one_col_table.kg b/tests/kgtests/db/test_create_one_col_table.kg index 0304301..7a18b7e 100644 --- a/tests/kgtests/db/test_create_one_col_table.kg +++ b/tests/kgtests/db/test_create_one_col_table.kg @@ -1,8 +1,3 @@ -err::0 -wl::{.w(x);.p("")} -fail::{err::1;.d("failed: ");.p(x);.d("expected: ");wl(z);.d("got: ");wl(y);[]} -t::{:[~y~z;fail(x;y;z);[]]} - .py("klongpy.db") T::.table(,"a",,[1 2 3]) @@ -11,5 +6,3 @@ db::.db(:{},"T",,T) t("db(""select * from T"")"; db("select * from T"); [1 2 3]) t(".schema(T)"; .schema(T); ["a"]) - -:[err;[];.p("ok!")] diff --git a/tests/kgtests/db/test_multi_col_insert_with_multi_index.kg b/tests/kgtests/db/test_multi_col_insert_with_multi_index.kg index 560ead2..0215ac8 100644 --- a/tests/kgtests/db/test_multi_col_insert_with_multi_index.kg +++ b/tests/kgtests/db/test_multi_col_insert_with_multi_index.kg @@ -1,8 +1,3 @@ -err::0 -wl::{.w(x);.p("")} -fail::{err::1;.d("failed: ");.p(x);.d("expected: ");wl(z);.d("got: ");wl(y);[]} -t::{:[~y~z;fail(x;y;z);[]]} - .py("klongpy.db") e::[] @@ -19,10 +14,10 @@ db::.db(:{},"T",,T) t("db(""select * from T"")"; db("select * from T"); [[1 2 3] [2 3 4] [3 4 5]]) .insert(T; [4 5 6]) -t("db(""select * from T"")"; db("select * from T"); [[1 2 3] [2 3 4] [3 4 5] [4 5 6]]) +t("db(""select * from T"")"; db("select * from T"); [[1 2 3] [2 3 4] [3 4 5] [4 5 6]]) .insert(T; [4 5 6]) -t("db(""select * from T"")"; db("select * from T"); [[1 2 3] [2 3 4] [3 4 5] [4 5 6]]) +t("db(""select * from T"")"; db("select * from T"); [[1 2 3] [2 3 4] [3 4 5] [4 5 6]]) .insert(T; [4 6 7]) t("db(""select * from T"")"; db("select * from T"); [[1 2 3] [2 3 4] [3 4 5] [4 5 6] [4 6 7]]) @@ -30,5 +25,3 @@ t("db(""select * from T"")"; db("select * from T"); [[1 2 3] [2 3 4] [3 4 5] [4 .rindex(T) .insert(T; [4 6 7]) t("db(""select * from T"")"; db("select * from T"); [[1 2 3] [2 3 4] [3 4 5] [4 5 6] [4 6 7] [4 6 7]]) - -:[err;[];.p("ok!")] diff --git a/tests/kgtests/db/test_multi_col_insert_with_single_index.kg b/tests/kgtests/db/test_multi_col_insert_with_single_index.kg index ef6d19a..a6fb6b1 100644 --- a/tests/kgtests/db/test_multi_col_insert_with_single_index.kg +++ b/tests/kgtests/db/test_multi_col_insert_with_single_index.kg @@ -1,9 +1,5 @@ -err::0 -wl::{.w(x);.p("")} -fail::{err::1;.d("failed: ");.p(x);.d("expected: ");wl(z);.d("got: ");wl(y);[]} -t::{:[~y~z;fail(x;y;z);[]]} - .py("klongpy.db") + e::[] e::e,,"a",,[1 2 3] e::e,,"b",,[2 3 4] @@ -16,15 +12,15 @@ db::.db(:{},"T",,T) t("db(""select * from T"")"; db("select * from T"); [[1 2 3] [2 3 4] [3 4 5]]) .insert(T; [4 5 6]) -t("db(""select * from T"")"; db("select * from T"); [[1 2 3] [2 3 4] [3 4 5] [4 5 6]]) +t("db(""select * from T"")"; db("select * from T"); [[1 2 3] [2 3 4] [3 4 5] [4 5 6]]) .insert(T; [4 5 6]) -t("db(""select * from T"")"; db("select * from T"); [[1 2 3] [2 3 4] [3 4 5] [4 5 6] [4 5 6]]) +t("db(""select * from T"")"; db("select * from T"); [[1 2 3] [2 3 4] [3 4 5] [4 5 6] [4 5 6]]) t(".index(T;[""a""])"; .index(T;["a"]); ["a"]) .insert(T; [4 5 6]) -t("db(""select * from T"")"; db("select * from T"); [[1 2 3] [2 3 4] [3 4 5] [4 5 6]]) +t("db(""select * from T"")"; db("select * from T"); [[1 2 3] [2 3 4] [3 4 5] [4 5 6]]) .insert(T; [4 6 7]) t("db(""select * from T"")"; db("select * from T"); [[1 2 3] [2 3 4] [3 4 5] [4 6 7]]) @@ -32,5 +28,3 @@ t("db(""select * from T"")"; db("select * from T"); [[1 2 3] [2 3 4] [3 4 5] [4 .rindex(T) .insert(T; [4 6 7]) t("db(""select * from T"")"; db("select * from T"); [[1 2 3] [2 3 4] [3 4 5] [4 6 7] [4 6 7]]) - -:[err;[];.p("ok!")] diff --git a/tests/kgtests/db/test_multi_insert_no_index.kg b/tests/kgtests/db/test_multi_insert_no_index.kg index 4b4543e..6516d59 100644 --- a/tests/kgtests/db/test_multi_insert_no_index.kg +++ b/tests/kgtests/db/test_multi_insert_no_index.kg @@ -1,9 +1,5 @@ -err::0 -wl::{.w(x);.p("")} -fail::{err::1;.d("failed: ");.p(x);.d("expected: ");wl(z);.d("got: ");wl(y);[]} -t::{:[~y~z;fail(x;y;z);[]]} - .py("klongpy.db") + a::[1 2 3] b::[2 3 4] c::[3 4 5] @@ -21,5 +17,3 @@ t("db(""select * from T"")"; db("select * from T"); [[1 2 3] [2 3 4] [3 4 5]]) .insert(T; [4 5 6]) t("db(""select * from T"")"; db("select * from T"); [[1 2 3] [2 3 4] [3 4 5] [4 5 6]]) - -:[err;[];.p("ok!")] diff --git a/tests/kgtests/db/test_multi_table_join.kg b/tests/kgtests/db/test_multi_table_join.kg index 96b5869..142ec8d 100644 --- a/tests/kgtests/db/test_multi_table_join.kg +++ b/tests/kgtests/db/test_multi_table_join.kg @@ -1,8 +1,3 @@ -err::0 -wl::{.w(x);.p("")} -fail::{err::1;.d("failed: ");.p(x);.d("expected: ");wl(z);.d("got: ");wl(y);[]} -t::{:[~y~z;fail(x;y;z);[]]} - .py("klongpy.db") d::[] @@ -25,5 +20,3 @@ t("db(""select * from T join G on G.c = T.b"")"; db("select * from T join G on G t("#.schema(db)"; #.schema(db); 2) t(".schema(db)?""T"""; .schema(db)?"T"; ["a" "b"]) t(".schema(db)?""G"""; .schema(db)?"G"; ["c"]) - -:[err;[];.p("ok!")] diff --git a/tests/kgtests/db/test_rindex.kg b/tests/kgtests/db/test_rindex.kg index 64a9fe4..8c36f73 100644 --- a/tests/kgtests/db/test_rindex.kg +++ b/tests/kgtests/db/test_rindex.kg @@ -1,8 +1,3 @@ -err::0 -wl::{.w(x);.p("")} -fail::{err::1;.d("failed: ");.p(x);.d("expected: ");wl(z);.d("got: ");wl(y);[]} -t::{:[~y~z;fail(x;y;z);[]]} - .py("klongpy.db") T::.table(,"a",,[1 2 3]) @@ -11,5 +6,3 @@ t(".index(T;[""a""])"; .index(T;["a"]); ["a"]) t(".rindex(T) 1"; .rindex(T); 1) t(".rindex(T) 0"; .rindex(T); 0) - -:[err;[];.p("ok!")] diff --git a/tests/kgtests/db/test_table_modification_array_effects.kg b/tests/kgtests/db/test_table_modification_array_effects.kg index a4db775..0393018 100644 --- a/tests/kgtests/db/test_table_modification_array_effects.kg +++ b/tests/kgtests/db/test_table_modification_array_effects.kg @@ -1,8 +1,3 @@ -err::0 -wl::{.w(x);.p("")} -fail::{err::1;.d("failed: ");.p(x);.d("expected: ");wl(z);.d("got: ");wl(y);[]} -t::{:[~y~z;fail(x;y;z);[]]} - .py("klongpy.db") a::[1 2 3] @@ -27,5 +22,3 @@ t("db(""select a from T"")"; db("select a from T"); [1 2 3 4]) t("a"; a; [1 2 3]) t("b"; b; [2 3 4]) t("c"; c; [3 4 5]) - -:[err;[];.p("ok!")] diff --git a/tests/kgtests/db/test_table_via_dict_behavior.kg b/tests/kgtests/db/test_table_via_dict_behavior.kg index 515a7bb..0ed659c 100644 --- a/tests/kgtests/db/test_table_via_dict_behavior.kg +++ b/tests/kgtests/db/test_table_via_dict_behavior.kg @@ -1,8 +1,3 @@ -err::0 -wl::{.w(x);.p("")} -fail::{err::1;.d("failed: ");.p(x);.d("expected: ");wl(z);.d("got: ");wl(y);[]} -t::{:[~y~z;fail(x;y;z);[]]} - .py("klongpy.db") d::[] @@ -23,5 +18,3 @@ t("db(""select * from T"")"; db("select * from T"); [[1 2 3] [2 3 4] [3 4 5]]) t("#.schema(db)"; #.schema(db); 1) t(".schema(db)?""T"""; .schema(db)?"T"; ["a" "b" "c"]) - -:[err;[];.p("ok!")] diff --git a/tests/kgtests/interop/test_import.kg b/tests/kgtests/interop/test_import.kg index 7a4706d..f2b7a74 100644 --- a/tests/kgtests/interop/test_import.kg +++ b/tests/kgtests/interop/test_import.kg @@ -1,9 +1,2 @@ -err::0 -wl::{.w(x);.p("")} -fail::{err::1;.d("failed: ");.p(x);.d("expected: ");wl(z);.d("got: ");wl(y);[]} -t::{:[~y~z;fail(x;y;z);[]]} - t(".py(""math"")"; .py("math"); 1) t("sqrt(4)"; sqrt(4); 2) - -:[err;[];.p("ok!")] diff --git a/tests/kgtests/interop/test_import_multiple_sub_modules.kg b/tests/kgtests/interop/test_import_multiple_sub_modules.kg index c2994a4..7c28dfc 100644 --- a/tests/kgtests/interop/test_import_multiple_sub_modules.kg +++ b/tests/kgtests/interop/test_import_multiple_sub_modules.kg @@ -1,10 +1,3 @@ -err::0 -wl::{.w(x);.p("")} -fail::{err::1;.d("failed: ");.p(x);.d("expected: ");wl(z);.d("got: ");wl(y);[]} -t::{:[~y~z;fail(x;y;z);[]]} - t(".py(""math"";[""sqrt"" ""fsum""])"; .py("math";["sqrt" "fsum"]); 1) t("sqrt(4)"; sqrt(4); 2) t("fsum(!100)"; fsum(!100); +/!100) - -:[err;[];.p("ok!")] diff --git a/tests/kgtests/interop/test_import_sub_module.kg b/tests/kgtests/interop/test_import_sub_module.kg index 89531b5..1618e99 100644 --- a/tests/kgtests/interop/test_import_sub_module.kg +++ b/tests/kgtests/interop/test_import_sub_module.kg @@ -1,9 +1,2 @@ -err::0 -wl::{.w(x);.p("")} -fail::{err::1;.d("failed: ");.p(x);.d("expected: ");wl(z);.d("got: ");wl(y);[]} -t::{:[~y~z;fail(x;y;z);[]]} - t(".py(""math"";""sqrt"")"; .py("math";"sqrt"); 1) t("sqrt(4)"; sqrt(4); 2) - -:[err;[];.p("ok!")] diff --git a/tests/kgtests/known_failure.kg b/tests/kgtests/known_failure.kg new file mode 100644 index 0000000..4edbc6e --- /dev/null +++ b/tests/kgtests/known_failure.kg @@ -0,0 +1 @@ +t("1+1"; 1+1; 3) diff --git a/tests/kgtests/runner.kg b/tests/kgtests/runner.kg new file mode 100644 index 0000000..c31fd40 --- /dev/null +++ b/tests/kgtests/runner.kg @@ -0,0 +1,9 @@ +err::0 +wl::{.w(x);.p("")} +fail::{err::1;.d("failed: ");.p(x);.d("expected: ");wl(z);.d("got: ");wl(y);[]} +t::{:[~y~z;fail(x;y;z);[]]} + +.p("testing: ");.p(x) +.l(fullpath) + +:[err;[];.p("ok!")] diff --git a/tests/test_kgtests.py b/tests/test_kgtests.py index 8a5d7ac..04c438c 100644 --- a/tests/test_kgtests.py +++ b/tests/test_kgtests.py @@ -8,6 +8,13 @@ class TestKgTests(unittest.TestCase): + def test_known_failure(self): + klong = KlongInterpreter() + klong['fullpath'] = "tests/kgtests/known_failure.kg" + klong('.l("tests/kgtests/runner.kg")') + self.assertEqual(klong['err'], 1) + + def test_kgtests(self): """ Recursively run all tests under the kgtests folder that begin with "test" and end with ".kg". @@ -19,9 +26,9 @@ def test_kgtests(self): for fname in filenames: if fname.startswith("test") and fname.endswith(".kg"): ran_tests = True - full_path = os.path.join(dirpath, fname) - print(f"TESTING: {fname}") - klong, _ = run_file(full_path) + klong = KlongInterpreter() + klong['fullpath'] = os.path.join(dirpath, fname) + klong('.l("tests/kgtests/runner.kg")') self.assertEqual(klong['err'], 0) self.assertTrue(ran_tests)