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 / tcl-extension-testing.md
| 1 | # Test Procedures For The SQLite TCL Extension |
| 2 | |
| 3 | ## 1.0 Background |
| 4 | |
| 5 | The SQLite TCL extension logic (in the |
| 6 | "[tclsqlite.c](/file/src/tclsqlite.c)" source |
| 7 | file) is statically linked into "textfixture" executable |
| 8 | which is the program used to do most of the testing |
| 9 | associated with "make test", "make devtest", and/or |
| 10 | "make releasetest". So the functionality of the SQLite |
| 11 | TCL extension is thoroughly vetted during normal testing. The |
| 12 | procedures below are designed to test the loadable extension |
| 13 | aspect of the SQLite TCL extension, and in particular to verify |
| 14 | that the "make tclextension-install" build target works and that |
| 15 | an ordinary tclsh can subsequently run "package require sqlite3". |
| 16 | |
| 17 | This procedure can also be used as a template for how to set up |
| 18 | a local TCL+SQLite development environment. In other words, it |
| 19 | can be be used as a guide on how to compile per-user copies of |
| 20 | Tcl that are used to develop, test, and debug SQLite. In that |
| 21 | case, perhaps make minor changes to the procedure such as: |
| 22 | |
| 23 | * Make TCLBUILD directory is permanent. |
| 24 | * Enable debugging symbols on the Tcl library build. |
| 25 | * Reduce the optimization level to -O0 for easier debugging. |
| 26 | * Also compile "wish" to go with each "tclsh". |
| 27 | |
| 28 | |
| 29 | <a id="unix"></a> |
| 30 | ## 2.0 Testing On Unix-like Systems (Including Mac) |
| 31 | |
| 32 | See also the [](./compile-for-unix.md) document which provides another |
| 33 | perspective on how to compile SQLite on unix-like systems. |
| 34 | |
| 35 | ### 2.1 Setup |
| 36 | |
| 37 | <ol type="1"> |
| 38 | <li value="1"> |
| 39 | [Fossil][] installed. |
| 40 | <li> Check out source code and set environment variables: |
| 41 | <ol type="a"> |
| 42 | <li> **TCLSOURCE** → |
| 43 | The top-level directory of a [Fossil][] check-out of the |
| 44 | [TCL source tree][tcl-fossil]. |
| 45 | <li> **SQLITESOURCE** → |
| 46 | A Fossil check-out of the SQLite source tree. |
| 47 | <li> **TCLHOME** → |
| 48 | A directory that does not exist at the start of the test and which |
| 49 | will be deleted at the end of the test, and that will contain the |
| 50 | test builds of the TCL libraries and the SQLite TCL Extensions. |
| 51 | It is the top-most installation directory, i.e. the one provided |
| 52 | to Tcl's `./configure --prefix=/path/to/tcl`. |
| 53 | <li> **TCLVERSION** → |
| 54 | The `X.Y`-form version of Tcl being used: 8.6, 9.0, 9.1... |
| 55 | </ol> |
| 56 | </ol> |
| 57 | |
| 58 | ### 2.2 Testing TCL 8.x and 9.x on unix |
| 59 | |
| 60 | From a checked-out copy of [the core Tcl tree][tcl-fossil] |
| 61 | |
| 62 | <ol type="1"> |
| 63 | <li value="3">`TCLVERSION=8.6` <br> |
| 64 | ↑ A version of your choice. This process has been tested with |
| 65 | values of 8.6, 9.0, and 9.1 (as of 2025-04-16). The out-of-life |
| 66 | version 8.5 fails some of `make devtest` for undetermined reasons. |
| 67 | <li>`TCLHOME=$HOME/tcl/$TCLVERSION` |
| 68 | <li>`TCLSOURCE=/path/to/tcl/checkout` |
| 69 | <li>`SQLITESOURCE=/path/to/sqlite/checkout` |
| 70 | <li>`rm -fr $TCLHOME` <br> |
| 71 | ↑ Ensure that no stale Tcl installation is laying around. |
| 72 | <li> `cd $TCLSOURCE` |
| 73 | <li> `fossil up core-8-6-branch` <br> |
| 74 | ↑ The branch corresponding to `$TCLVERSION`, e.g. |
| 75 | `core-9-0-branch` or `trunk`. |
| 76 | <li> `fossil clean -x` |
| 77 | <li> `cd unix` |
| 78 | <li> `./configure --prefix=$TCLHOME --disable-shared` <br> |
| 79 | ↑ The `--disable-shared` is to avoid the need to set `LD_LIBRARY_PATH` |
| 80 | when using this Tcl build. |
| 81 | <li> `make install` |
| 82 | <li> `cd $SQLITESOURCE` |
| 83 | <li> `fossil clean -x` |
| 84 | <li> `./configure --with-tcl=$TCLHOME --all` |
| 85 | <li> `make tclextension-install` <br> |
| 86 | ↑ Verify extension installed at |
| 87 | `$TCLHOME/lib/tcl${TCLVERSION}/sqlite<SQLITE_VERSION>`. |
| 88 | <li> `make tclextension-list` <br> |
| 89 | ↑ Verify TCL extension correctly installed. |
| 90 | <li> `make tclextension-verify` <br> |
| 91 | ↑ Verify that the correct version is installed. |
| 92 | <li> `$TCLHOME/bin/tclsh[89].[0-9] test/testrunner.tcl release --explain` <br> |
| 93 | ↑ Verify thousands of lines of output with no errors. Or |
| 94 | consider running "devtest" without --explain instead of "release". |
| 95 | </ol> |
| 96 | |
| 97 | ### 2.3 Cleanup |
| 98 | |
| 99 | <ol type="1"> |
| 100 | <li value="29"> `rm -rf $TCLHOME` |
| 101 | </ol> |
| 102 | |
| 103 | <a id="windows"></a> |
| 104 | ## 3.0 Testing On Windows |
| 105 | |
| 106 | See also the [](./compile-for-windows.md) document which provides another |
| 107 | perspective on how to compile SQLite on Windows. |
| 108 | |
| 109 | ### 3.1 Setup for Windows |
| 110 | |
| 111 | (These docs are not as up-to-date as the Unix docs, above.) |
| 112 | |
| 113 | <ol type="1"> |
| 114 | <li value="1"> |
| 115 | [Fossil][] installed. |
| 116 | <li> |
| 117 | Unix-like command-line tools installed. Example: |
| 118 | [unxutils](https://unxutils.sourceforge.net/) |
| 119 | <li> [Visual Studio](https://visualstudio.microsoft.com/vs/community/) |
| 120 | installed. VS2015 or later required. |
| 121 | <li> Check out source code and set environment variables. |
| 122 | <ol type="a"> |
| 123 | <li> **TCLSOURCE** → |
| 124 | The top-level directory of a Fossil check-out of the TCL source tree. |
| 125 | <li> **SQLITESOURCE** → |
| 126 | A Fossil check-out of the SQLite source tree. |
| 127 | <li> **TCLBUILD** → |
| 128 | A directory that does not exist at the start of the test and which |
| 129 | will be deleted at the end of the test, and that will contain the |
| 130 | test builds of the TCL libraries and the SQLite TCL Extensions. |
| 131 | <li> **ORIGINALPATH** → |
| 132 | The original value of %PATH%. In other words, set as follows: |
| 133 | `set ORIGINALPATH %PATH%` |
| 134 | </ol> |
| 135 | </ol> |
| 136 | |
| 137 | ### 3.2 Testing TCL 8.6 on Windows |
| 138 | |
| 139 | <ol type="1"> |
| 140 | <li value="5"> `mkdir %TCLBUILD%\tcl86` |
| 141 | <li> `cd %TCLSOURCE%\win` |
| 142 | <li> `fossil up core-8-6-16` <br> |
| 143 | ↑ Or some other version of Tcl8.6. |
| 144 | <li> `fossil clean -x` |
| 145 | <li> `set INSTALLDIR=%TCLBUILD%\tcl86` |
| 146 | <li> `nmake /f makefile.vc release` <br> |
| 147 | ⇅ You *must* invoke the "release" and "install" targets |
| 148 | using separate "nmake" commands or tclsh86t.exe won't be |
| 149 | installed. |
| 150 | <li> `nmake /f makefile.vc install` |
| 151 | <li> `cd %SQLITESOURCE%` |
| 152 | <li> `fossil clean -x` |
| 153 | <li> `set TCLDIR=%TCLBUILD%\tcl86` |
| 154 | <li> `set PATH=%TCLBUILD%\tcl86\bin;%ORIGINALPATH%` |
| 155 | <li> `set TCLSH_CMD=%TCLBUILD%\tcl86\bin\tclsh86t.exe` |
| 156 | <li> `nmake /f Makefile.msc tclextension-install` <br> |
| 157 | ↑ Verify extension installed at %TCLBUILD%\\tcl86\\lib\\tcl8.6\\sqlite3.* |
| 158 | <li> `nmake /f Makefile.msc tclextension-verify` |
| 159 | <li>`tclsh86t test/testrunner.tcl release --explain` <br> |
| 160 | ↑ Verify thousands of lines of output with no errors. Or |
| 161 | consider running "devtest" without --explain instead of "release". |
| 162 | </ol> |
| 163 | |
| 164 | ### 3.3 Testing TCL 9.0 on Windows |
| 165 | |
| 166 | <ol> |
| 167 | <li value="20"> `mkdir %TCLBUILD%\tcl90` |
| 168 | <li> `cd %TCLSOURCE%\win` |
| 169 | <li> `fossil up core-9-0-0` <br> |
| 170 | ↑ Or some other version of Tcl9 |
| 171 | <li> `fossil clean -x` |
| 172 | <li> `set INSTALLDIR=%TCLBUILD%\tcl90` |
| 173 | <li> `nmake /f makefile.vc release` <br> |
| 174 | ⇅ You *must* invoke the "release" and "install" targets |
| 175 | using separate "nmake" commands or tclsh90.exe won't be |
| 176 | installed. |
| 177 | <li> `nmake /f makefile.vc install` |
| 178 | <li> `cd %SQLITESOURCE%` |
| 179 | <li> `fossil clean -x` |
| 180 | <li> `set TCLDIR=%TCLBUILD%\tcl90` |
| 181 | <li> `set PATH=%TCLBUILD%\tcl90\bin;%ORIGINALPATH%` |
| 182 | <li> `set TCLSH_CMD=%TCLBUILD%\tcl90\bin\tclsh90.exe` |
| 183 | <li> `nmake /f Makefile.msc tclextension-install` <br> |
| 184 | ↑ Verify extension installed at %TCLBUILD%\\tcl90\\lib\\sqlite3.* |
| 185 | <li> `nmake /f Makefile.msc tclextension-verify` |
| 186 | <li> `tclsh90 test/testrunner.tcl release --explain` <br> |
| 187 | ↑ Verify thousands of lines of output with no errors. Or |
| 188 | consider running "devtest" without --explain instead of "release". |
| 189 | </ol> |
| 190 | |
| 191 | ### 3.4 Cleanup |
| 192 | |
| 193 | <ol type="1"> |
| 194 | <li value="35"> `rm -rf %TCLBUILD%` |
| 195 | </ol> |
| 196 | |
| 197 | ## 4.0 Testing the TEA(ish) Build (unix only) |
| 198 | |
| 199 | This part requires following the setup instructions for Unix systems, |
| 200 | at the top of this document. |
| 201 | |
| 202 | The former TEA, now TEA(ish), build of this extension uses the same |
| 203 | code as the builds described above but is provided in a form more |
| 204 | convenient for downstream Tcl users. |
| 205 | |
| 206 | It lives in `autoconf/tea` and, as part of the `autoconf` bundle, |
| 207 | _cannot be tested directly from the canonical tree_. Instead it has to |
| 208 | be packaged. |
| 209 | |
| 210 | ### 4.1 Teaish Setup |
| 211 | |
| 212 | Follow the same Tcl- and environment-related related setup described |
| 213 | in the first section of this document, up to and including the |
| 214 | installation of Tcl (unless, of course, it was already installed using |
| 215 | those same instructions). |
| 216 | |
| 217 | ### 4.2 Teaish Testing |
| 218 | |
| 219 | <ol> |
| 220 | <li>`cd $SQLITESOURCE` |
| 221 | <li>Run either `make snapshot-tarball` or `make amalgamation-tarball` |
| 222 | ↑ |
| 223 | Those steps will leave behind a temp dir called `mkpkg_tmp_dir`, |
| 224 | under which the extension is most readily reached. It can optionally |
| 225 | be extracted from the generated tarball, but that tarball was |
| 226 | generated from this dir, and reusing this dir is a time saver |
| 227 | during development. |
| 228 | <li> `cd mkpkg_tmp/tea` |
| 229 | <li> `./configure --with-tcl=$TCLHOME` |
| 230 | <li> `make test install` <br> |
| 231 | ↑ Should run to completion without any errors. |
| 232 | <li> `make uninstall` <br> |
| 233 | ↑ Will uninstall the extension. This _can_ be run |
| 234 | in the same invocation as the `install` target, but only |
| 235 | if the `-j#` make flag is _not_ used. If it is, the |
| 236 | install/uninstall steps will race and make a mess of things. |
| 237 | Parallel builds do not help in this build, anyway, as there's |
| 238 | only a single C file to compile. |
| 239 | </ol> |
| 240 | |
| 241 | When actively developing and testing the teaish build, which requires |
| 242 | going through the tarball generation, there's a caveat about the |
| 243 | `mkpkg_tmp_dir` dir: it will be deleted every time a tarball is |
| 244 | built, the shell console which is parked in that |
| 245 | directory for testing needs to add `cd $PWD &&` to the start of the |
| 246 | build commands, like: |
| 247 | |
| 248 | > |
| 249 | ``` |
| 250 | [user@host:.../mkpkg_tmp_dir/tea]$ \ |
| 251 | cd $PWD && ./configure CFLAGS=-O0 --with-tcl=$TCLHOME \ |
| 252 | && make test install uninstall |
| 253 | ``` |
| 254 | |
| 255 | ### 4.3 Teaish Cleanup |
| 256 | |
| 257 | |
| 258 | <ol type="1"> |
| 259 | <li> `rm -rf $TCLHOME` |
| 260 | <li> `cd $SQLITESOURCE; rm -fr mkpkg_tmp_dir; fossil clean -x` |
| 261 | </ol> |
| 262 | |
| 263 | [Fossil]: https://fossil-scm.org/home |
| 264 | [tcl-fossil]: https://core.tcl-lang.org/tcl |