From 9106d1437161717213bacf3bc9ac040a5aac181e Mon Sep 17 00:00:00 2001 From: Elliot Chance Date: Thu, 21 Dec 2023 22:53:16 +0100 Subject: [PATCH] testing: Comments are now supported (#182) Not sure why it took me so long to implement, but you can now add comments to tests by using `-- #`. --- docs/testing.rst | 27 +++++++++++++++++++++++++++ tests/testing-comments.sql | 10 ++++++++++ vsql/sql_test.v | 2 ++ 3 files changed, 39 insertions(+) create mode 100644 tests/testing-comments.sql diff --git a/docs/testing.rst b/docs/testing.rst index 8ea5919..9f84d63 100644 --- a/docs/testing.rst +++ b/docs/testing.rst @@ -227,6 +227,33 @@ There are slightly different forms depending on the type of the host parameter: - ``/* set b 'foo' */`` for string values. - ``/* set b NULL BOOLEAN */`` for ``NULL`` values (must specify a type). +Comments +^^^^^^^^ + +Ordinary comments are collected for the expected output. If you want to place an +ignored comment line you can prefix the line with ``-- #``: + +.. code-block:: sql + + -- # This test adds some numbers. + VALUES 1 + 2; + -- COL1: 3 + +While the placement of comment lines does not matter, it is by convention that +comments pertaining to a specific test be joined (without a blank line) and +comments relating to the entire file or group of tests below use a empty line +separator: + +.. code-block:: sql + + -- # The following tests are arithmetic. + + VALUES 1 + 2; + -- COL1: 3 + + VALUES 3 * 4; + -- COL1: 12 + Multiple Connections ^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/testing-comments.sql b/tests/testing-comments.sql new file mode 100644 index 0000000..5e43349 --- /dev/null +++ b/tests/testing-comments.sql @@ -0,0 +1,10 @@ +-- # The following tests are arithmetic. + +-- # Adding +VALUES 1 + 2; +-- COL1: 3 + +VALUES 3 * 4; +-- # Comments can be nested, +-- COL1: 12 +-- # .. and afterwards. diff --git a/vsql/sql_test.v b/vsql/sql_test.v index 6edc7b3..cc7473b 100644 --- a/vsql/sql_test.v +++ b/vsql/sql_test.v @@ -72,6 +72,8 @@ fn get_tests() ![]SQLTest { } else { panic('bad directive: "${contents}"') } + } else if line.starts_with('-- #') { + continue } else if line.starts_with('-- ') { expected << line[3..] } else {