Skip to content

Commit

Permalink
testing: Comments are now supported (#182)
Browse files Browse the repository at this point in the history
Not sure why it took me so long to implement, but you can now add
comments to tests by using `-- #`.
  • Loading branch information
elliotchance committed Dec 21, 2023
1 parent 6514f2c commit 9106d14
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
27 changes: 27 additions & 0 deletions docs/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^^^^^^^^^^^^^^^

Expand Down
10 changes: 10 additions & 0 deletions tests/testing-comments.sql
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 2 additions & 0 deletions vsql/sql_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 9106d14

Please sign in to comment.