sqlite
[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.
Brought by drakestapleton
sqlite / doc / writing-test-cases.md
| 1 | # Hints For Writing Test Cases For SQLite |
| 2 | |
| 3 | ## SQL scripts that run using the "sqlite3" command-line interface (CLI) |
| 4 | |
| 5 | * This is preferred. Use this technique unless the test |
| 6 | requires capabilities not available in the CLI. |
| 7 | |
| 8 | * If possible, the test case should be runable with the --safe command-line |
| 9 | option of the CLI. If not possible, externally submitted test scripts |
| 10 | should explain why not in a comment near the top of the file. |
| 11 | |
| 12 | * The test case should use an in-memory database only, if possible. |
| 13 | If external filesystem resources are required, they should be specified |
| 14 | using relative pathnames. A concise comment explaining why external |
| 15 | resources are required should appear near the top of the script. |
| 16 | |
| 17 | * Format the SQL for readability, with indentation that shows |
| 18 | structure. Avoid lines of text longer than 80 characters. |
| 19 | |
| 20 | * SQL keywords in uppercase. Identifiers in lowercase. |
| 21 | |
| 22 | * Identifiers should be short - two or three characters - unless a long |
| 23 | identifier name is required to demonstrate the desired behavior. |
| 24 | |
| 25 | * Column names should be unique across all table, unless shared |
| 26 | column names are required to demonstrate the desired behavior (for |
| 27 | example the USING clause or NATURAL joins). |
| 28 | |
| 29 | * The test case should be as simple as possible without compromising |
| 30 | legibility. Omit unnecessary SQL clauses and other complications. |
| 31 | Populate test databases with the minimum amount of content needed |
| 32 | to demonstrate the desired behavior. |
| 33 | |
| 34 | * Concise comments are ok. Prolix comments are discouraged. |
| 35 | |
| 36 | * Avoid unnecessary ".print" commands as these can be annoying to |
| 37 | users of the script. Commentary should go in comments. |
| 38 | |
| 39 | * Use ".testcase" and ".check" pairs to enclose individual tests as |
| 40 | the argument to ".check" clearly shows the reader what the result |
| 41 | should be which is helpful in understanding the script. |
| 42 | |
| 43 | * Rules for quoting arguments to dot-command: |
| 44 | <https://sqlite.org/cli.html#dot_command_arguments> |
| 45 | |
| 46 | * Use ".help" to see a list of available dot-commands in the CLI. |
| 47 | Use ".help COMMAND" for more information about a particular command. |
| 48 | |
| 49 | * Detailed documentation on operating the CLI: |
| 50 | <https://sqlite.org/cli.html> |
| 51 | |
| 52 | * Use files in the SQLite source tree named "test/\*.sql" as examples. |
| 53 | |
| 54 | ## TCL scripts run with "testfixture" |
| 55 | |
| 56 | * SQL scripts are preferred. Use a TCL test script only if an SQL |
| 57 | script is unable to easily demonstrate the desired behavior. |
| 58 | Externally submitted scripts should include a one- or two-sentence |
| 59 | explanation of why TCL is necessary in a comment near the top of |
| 60 | the script. |
| 61 | |
| 62 | * All applicable rules of SQL test scripts apply to TCL scripts too. |
| 63 | |
| 64 | * Use files in the SQLite source tree named "\*.test" as examples. |
| 65 | |
| 66 | ## C programs that link against the "sqlite3.c" amalgamated source code. |
| 67 | |
| 68 | * SQL scripts and TCL scripts are preferred over C code Only use |
| 69 | C code if pure SQL or a TCL script is inadequate. Include a short |
| 70 | comment near the top of the C source file explaining why C code is |
| 71 | necessary. |
| 72 | |
| 73 | * Portable C99. Should compile with gcc and/or clang on Linux. |
| 74 | Use C code written for "cl" on Windows only for Windows-specific tests. |
| 75 | |
| 76 | * All applicable rules of SQL and TCL test scripts apply to C code |
| 77 | tests too. |