![]() |
Specs
Beautiful C++ Test Framework
|
Specs
is very easy to install if you're using xmake
or vcpkg
.
Specs
has quite a few library dependencies which are available asxmake
andvcpkg
packages.Due to the dependencies, I do not recommend installing
Specs
manually.
Specs
requires C++17
or higher.
Using C++20
works out-of-the-box without any additional dependencies.
If you are using C++17
, you must add fmt
as a dependency for string formatting.
Why not C++14?
Specs
usesstring_view
andstructured bindings
which are C++17 features.
The following is an xmake.lua
example which sets up a Specs
test suite:
That's it!
If you want to verify that it works, create a Test.cpp
with the following contents:
Then build and run your test target.
You should see the following output:
By default, Specs
will catch any std::exception
(or literal string) thrown and display it as a test failure message.
If you want to integrate with an assertion library, we provide integrations for the snowhouse
and libassert
assertion libraries.
If you want to install the the Snowhouse
assertion library with Specs
support:
If you want to verify that it works, create a Test.cpp
with the following contents:
Then build and run your test target.
You should see the following output:
If you want to install the the libassert
assertion library with Specs
support:
Note: at the time of writing, I was having trouble getting
libassert
to build from the officialxmake
registry.If you run into problems, feel free to use the latest version of
libassert
from theMrowrLib
registry (using thelibassert_latest
package):add_requires("libassert_latest", { configs = { lowercase = true } })-- # ...target("MyProject.Tests")-- # ...-- # Add the libassert and specs_libassert packages to your targetadd_packages("libassert_latest", "specs_libassert")
If you want to verify that it works, create a Test.cpp
with the following contents:
Then run xmake run MyProject.Tests
and you should see the following output:
Release Mode
Note:
libassert
'sassert
macro does NOT throw exceptions inrelease
mode.This means that
Specs
will not be able to catch the assertion failure and report it as a test failure.To get around this:
- you can use the
VERIFY
macro instead ofassert
(which throws exceptions inrelease
mode)- (recommended) use the
assert_that
macro provided bySpecs
(which is an alias forVERIFY
) ```
In this example, we use a
vcpkg.json
file to manage ourvcpkg
dependencies.See vcpkg Manifest Mode for more information.
To install Specs
using vcpkg
, you will need to:
specs
as a dependency in your vcpkg.json
MrowrLib/Packages
registry to your vcpkg-configuration.json
specs::specs
in your test target in your CMakelists.txt
Add specs
as a dependency in your vcpkg.json
:
Add the MrowrLib/Packages
registry to your vcpkg-configuration.json
, including a full list of all Specs
dependencies from the registry:
Note: you will want to update the
baseline
values invcpkg-configuration.json
for:
- the
default-registry
registry: this should be the latest commit SHA ofmicrosoft/vcpkg
- the
MrowrLib/Packages
registry: this should be the latest commit SHA ofMrowrLib/Packages
If you want to verify that it works, create a Test.cpp
with the following contents:
Then run xmake run MyProject.Tests
and you should see the following output:
By default, Specs
will catch any std::exception
(or literal string) thrown and display it as a test failure message.
If you want to integrate with an assertion library, we provide integrations for the snowhouse
and libassert
assertion libraries.
If you want to install the the Snowhouse
assertion library with Specs
support:
specs-snowhouse
to your vcpkg.json
specs::specs_snowhouse
in your test target in your CMakelists.txt
Here we add snowhouse
from the official vcpkg
registry, and specs-snowhouse
from the MrowrLib/Packages
registry:
If you want to verify that it works, create a Test.cpp
with the following contents:
Then build and run your test target.
You should see the following output:
At the time of writing, I can't get the vcpkg
version of libassert
to build.
I couldn't get the instructions on the libassert
GitHub page to work either.
For that reason, for now... you're on your own.
Here is the libassert
README: https://github.com/jeremy-rifkin/libassert
Here is a recent bug report for the vcpkg
: https://github.com/jeremy-rifkin/libassert/issues/75
Don't worry, I really like the elegance of
libassert
and I hope to get this working!