diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-10-16 21:03:57 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-10-16 21:03:57 +0100 |
| commit | 9f056da229fa326f364bd7ac3a8d835e164f7a9d (patch) | |
| tree | dbc2bd0d50522336c5aa301375f4830d1464dc90 | |
| parent | 62a4eceab6cc1ef19ab3fd4aa42d0ae970e73fcb (diff) | |
Add test for SQL creation scriptmain
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | examples/18-database/output/sqlite3/test.py | 24 | ||||
| -rw-r--r-- | src/test/java/org/zwobble/hobgoblin/compiler/ExampleTests.java | 13 |
3 files changed, 38 insertions, 0 deletions
@@ -1,3 +1,4 @@ /.idea /target last-test-run.properties +__pycache__ diff --git a/examples/18-database/output/sqlite3/test.py b/examples/18-database/output/sqlite3/test.py new file mode 100644 index 0000000..885212b --- /dev/null +++ b/examples/18-database/output/sqlite3/test.py @@ -0,0 +1,24 @@ +import os.path +import sqlite3 +import unittest + + +class DataTestCase(unittest.TestCase): + def test_create(self): + sql_script_path = os.path.join(os.path.dirname(__file__), "scripts/data/Data.sql") + with open(sql_script_path, "rt", encoding="utf-8") as sql_script_file: + sql_script = sql_script_file.read() + + connection = sqlite3.connect(":memory:", autocommit=False) + cursor = connection.cursor() + cursor.executescript(sql_script) + connection.commit() + + cursor.execute("INSERT INTO authors VALUES (1, 'Alice')") + cursor.execute("INSERT INTO authors VALUES (2, 'Bob')") + cursor.execute("INSERT INTO authors VALUES (3, 'Carol')") + + cursor.execute("SELECT id, name FROM authors WHERE id > 1 ORDER BY id") + rows = cursor.fetchall() + + self.assertEqual(rows, [(2, "Bob"), (3, "Carol")]) diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/ExampleTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/ExampleTests.java index dbd1227..d1f177d 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/ExampleTests.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/ExampleTests.java @@ -32,6 +32,7 @@ public class ExampleTests { var javaOutputPath = verifyJavaOutput(exampleSet); var rustOutputPath = verifyRustOutput(exampleSet); + verifySqlite3Output(exampleSet); verifyTypescriptOutput(exampleSet); var transient0OutputDirs = Stream.of(javaOutputPath, rustOutputPath) @@ -68,6 +69,18 @@ public class ExampleTests { return verifyOutput(exampleSet, "rust", List.of(List.of("cargo", "test"))); } + private void verifySqlite3Output( + ExampleSet exampleSet + ) throws NoSuchAlgorithmException, IOException, InterruptedException { + verifyOutput( + exampleSet, + "sqlite3", + List.of( + List.of("python3", "-m", "unittest", "test.py") + ) + ); + } + private Optional<Path> verifyTypescriptOutput(ExampleSet exampleSet) throws NoSuchAlgorithmException, IOException, InterruptedException { return verifyOutput(exampleSet, "typescript", List.of( List.of("pnpm", "install"), |
