This folder contains Bold's test suite. Delphi runs it with DUnitX, Free Pascal runs the same test units with FPCUnit; the main README has the current test count and coverage. How to write a test is in Unit Testing.
The Delphi test projects require two external frameworks that are not part
of this repository. If you just tried to build UnitTest.dproj and got
F2613 Unit 'DUnitX.Loggers.Console' not found
F2613 Unit 'Delphi.Mocks' not found
this README is for you. Nothing in Source/ needs these frameworks;
they are test-only dependencies.
| Dependency | Environment variable | Purpose |
|---|---|---|
| DUnitX | DUnitX |
Unit testing framework |
| Delphi-Mocks | DelphiMocks |
Mocking framework for interface testing |
| FastMM4 (optional) | FastMM4 |
Memory check check_memory.ps1 only; MPL 1.1 / LGPL 2.1, not distributed with Bold |
| DelphiCodeCoverage (optional) | - | Code coverage, run_coverage.ps1 only (see Code Coverage) |
The .dproj search paths reference them as $(DUnitX) and
$(DelphiMocks). Each variable must point to the framework's Source
subfolder. FastMM4 points to the FastMM4 folder itself, the one with
FastMM4.pas; nothing but check_memory.ps1 needs it (see
Memory leaks and freed memory).
cd UnitTest
.\setup-tests.ps1This clones both frameworks next to the repository and sets the two environment variables (user level). Restart the Delphi IDE afterwards - it reads environment variables at startup.
-
Get the frameworks, either with Git:
git clone https://github.com/VSoftTechnologies/DUnitX.git git clone https://github.com/VSoftTechnologies/Delphi-Mocks.gitor without Git — download and extract the ZIPs:
- https://github.com/VSoftTechnologies/DUnitX/archive/refs/heads/master.zip
- https://github.com/VSoftTechnologies/Delphi-Mocks/archive/refs/heads/master.zip
(A ZIP extracts to a folder named
DUnitX-master/Delphi-Mocks-master— rename or just point the variables at the actual folder.) -
Set the variables, either as Windows user environment variables or in the Delphi IDE under Tools > Options > IDE > Environment Variables. Each variable must point to the framework's
Sourcesubfolder:DUnitX=<path>\DUnitX\SourceDelphiMocks=<path>\Delphi-Mocks\Source
-
Restart the IDE — it reads environment variables at startup.
-
Open
UnitTest.groupprojand build.
In the IDE: open UnitTest.groupproj (contains the console runner
UnitTest.dproj and the GUI runner UnitTestGUI.dproj) and build.
Command line:
.\build.ps1 # console runner, Debug/Win64 .\build.ps1 -Platform Win32 # the 32-bit runner .\build.ps1 -GUI # GUI runner .\UnitTest.exe # run all tests
Run a specific fixture or test. The filter is UnitName.ClassName[.TestName]:
.\UnitTest.exe --run:Test.BoldUndoHandler.TTestBoldUndoHandler --consolemode:Verbose .\UnitTest.exe --exit:Pause # wait for a key before the console closes
The persistence tests run against the engine that UnitTest.ini selects in
[Database] Engine=: SQLite by default, in a temporary file per run.
SQLServer, Interbase, Firebird and PostgreSQL sections are provided.
The environment variable BOLD_TEST_ENGINE overrides the ini without editing
it:
$env:BOLD_TEST_ENGINE = 'SQLServer'; .\UnitTest.exe --run:Test.BoldBatchQueries
run_matrix.ps1 uses that variable to run the suite on each engine in turn:
the FireDAC build on SQLite, SQL Server and PostgreSQL, then the DebugUniDAC
build on the same engines when UniDAC is installed (on SQL Server only with a
UniDAC installation that has no SQLite provider). The PostgreSQL rows need the
server of [PostgreSQL] in the ini, and FireDAC needs a 64-bit libpq.dll,
which the script finds on the PATH or in the newest PostgreSQL installation.
A PostgreSQL row that cannot run is reported as skipped, not failed. The test
bases create the databases when the server does not have them. Logs go to
matrix_<adapter>_<engine>.log; the exit code is the number of failed runs.
.\run_matrix.ps1 # the full matrix .\run_matrix.ps1 -Engines SQLite # one engine .\run_matrix.ps1 -SkipBuild -Filter Test.BoldBatchQueries
Run the matrix after a change in Source\Persistence or Source\PMapper; the
SQLite run alone is the everyday check.
The Bold runtime (object space, OCL, handles, persistence, XML streaming) must
build without the VCL, for console and service applications, FMX and Free
Pascal (#117). examples\Compound\Invoicing\Console is that build,
with FrameworkType=None: the Bold core links no GUI framework, and a VCL
application links BoldEnvironmentVCL itself.
examples\Compound\Invoicing\FMX adds TBoldDataSet, the control packs it
builds on and LiveBindings, with FrameworkType=FMX and BOLD_NO_VCL (#117 step 9).
Tools\ModelEditor\FMX, the standalone model editor's FMX client (#128), adds
the UML model, the code generator and the data module it shares with the LCL
client. check_no_vcl.ps1 builds the three with a detailed map file and fails
when any links a Vcl.* unit, naming the units; with -Run it also runs the console's
101-check scenario. An FMX project knows no Vcl unit scope, so an unscoped VCL
import (Controls, Forms) outside BOLD_VCL already fails its build with F2613;
a scoped one (Vcl.Controls) builds and is caught in the map file.
The FMX projects take Stacker as their stack-trace provider (Tools/BoldStacker.targets, #130): the
script needs it in the environment variable STACKER or in a folder stacker next to the repository, or
STACKER=off to build without it.
Run it after a change under Source, and after saving dmInvoicing in the IDE
designer: its {%CLASSGROUP 'System.Classes.TPersistent'} keeps the designer
from adding BoldEnvironmentVCL to its uses clause.
.\check_no_vcl.ps1 # build the three Debug/Win64, check the map files .\check_no_vcl.ps1 -Run # ... and run the scenario against ..\Model\Invoicing.bld .\check_no_vcl.ps1 -Project FMX # only the Invoicing FMX client (Console, ModelEditor: the others)
For Delphi, BoldXMLStreaming uses MSXML on Windows and Delphi's own
Xml.xmldom with the OmniXML vendor on other platforms (#117); Free Pascal uses
fcl-xml. To run the suite on the OmniXML backend without a macOS or Linux
target, add BOLD_XMLDOM to the conditional defines of a UnitTest build. Every
XML round trip in the suite then goes through it, and Test.BoldXMLStreaming
tests the backend directly. The Windows-only units that use MSXML themselves
(SOAP, XMI, COM) are not part of UnitTest and need MSXML.
The console runner also builds for Linux64 (#117), with Delphi 12.3 or 13 and a Linux SDK imported through the SDK Manager. The command-line build needs only the imported SDK files; PAServer is needed to deploy and run from the IDE, not to build:
.\build.ps1 -Platform Linux64 # writes the ELF UnitTest (no extension) next to the script
A Linux64 build regenerates the tracked UnitTest.res without the Windows icon
and version information. build.ps1 puts the Windows one back afterwards; after
a Linux64 build in the IDE, revert UnitTest.res before committing.
Copy UnitTest and UnitTest.ini to a folder on the Linux machine and run it
there:
chmod +x UnitTest ./UnitTest --exit:Continue
FireDAC loads the unversioned libsqlite3.so, which most distributions ship
only in the development package (sudo apt install libsqlite3-dev on Ubuntu).
The results also go to dunitx-results.xml (NUnit format) in the current
folder.
The runner has one unit list for every platform. Test units whose subject is
Windows only (COM, WinInet, the Windows message loop of BoldThread, the VCL
control packs) are empty on other platforms, and so are the Delphi-Mocks
fixtures, because Delphi-Mocks does not compile for Linux64. The leak checks
read a counting wrapper around libc's malloc that BoldTestFramework installs
on Linux.
Most of the suite also builds with Free Pascal through FPC/build.sh. The
FPCUnit runner is FPC/UnitTestFPC.lpr, and the test units are shared with
Delphi through Code/Common/BoldTestFramework.pas (GitHub issue #117).
| Dependency | Environment variable | Purpose |
|---|---|---|
| Free Pascal 3.2.2 or later | - | Compiler |
| Zeos 8.0 | ZEOS |
Database access: under Free Pascal Bold uses its Zeos adapter, under Delphi FireDAC |
Zeos is mandatory for the Free Pascal build. build.sh stops with an
error when ZEOS is not set; there is no stub, unlike UniDAC on Delphi. Zeos
is free (LGPL with a static linking exception), so every Free Pascal run
includes the database tests. ZEOS points to the Zeos root folder, the one
that contains src/. The SQLite tests also need the SQLite library
(libsqlite3.so.0, package libsqlite3-0 on Debian and Ubuntu).
# zeosdbo-8.0.0-stable.zip from # https://sourceforge.net/projects/zeoslib/files/Zeos%20Database%20Objects/zeosdbo-8.0.0-stable/ unzip zeosdbo-8.0.0-stable.zip -d ~/components/zeosdbo-8.0.0 export ZEOS=~/components/zeosdbo-8.0.0 sh FPC/build.sh # build, then run all tests sh FPC/build.sh --suite=TTestBoldSystem --format=plain # one fixture
The same commands run in Git Bash on Windows. There build.sh finds Free
Pascal in the Lazarus installation (C:\lazarus, or the folder in
LAZARUS_DIR), ZEOS may be written as /c/... or C:/..., and Zeos loads
sqlite3.dll (64-bit) from the PATH. The Windows handling is in
Tools/fpc-env.sh, which every Free Pascal and Lazarus build.sh reads; on
Linux it does nothing.
build.sh compiles Zeos first, in mode Delphi as its Lazarus packages do,
into FPC/bin/zeos, and then the tests in mode DelphiUnicode against those
units. Output goes to FPC/bin; the exit code is 0 when every test passed.
The database tests run on SQLite in memory by default. The engine is chosen
as on Delphi: the environment variable BOLD_TEST_ENGINE, otherwise
[Database] Engine in UnitTest.ini. Through Zeos, SQLite and PostgreSQL are
set up (Code/Persistence/Zeos/BoldTestZeos.pas). PostgreSQL uses the server
of [PostgreSQL] in UnitTest.ini and needs the client library (libpq.so.5,
package libpq5 on Debian and Ubuntu; libpq.dll on the PATH on Windows).
BOLD_TEST_PG_SERVER and BOLD_TEST_PG_PORT override the host and the port
of the ini, for a server that listens elsewhere. The test databases are created
when the server does not have them:
BOLD_TEST_ENGINE=PostgreSQL BOLD_TEST_PG_PORT=5434 sh FPC/build.sh
GitHub Actions runs the same build on every push and pull request to
develop (.github/workflows/fpc-tests.yml, in an Ubuntu 26.04 container, FPC
3.2.2, the same as the Linux development machine): it
downloads the Zeos 8.0.0 release above, checks its SHA-256 and runs
FPC/build.sh, so a change made in Delphi cannot break the Free Pascal build
unnoticed. It runs the suite once more on PostgreSQL 18 through Zeos, on a
server GitHub starts for the job (a service container). A second workflow (.github/workflows/fpc-tests-windows.yml) runs
the same scripts in Git Bash on 64-bit Windows, with Lazarus 4.8 and its Free
Pascal 3.2.2: Linux has UTF-8 as its system code page, which hides text lost in
a Windows code page. The Delphi suite still runs on Windows only.
Both suites can run with freed memory overwritten, so that a use of freed memory fails instead of passing by luck, and with every block still allocated at exit reported together with the line that allocated it.
$env:FastMM4 = 'C:\path\to\FastMM4' # a clone of https://github.com/pleriche/FastMM4 .\check_memory.ps1 # build DebugFastMM4/Win64, run the suite, check the log .\check_memory.ps1 -Run Test.BoldXMLStreaming. # a spot check: only the tests the filter names .\check_memory.ps1 -FreedBlocks # check writes to freed blocks instead
check_memory.ps1 builds UnitTest.dproj in the configuration DebugFastMM4
(exe, map file and event log in FastMM4\) and runs the suite under FastMM4 in
FullDebugMode. FastMM4 is the first unit of UnitTest.dpr under
{$IFDEF BOLD_FASTMM4}, which only that configuration defines, so normal builds
do not need FastMM4. An interface released after its object was freed, or a
virtual call on a freed object, is caught and logged with its stack trace, and
at exit FastMM4 logs every block still allocated with the stack trace of its
allocation, with unit and line from the detailed map file. The script prints
those entries and fails on any leak, any memory error and any failed test, and
when no test ran (a filter that matches nothing). The
full suite takes about a minute and a half. There is no Delphi CI, so run it in
every cycle, like check_no_vcl.ps1.
FastMM4 is optional and not distributed with Bold (MPL 1.1 / LGPL 2.1).
FastMM4 points to the folder with FastMM4.pas, FastMM4Options.inc and
FullDebugMode DLL\Precompiled; the script copies the FullDebugMode DLL for the
platform next to the exe. It only reads that folder: it copies the units to
FastMM4\src and appends its settings to the copied FastMM4Options.inc
(FullDebugMode, everything logged to the event log, no message boxes), because
the original defines RequireDebuggerPresenceForLeakReporting, which a
command-line define cannot undo. One build checks either interfaces of freed
objects (the default) or writes to freed blocks (-FreedBlocks): FastMM4's
CatchUseOfFreedInterfaces turns the freed-block check off.
BOLD_HEAPTRC=1 sh FPC/build.sh # the suite under heaptrcBOLD_HEAPTRC=1 builds the runner with Free Pascal's heaptrc (-gh) and line
info (-gl) into FPC/bin-heaptrc and runs it. heaptrc fills freed memory with
$F0, so a use of freed memory raises instead of passing by luck, and at exit it
lists every block still allocated with the line that allocated it. build.sh
then prints that report and fails. CI runs the suite both ways.
There is no per-test leak check: a cache created in one test and freed in a
later one makes per-test counts noisy. To pin a leak in a code path, a test
counts the heap around a loop, BoldTestAllocatedBytes under Free Pascal or
BoldTestAllocatedBlocks under Delphi, as TestMalformedXMLDoesNotLeak and
TestFaultDoesNotLeak do. The leak column of the Delphi runner always shows 0:
its default DUnitX leak monitor measures nothing.
.\run_coverage.ps1 # build, run the suite under coverage, open the report .\run_coverage.ps1 -SkipBuild # reuse the existing UnitTest.exe and map file .\run_coverage.ps1 -OpenReport:$false # do not open the report .\run_coverage.ps1 -Upload # also upload to Codecov.io (needs CODECOV_TOKEN)
The script builds UnitTest.exe with a detailed map file, runs the whole
suite under
DelphiCodeCoverage
and writes the HTML report to coverage_report/; open
CodeCoverage_summary.html. coverage_units.lst names the units that are
measured, and coverage_source_paths.lst the folders their source is in: add a
new Source unit or folder there, or it shows no coverage.
The script still has the paths of the maintainer's machine at its top:
DelphiCodeCoverage in C:\Attracs\DelphiCodeCoverage\build\Win32\, the
build script C:\Attracs\DelphiStandards\DelphiBuildDPROJ.ps1 and the
repository in C:\Attracs\BoldForDelphi. Change them to run it elsewhere.
Codecov Setup describes the upload.