Skip to content

Commit

Permalink
use klongpy to test klongpy
Browse files Browse the repository at this point in the history
  • Loading branch information
briangu committed Sep 23, 2023
1 parent f7d6c87 commit c8889a7
Show file tree
Hide file tree
Showing 18 changed files with 27 additions and 113 deletions.
7 changes: 0 additions & 7 deletions tests/kgtests/db/test_array_modification_table_effects.kg
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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!")]
7 changes: 0 additions & 7 deletions tests/kgtests/db/test_array_update_table_effects.kg
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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!")]
7 changes: 0 additions & 7 deletions tests/kgtests/db/test_create_empty_table.kg
Original file line number Diff line number Diff line change
@@ -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" []]])
Expand All @@ -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!")]
7 changes: 0 additions & 7 deletions tests/kgtests/db/test_create_multi_col_table.kg
Original file line number Diff line number Diff line change
@@ -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::[]
Expand All @@ -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!")]
7 changes: 0 additions & 7 deletions tests/kgtests/db/test_create_one_col_table.kg
Original file line number Diff line number Diff line change
@@ -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])
Expand All @@ -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!")]
11 changes: 2 additions & 9 deletions tests/kgtests/db/test_multi_col_insert_with_multi_index.kg
Original file line number Diff line number Diff line change
@@ -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::[]
Expand All @@ -19,16 +14,14 @@ 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]])

.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!")]
14 changes: 4 additions & 10 deletions tests/kgtests/db/test_multi_col_insert_with_single_index.kg
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -16,21 +12,19 @@ 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]])

.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!")]
8 changes: 1 addition & 7 deletions tests/kgtests/db/test_multi_insert_no_index.kg
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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!")]
7 changes: 0 additions & 7 deletions tests/kgtests/db/test_multi_table_join.kg
Original file line number Diff line number Diff line change
@@ -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::[]
Expand All @@ -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!")]
7 changes: 0 additions & 7 deletions tests/kgtests/db/test_rindex.kg
Original file line number Diff line number Diff line change
@@ -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])
Expand All @@ -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!")]
7 changes: 0 additions & 7 deletions tests/kgtests/db/test_table_modification_array_effects.kg
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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!")]
7 changes: 0 additions & 7 deletions tests/kgtests/db/test_table_via_dict_behavior.kg
Original file line number Diff line number Diff line change
@@ -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::[]
Expand All @@ -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!")]
7 changes: 0 additions & 7 deletions tests/kgtests/interop/test_import.kg
Original file line number Diff line number Diff line change
@@ -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!")]
7 changes: 0 additions & 7 deletions tests/kgtests/interop/test_import_multiple_sub_modules.kg
Original file line number Diff line number Diff line change
@@ -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!")]
7 changes: 0 additions & 7 deletions tests/kgtests/interop/test_import_sub_module.kg
Original file line number Diff line number Diff line change
@@ -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!")]
1 change: 1 addition & 0 deletions tests/kgtests/known_failure.kg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
t("1+1"; 1+1; 3)
9 changes: 9 additions & 0 deletions tests/kgtests/runner.kg
Original file line number Diff line number Diff line change
@@ -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!")]
13 changes: 10 additions & 3 deletions tests/test_kgtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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".
Expand All @@ -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)

0 comments on commit c8889a7

Please sign in to comment.