The Tests project is the automated test suite for SQL Notebook. It uses a custom test framework and primarily tests the scripting engine through file-based SQL test scripts.
The project implements its own lightweight test runner rather than using xUnit or NUnit:
- Attributes:
[TestClass],[TestMethod],[ClassInitialize](defined inProgram.cs) - Assert class: Custom implementation with
AreEqual,IsTrue,IsInstanceOfType,Fail. String comparisons automatically normalize whitespace and line endings. - Test runner: Uses reflection to discover and execute test classes. Supports command-line filtering by test name. Returns exit code 1 on failure.
Test methods in ScriptTest.g.cs are auto-generated by ps1/Update-Tests.ps1, which scans the scripts/ directory and generates one [TestMethod] per .sql file. This means adding a new test is as simple as adding a .sql file and re-running the generator.
Each .sql file contains a SQL Notebook script followed by expected output, separated by --output--:
DECLARE @x = 5;
PRINT @x;
--output--
5Multi-script tests use --script-- separators to define named scripts that can call each other via EXECUTE.
Placeholders:
<TEMP>- Replaced with a temporary directory path<FILES>- Replaced with the path to thefiles/test data directory
Result format: Data table output uses CSV-like formatting with - row separators between columns and rows.
| Class | File | Coverage |
|---|---|---|
ScriptTest |
ScriptTest.cs, ScriptTest.g.cs |
224 script-based integration tests covering the full scripting language |
SqliteGrammarTest |
SqliteGrammarTest.cs |
Validates 100+ SQL statements against the SQLite grammar parser |
DropStatementsTest |
DropStatementsTest.cs |
Tests DROP SCRIPT and DROP PAGE with case-insensitivity |
SqlNotebookCmdTest |
SqlNotebookCmdTest.cs |
CLI integration tests (success, errors, help output) |
FileVersionTest |
FileVersionTest.cs |
Backward compatibility with v1 notebook format |
Pre-built test data files used by import tests:
- CSV:
utf8.csv,utf16.csv,blank-values.csv,duplicate-header.csv, etc. - Excel:
excel.xlsx,excel.xls, variants with blank rows/values - Text:
utf8.txt,utf16.txt,shiftjis.txt - Databases:
example.sqlite3,example.duckdb - Notebooks:
cli_test.sqlnb,v1.sqlnb
The 224 script tests cover:
- Control flow: IF/ELSE, WHILE, FOR, FOREACH, BREAK, CONTINUE, nested loops
- Variables: DECLARE, SET, parameter passing, default values
- Script execution: EXECUTE with parameters, return values
- Import: CSV (24 tests), Excel (32 tests), TXT (6 tests), DATABASE (4 tests)
- Export: CSV (9 tests), TXT (4 tests)
- DDL: ALTER TABLE (10 tests), CREATE TABLE, DROP statements
- Functions: Array, date, string, system, aggregate functions
- Advanced SQL: RETURNING clauses, JOINs, NULLS FIRST/LAST, CTEs, JSON operations
- Error handling: TRY/CATCH, THROW
- Documentation examples: 85 tests in
scripts/doc/that validate examples from the help docs
Runs once before any tests:
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance)- Enable legacy encodingsNotebook.InitSqlite()- Initialize the native SQLite engine and extensions
No NuGet packages. Only project references to SqlNotebook, SqlNotebookScript, and SqlNotebookCmd.