diff --git a/Alltest b/Alltest deleted file mode 100755 index c7d1238..0000000 --- a/Alltest +++ /dev/null @@ -1,236 +0,0 @@ -#!/usr/bin/bash - -# ShellChecked on every push - Always ShellCheck your scripts! - -# First some configs -# Assumes it's running from the root dir. of the repository -if [ -z "${FOAM_LIBBIN}" ]; then - echo "Please source an OpenFOAM version. Aborting..." - echo "USAGE: ./Alltest [--no-serial|--no-parallel] [--report] [--html]" - exit 1 -fi - -# If tests folder is supplied through an env. var. -# do the symlinking -if [ -n "${FOAM_FOAMUT_TESTS}" ]; then - find "${FOAM_FOAMUT_TESTS}" -type d -name "Make" | while read -r make_dir; do - parent_dir=$(basename "$(dirname "$make_dir")") - target_dir="$PWD/tests/$parent_dir" - ln -f -s "$(dirname "$make_dir")" "$target_dir" - echo "picked up $parent_dir tests" - done -fi - -doSerial=true -doParallel=true -doReport=false -for i in "$@"; do - case $i in - --no-serial) - doSerial=false - ;; - --no-parallel) - doParallel=false - ;; - --report) - doReport=true - ;; - *) - ;; - esac -done - -set -e -root=$PWD -export FOAM_FOAMUT="$root" -foamV=$(echo "${WM_PROJECT}$(test ! -z "${WM_FORK}" && echo '-'"${WM_FORK}")-${WM_PROJECT_VERSION}") -args_array=("$@") - -# If there is no lib${libName}.so, create a dummy one -dummyLibChecks="Pstream dynamicFvMesh" -for dummy in $dummyLibChecks; do - if [ ! -f "${FOAM_LIBBIN}/lib${dummy}.so" ] && - [ ! -f "${FOAM_USER_LIBBIN}/lib${dummy}.so" ] && - [ ! -f "${FOAM_LIBBIN}/${FOAM_MPI}/lib${dummy}.so" ]; then - echo '!' > "${FOAM_USER_LIBBIN}/lib${dummy}.so" - fi -done - -# libraries to test -libs=$(find -L tests/ -maxdepth 1 -mindepth 1 -type d) -libs_array=($libs) -# where to run OpenFOAM cases -caseRun=/tmp/foamUtCases -mkdir -p "$caseRun" -# a timeout to prevent hanging processes (be CI friendly) -timeOut="${CATCH_TIMEOUT:-60}" - -serialTests() { - local fargs=("$@") - local params=() - for ((i = 4; i <= $#; i++)); do - arg="${fargs[i]}" - case "$arg" in - --no-parallel|--no-serial|--report) - ;; - *) - params+=("$arg") - ;; - esac - done - for ((i = 0; i < ${#libs_array[@]}; i++)); do - lib="${libs_array[i]}" - printf "\n\nRunning tests for lib %s, on %s case in serial...\n" "$lib" "${2}" >&2 - libName=$(basename "$lib") - report="" - case $doReport in - (true) report="-s -r json::out=${root}/reports/${libName}_${2}_serial.json -d yes" - echo "Report: ${root}/reports/${libName}_${2}_serial.json" >&2 - ;; - esac - timeout "$timeOut" "$root"/"$lib"/testDriver --allow-running-no-tests \ - -n "$(basename "$lib")" $report "[serial][${2}]" "${params[@]}" \ - --- -case "${3}" - locErr=$? - err=$((err+locErr)) - # separator in case json reporter is used - for element in "${params[@]}"; do - if [ "$element" == "json" ]; then - if ((i != ${#libs_array[@]})); then - printf "," - fi - fi - done - done -} - -parallelTests(){ - if ! test -f "${3}/system/decomposeParDict" ; then - rm -rf "${3}/processor*" - echo "decomposeParDict not found, not running parallel tests on this case..." >&2 - return 0 - fi - local fargs=("$@") - local params=() - for ((i = 4; i <= $#; i++)); do - arg="${fargs[i]}" - case "$arg" in - --no-parallel|--no-serial|--report) - ;; - *) - params+=("$arg") - ;; - esac - done - nProcs=$(grep -oP "numberOfSubdomains\s+\K\d+" "${3}"/system/decomposeParDict) - decomposePar -force -case "${3}" > "${3}/log.decomposePar" - err=$((err + $?)) - # run the case in parallel mode - report="" - case $doReport in - (true) report="-s -r json -d yes";; - esac - for ((i = 0; i < ${#libs_array[@]}; i++)); do - lib="${libs_array[i]}" - printf "\n\nRunning tests for lib %s, on %s case in parallel...\n" "$lib" "${2}" >&2 - libName=$(basename "$lib") - logdir="reports/${libName}_${2}_parallel" - logparams="" - direct="" - case $doReport in - (true) logparams="-output-filename $logdir" - direct="> /dev/null" - echo "Parallel Reports (${nProcs}): ${logdir}" >&2 - esac - timeout "$timeOut" mpirun $logparams -np "$nProcs" \ - "$root"/"$lib"/testDriver \ - --allow-running-no-tests \ - -n "$(basename "$lib")" $report \ - --rng-seed time "[parallel][${2}]" ${params[@]} --- -parallel -case "${3}" $direct - set +x - # separator in case json reporter is used - for element in "${params[@]}"; do - if [ "$element" == "json" ]; then - if ((i != ${#libs_array[@]} - 1)); then - printf "," - fi - fi - done - err=$((err + lerr)) - done -} - -# Compile catch -echo "Compiling Catch2 v3..." >&2 -if [ ! -f "$FOAM_USER_LIBBIN/catch2/lib/libCatch2.a" ]; then - cd catch2 - mkdir -p build - cd build - cmake -DCMAKE_INSTALL_PREFIX="$FOAM_USER_LIBBIN"/catch2 .. > log.cmake 2>&1 - make -j"$(nproc)" > log.makeBuild 2>&1 - make install > log.makeInstall 2>&1 - cd - > /dev/null - rm -rf build - cd .. -fi - -# 1st: compile tests -for lib in $libs; do - cd "$lib" - echo "Compiling $lib test driver..." >&2 - wmakeLnInclude . # Just in case the tested libs are header only - if ! wmake > log.wmake 2>&1; then - echo "Errors compiling $lib test driver, see $PWD/log.wmake for more information" - exit 1 - else - echo "Test driver for $lib has been compiled." >&2 - fi - cd - > /dev/null -done - -# go back to the root of the repository -cd "$root" - -# get setup to run tests -mapfile -t cases_array < <(find -L cases/ -maxdepth 1 -mindepth 1 -type d) -if [ ${#cases_array[@]} -eq 0 ]; then - echo "No cases found to run tests" - exit 1 -fi -mkdir -p "$root"/reports - -# run the tests, but do not exit until attempting everything -set +e -err=0 -for ((k = 0; k < ${#cases_array[@]}; k++)); do - ofCase="${cases_array[k]}" - caseName=$(basename "$ofCase") - casePath=$caseRun/$caseName - cp -rL "$ofCase" "$casePath" - case $doSerial in - (true) serialTests "$err" "$caseName" "$casePath" "$libs" "$@";; - esac - case $doParallel in - (true) parallelTests "$err" "$caseName" "$casePath" "$libs" "$@";; - esac - # separator in case json reporter is used - for element in "${args_array[@]}"; do - if [ "$element" == "json" ]; then - if ((k != ${#cases_array[@]} - 1)); then - printf "," - fi - fi - done - rm -rf "$casePath" -done - -# Cleanup -for dummy in $dummyLibChecks; do - if [ -f "${FOAM_USER_LIBBIN}/lib${dummy}.so" ] && - tr '\n' ' ' < "${FOAM_USER_LIBBIN}/lib${dummy}.so" | grep -q '^! $'; then - rm -rf "${FOAM_USER_LIBBIN}/lib${dummy}.so" - fi -done -rm -rf "$caseRun" - -exit $err diff --git a/Alltest b/Alltest new file mode 120000 index 0000000..9434592 --- /dev/null +++ b/Alltest @@ -0,0 +1 @@ +foamut \ No newline at end of file diff --git a/README.md b/README.md index d3032f4..70027e7 100644 --- a/README.md +++ b/README.md @@ -3,12 +3,42 @@ > This offering is not approved or endorsed by OpenCFD Limited, > the producer of the OpenFOAM software and owner of the OPENFOAM® and OpenCFD® trade marks. +> [!IMPORTANT] +> There have been breaking changes on the CLI interface from **v2.0.0**: +> - `foamut` is now the main command (built with [bashly](https://bashly.dannyb.co/)) +> - `Alltest` remains available as a symlink for backward compatibility +> - **New default behavior**: Serial tests only (use `--parallel` for parallel-only execution) +> - **New features**: +> - `--standalone`: Run tests without OpenFOAM cases (mode-agnostic and serial tests) +> - `--test-driver `: Use custom testDriver.C source file +> - `--test-prefix `: Prefix test execution with debuggers/profilers (e.g., `gdb --args`, `valgrind`) +> - `--report`: Generate JSON test reports in `reports/` directory +> - `--force-timeout`: Keep timeout even when using `--test-prefix` +> - All Catch2 arguments can be passed directly (no special separator needed) +> +> If you need the old behavior, use tag **v1.0.0** + This is a unit/integration testing framework to help test-proof new OpenFOAM code (might be too late for the OpenFOAM library itself). This repository will always work with the latest versions of the main three OpenFOAM forks: [ESI OpenCFD's](https://openfoam.com), [Foundation version](https://openfoam.org) and [Foam-Extend](https://sourceforge.net/projects/foam-extend/files/). + + +* [A quick demo](#a-quick-demo) +* [How to use this repo](#how-to-use-this-repo) +* [Usage](#usage) +* [Migration from v1.0.0](#migration-from-v100) + * [Command Changes](#command-changes) + * [Behavior Changes](#behavior-changes) + * [New Capabilities](#new-capabilities) + * [CI/Automation](#ciautomation) +* [Documentation](#documentation) +* [Contributing](#contributing) + + + If you intend to write cross-forks code, this can help you maintain your sanity. You can just keep branches for each fork on your code's repository and invoke CI on them with the help of this testing framework. @@ -19,27 +49,107 @@ help of this testing framework. ## How to use this repo -The [Alltest](Alltest) script loops through the [OpenFOAM cases](cases) and runs corresponding -test cases (for directories it finds under [tests](tests) that contain a `Make` folder) -- both in serial and in parallel. - -You can use this to your advantage as you don't need to include this repo into your code base: - -1. In your library's repo, write tests the way you like; - ship them with their own `Make` directory to compile the test driver (see [example tests](tests/exampleTests)) -1. Set the `FOAM_FOAMUT` environment variable to your local clone of `foamUT` repository -1. In your CI workflows, checkout this repository, set `FOAM_FOAMUT` to its path, and either: - - symlink your tests somewhere under `tests` - ```bash - ln -s /path/to/your/tests/myLibTests tests/myLibTests - ``` - - or set `FOAM_FOAMUT_TESTS` to your `tests` folder - ```bash - export FOAM_FOAMUT_TESTS=/path/to/your/tests - ``` -1. Do the same for your OpenFOAM cases if you have any (only a simple cavity case is provided by default). - Put these under `cases`. -1. Run `./Alltest` to compile and run your tests on your cases. +The `foamut` command orchestrates the entire test pipeline: +1. Compiles [Catch2](https://github.com/catchorg/Catch2) v3 (if needed) +2. Compiles test drivers for each test library under [tests](tests) +3. Runs tests on [OpenFOAM cases](cases) in serial (default) or parallel (`--parallel`) +4. Supports standalone mode (`--standalone`) for tests that don't require OpenFOAM cases + +You can use this framework without including it in your codebase: + +1. **Write your tests** following the [Catch2 v3](https://github.com/catchorg/Catch2) framework + - Ship tests with their own `Make` directory (see [example tests](tests/exampleTests)) + - Tag tests appropriately: `[serial]`, `[parallel]`, and case-specific tags like `[cavity]` + +2. **Setup foamUT** in your environment: + ```bash + git clone https://github.com/FoamScience/foamUT.git + export FOAM_FOAMUT=/path/to/foamUT + ``` + +3. **Link your tests** using one of these methods: + - **Symlink** your tests under `tests/`: + ```bash + ln -s /path/to/your/tests/myLibTests $FOAM_FOAMUT/tests/myLibTests + ``` + - **Environment variable** (recommended for CI): + ```bash + export FOAM_FOAMUT_TESTS=/path/to/your/tests + ``` + +4. **Provide OpenFOAM cases** (optional, skip if using `--standalone`, or + if the default cavity case is enough): + - Symlink or copy your cases to `cases/` + - Cases must include `system/controlDict` (and `system/decomposeParDict` for parallel) + +5. **Run tests**: + ```bash + # Source OpenFOAM environment first + source /path/to/OpenFOAM/etc/bashrc + + # Run serial tests (default) + ./foamut + + # Run parallel tests only + ./foamut --parallel + + # Run standalone tests (no OpenFOAM cases needed) + ./foamut --standalone + + # Debug a specific test + ./foamut --test-prefix "gdb --args" "[mytest]" + + # Generate JSON reports + ./foamut --report + ``` + +## Usage + +Run `./foamut --help` to see all available options. `foamut -- -h` to see all +Catch2 options. + +## Migration from v1.0.0 + +If you're upgrading from v1.0.0, here are the key changes: + +### Command Changes +| v1.0.0 | v2.0.0 | Notes | +|--------|--------|-------| +| `./Alltest` | `./foamut` | `Alltest` still works (symlink) | +| `./Alltest` (both modes) | `./foamut` (serial only) | Use `--parallel` for parallel tests | +| N/A | `./foamut --standalone` | New: Run tests without cases | + +### Behavior Changes +- **Default**: v1.0.0 ran both serial and parallel tests; v2.0.0 runs **serial only** by default +- **Parallel mode**: Use `--parallel` flag explicitly to run parallel tests +- **Catch2 args**: No longer need special handling, pass directly (e.g., `./foamut "[mytag]"`) + +### New Capabilities +```bash +# Debug failing tests +./foamut --test-prefix "gdb --args" "[failing-test]" + +# Profile test performance +./foamut --test-prefix "valgrind --tool=callgrind" + +# Use custom test driver +./foamut --test-driver /path/to/myTestDriver.C + +# Run unit tests without OpenFOAM cases +./foamut --standalone +``` + +### CI/Automation +If you have CI pipelines using v1.0.0: +```bash +# Old way (v1.0.0) +./Alltest + +# New way (v2.0.0) - for same behavior, run both: +./foamut # Serial tests +./foamut --parallel # Parallel tests +./Alltest # This is just a symlink for ./foamut +``` ## Documentation diff --git a/catch2/.bazelrc b/catch2/.bazelrc index 6084470..b10a64f 100644 --- a/catch2/.bazelrc +++ b/catch2/.bazelrc @@ -1,10 +1,8 @@ -# Enable Bzlmod for every Bazel command -common --enable_bzlmod - build --enable_platform_specific_config build:gcc9 --cxxopt=-std=c++2a build:gcc11 --cxxopt=-std=c++2a +build:gcc13 --cxxopt=-std=c++2a build:clang13 --cxxopt=-std=c++17 build:vs2019 --cxxopt=/std:c++17 build:vs2022 --cxxopt=/std:c++17 diff --git a/catch2/.clang-tidy b/catch2/.clang-tidy index 3488457..fd18173 100644 --- a/catch2/.clang-tidy +++ b/catch2/.clang-tidy @@ -78,5 +78,5 @@ WarningsAsErrors: >- readability-duplicate-include, HeaderFilterRegex: '.*\.(c|cxx|cpp)$' FormatStyle: none -CheckOptions: {} +CheckOptions: [] ... diff --git a/catch2/.conan/test_package/CMakeLists.txt b/catch2/.conan/test_package/CMakeLists.txt index f067457..04d638a 100644 --- a/catch2/.conan/test_package/CMakeLists.txt +++ b/catch2/.conan/test_package/CMakeLists.txt @@ -1,8 +1,7 @@ cmake_minimum_required(VERSION 3.16) -project(PackageTest CXX) +project(PackageTest LANGUAGES CXX) find_package(Catch2 CONFIG REQUIRED) add_executable(test_package test_package.cpp) target_link_libraries(test_package Catch2::Catch2WithMain) -target_compile_features(test_package PRIVATE cxx_std_14) diff --git a/catch2/.github/workflows/linux-bazel-builds.yml b/catch2/.github/workflows/linux-bazel-builds.yml index dc826ac..92a1c5b 100644 --- a/catch2/.github/workflows/linux-bazel-builds.yml +++ b/catch2/.github/workflows/linux-bazel-builds.yml @@ -1,4 +1,4 @@ -name: Bazel build +name: Linux Builds (Bazel) on: [push, pull_request] @@ -7,18 +7,18 @@ jobs: name: Linux Ubuntu 22.04 Bazel build runs-on: ubuntu-22.04 strategy: + fail-fast: false matrix: compilation_mode: [fastbuild, dbg, opt] steps: - uses: actions/checkout@v4 - - name: Mount bazel cache + - name: Mount Bazel cache uses: actions/cache@v3 with: path: "/home/runner/.cache/bazel" key: bazel-ubuntu22-gcc11 - - name: Build Catch2 - run: | - bazelisk build --compilation_mode=${{matrix.compilation_mode}} //... + - name: Build + run: bazelisk build --compilation_mode=${{matrix.compilation_mode}} //... diff --git a/catch2/.github/workflows/linux-meson-builds.yml b/catch2/.github/workflows/linux-meson-builds.yml index 4a6cfd5..e48dea9 100644 --- a/catch2/.github/workflows/linux-meson-builds.yml +++ b/catch2/.github/workflows/linux-meson-builds.yml @@ -1,4 +1,4 @@ -name: Linux builds (meson) +name: Linux Builds (Meson) on: [push, pull_request] @@ -7,6 +7,7 @@ jobs: name: meson ${{matrix.cxx}}, C++${{matrix.std}}, ${{matrix.build_type}} runs-on: ubuntu-22.04 strategy: + fail-fast: false matrix: cxx: - g++-11 @@ -25,7 +26,7 @@ jobs: sudo apt-get update sudo apt-get install -y meson ninja-build ${{matrix.other_pkgs}} - - name: Configure build + - name: Configure env: CXX: ${{matrix.cxx}} CXXFLAGS: -std=c++${{matrix.std}} ${{matrix.cxxflags}} @@ -34,11 +35,10 @@ jobs: run: | meson -Dbuildtype=${{matrix.build_type}} ${{runner.workspace}}/meson-build - - name: Build tests + lib + - name: Build working-directory: ${{runner.workspace}}/meson-build run: ninja - - name: Run tests + - name: Test working-directory: ${{runner.workspace}}/meson-build - run: | - meson test --verbose + run: meson test --verbose diff --git a/catch2/.github/workflows/linux-other-builds.yml b/catch2/.github/workflows/linux-other-builds.yml index 6993c81..6095f24 100644 --- a/catch2/.github/workflows/linux-other-builds.yml +++ b/catch2/.github/workflows/linux-other-builds.yml @@ -1,72 +1,73 @@ # The builds in this file are more complex (e.g. they need custom CMake # configuration) and thus are unsuitable to the simple build matrix # approach used in simple-builds -name: Linux builds (complex) +name: Linux Builds (Complex) on: [push, pull_request] jobs: build: name: ${{matrix.build_description}}, ${{matrix.cxx}}, C++${{matrix.std}} ${{matrix.build_type}} - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 strategy: + fail-fast: false matrix: # We add builds one by one in this case, because there are no # dimensions that are shared across the builds include: # Single surrogate header build - - cxx: clang++-10 + - cxx: clang++-14 build_description: Surrogates build build_type: Debug std: 14 - other_pkgs: clang-10 + other_pkgs: clang-14 cmake_configurations: -DCATCH_BUILD_SURROGATES=ON - # Extras and examples with gcc-7 - - cxx: g++-7 + # Extras and examples with gcc-11 + - cxx: g++-11 build_description: Extras + Examples build_type: Debug std: 14 - other_pkgs: g++-7 + other_pkgs: g++-11 cmake_configurations: -DCATCH_BUILD_EXTRA_TESTS=ON -DCATCH_BUILD_EXAMPLES=ON -DCATCH_ENABLE_CMAKE_HELPER_TESTS=ON - - cxx: g++-7 + - cxx: g++-11 build_description: Extras + Examples build_type: Release std: 14 - other_pkgs: g++-7 + other_pkgs: g++-11 cmake_configurations: -DCATCH_BUILD_EXTRA_TESTS=ON -DCATCH_BUILD_EXAMPLES=ON -DCATCH_ENABLE_CMAKE_HELPER_TESTS=ON - # Extras and examples with Clang-10 - - cxx: clang++-10 + # Extras and examples with Clang-14 + - cxx: clang++-14 build_description: Extras + Examples build_type: Debug std: 17 - other_pkgs: clang-10 + other_pkgs: clang-14 cmake_configurations: -DCATCH_BUILD_EXTRA_TESTS=ON -DCATCH_BUILD_EXAMPLES=ON -DCATCH_ENABLE_CMAKE_HELPER_TESTS=ON - - cxx: clang++-10 + - cxx: clang++-14 build_description: Extras + Examples build_type: Release std: 17 - other_pkgs: clang-10 + other_pkgs: clang-14 cmake_configurations: -DCATCH_BUILD_EXTRA_TESTS=ON -DCATCH_BUILD_EXAMPLES=ON -DCATCH_ENABLE_CMAKE_HELPER_TESTS=ON - # Configure tests with Clang-10 - - cxx: clang++-10 + # Configure tests with Clang-14 + - cxx: clang++-14 build_description: CMake configuration tests build_type: Debug std: 14 - other_pkgs: clang-10 + other_pkgs: clang-14 cmake_configurations: -DCATCH_ENABLE_CONFIGURE_TESTS=ON - # Valgrind test Clang-10 - - cxx: clang++-10 - build_description: Valgrind tests - build_type: Debug - std: 14 - other_pkgs: clang-10 valgrind - cmake_configurations: -DMEMORYCHECK_COMMAND=`which valgrind` -DMEMORYCHECK_COMMAND_OPTIONS="-q --track-origins=yes --leak-check=full --num-callers=50 --show-leak-kinds=definite --error-exitcode=1" - other_ctest_args: -T memcheck -LE uses-python + # Valgrind test Clang-14 + # - cxx: clang++-14 + # build_description: Valgrind tests + # build_type: Debug + # std: 14 + # other_pkgs: clang-14 valgrind + # cmake_configurations: -DMEMORYCHECK_COMMAND=`which valgrind` -DMEMORYCHECK_COMMAND_OPTIONS="-q --track-origins=yes --leak-check=full --num-callers=50 --show-leak-kinds=definite --error-exitcode=1" + # other_ctest_args: -T memcheck -LE uses-python steps: @@ -78,77 +79,47 @@ jobs: sudo apt-get install -y ninja-build ${{matrix.other_pkgs}} - name: Configure build - working-directory: ${{runner.workspace}} - env: - CXX: ${{matrix.cxx}} - CXXFLAGS: ${{matrix.cxxflags}} - # Note: $GITHUB_WORKSPACE is distinct from ${{runner.workspace}}. - # This is important run: | - cmake -Bbuild -H$GITHUB_WORKSPACE \ + cmake --preset basic-tests -GNinja \ -DCMAKE_BUILD_TYPE=${{matrix.build_type}} \ + -DCMAKE_CXX_COMPILER=${{matrix.cxx}} \ -DCMAKE_CXX_STANDARD=${{matrix.std}} \ - -DCMAKE_CXX_STANDARD_REQUIRED=ON \ - -DCMAKE_CXX_EXTENSIONS=OFF \ - -DCATCH_DEVELOPMENT_BUILD=ON \ - ${{matrix.cmake_configurations}} \ - -G Ninja - - - name: Build tests + lib - working-directory: ${{runner.workspace}}/build - run: ninja - - - name: Run tests - env: - CTEST_OUTPUT_ON_FAILURE: 1 - working-directory: ${{runner.workspace}}/build - run: ctest -C ${{matrix.build_type}} -j `nproc` ${{matrix.other_ctest_args}} + ${{matrix.cmake_configurations}} + + - name: Build + run: cmake --build build + + - name: Test + run: ctest --test-dir build -j --output-on-failure + clang-tidy: - name: clang-tidy ${{matrix.version}}, ${{matrix.build_description}}, C++${{matrix.std}} ${{matrix.build_type}} + name: clang-tidy runs-on: ubuntu-22.04 - strategy: - matrix: - include: - - version: "15" - build_description: all - build_type: Debug - std: 17 - other_pkgs: '' - cmake_configurations: -DCATCH_BUILD_EXAMPLES=ON -DCATCH_ENABLE_CMAKE_HELPER_TESTS=ON steps: - uses: actions/checkout@v4 - name: Prepare environment run: | sudo apt-get update - sudo apt-get install -y ninja-build clang-${{matrix.version}} clang-tidy-${{matrix.version}} ${{matrix.other_pkgs}} + sudo apt-get install -y ninja-build clang-15 clang-tidy-15 - - name: Configure build - working-directory: ${{runner.workspace}} - env: - CXX: clang++-${{matrix.version}} - CXXFLAGS: ${{matrix.cxxflags}} - # Note: $GITHUB_WORKSPACE is distinct from ${{runner.workspace}}. - # This is important + - name: Configure run: | - clangtidy="clang-tidy-${{matrix.version}};-use-color" + clangtidy="clang-tidy-15;-use-color" # Use a dummy compiler/linker/ar/ranlib to effectively disable the # compilation and only run clang-tidy. - cmake -Bbuild -H$GITHUB_WORKSPACE \ - -DCMAKE_BUILD_TYPE=${{matrix.build_type}} \ - -DCMAKE_CXX_STANDARD=${{matrix.std}} \ - -DCMAKE_CXX_STANDARD_REQUIRED=ON \ - -DCMAKE_CXX_EXTENSIONS=OFF \ - -DCATCH_DEVELOPMENT_BUILD=ON \ - -DCMAKE_CXX_CLANG_TIDY="$clangtidy" \ - -DCMAKE_CXX_COMPILER_LAUNCHER=/usr/bin/true \ + cmake --preset basic-tests -GNinja \ -DCMAKE_AR=/usr/bin/true \ + -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_CXX_CLANG_TIDY="$clangtidy" \ -DCMAKE_CXX_COMPILER_AR=/usr/bin/true \ - -DCMAKE_RANLIB=/usr/bin/true \ + -DCMAKE_CXX_COMPILER_LAUNCHER=/usr/bin/true \ + -DCMAKE_CXX_COMPILER=clang++-15 \ -DCMAKE_CXX_LINK_EXECUTABLE=/usr/bin/true \ - ${{matrix.cmake_configurations}} \ - -G Ninja + -DCMAKE_CXX_STANDARD=17 \ + -DCMAKE_RANLIB=/usr/bin/true \ + -DCATCH_BUILD_EXAMPLES=ON \ + -DCATCH_ENABLE_CMAKE_HELPER_TESTS=ON - name: Run clang-tidy - working-directory: ${{runner.workspace}}/build - run: ninja + run: cmake --build build diff --git a/catch2/.github/workflows/linux-simple-builds.yml b/catch2/.github/workflows/linux-simple-builds.yml index 4cca316..15db5cf 100644 --- a/catch2/.github/workflows/linux-simple-builds.yml +++ b/catch2/.github/workflows/linux-simple-builds.yml @@ -1,40 +1,39 @@ -name: Linux builds (basic) +name: Linux Builds (Basic) on: [push, pull_request] jobs: build: name: ${{matrix.cxx}}, C++${{matrix.std}}, ${{matrix.build_type}} - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 strategy: + fail-fast: false matrix: cxx: - - g++-5 - - g++-6 - - g++-7 - - g++-8 - g++-9 - g++-10 + - g++-11 + - g++-12 - clang++-6.0 - clang++-7 - clang++-8 - clang++-9 - clang++-10 + - clang++-11 + - clang++-12 + - clang++-13 + - clang++-14 build_type: [Debug, Release] std: [14] include: - - cxx: g++-5 - other_pkgs: g++-5 - - cxx: g++-6 - other_pkgs: g++-6 - - cxx: g++-7 - other_pkgs: g++-7 - - cxx: g++-8 - other_pkgs: g++-8 - cxx: g++-9 other_pkgs: g++-9 - cxx: g++-10 other_pkgs: g++-10 + - cxx: g++-11 + other_pkgs: g++-11 + - cxx: g++-12 + other_pkgs: g++-12 - cxx: clang++-6.0 other_pkgs: clang-6.0 - cxx: clang++-7 @@ -45,79 +44,62 @@ jobs: other_pkgs: clang-9 - cxx: clang++-10 other_pkgs: clang-10 - # Clang 6 + C++17 - # does not work with the default libstdc++ version thanks - # to a disagreement on variant implementation. - # - cxx: clang++-6.0 - # build_type: Debug - # std: 17 - # other_pkgs: clang-6.0 - # - cxx: clang++-6.0 - # build_type: Release - # std: 17 - # other_pkgs: clang-6.0 - # Clang 10 + C++17 - - cxx: clang++-10 + - cxx: clang++-11 + other_pkgs: clang-11 + - cxx: clang++-12 + other_pkgs: clang-12 + - cxx: clang++-13 + other_pkgs: clang-13 + - cxx: clang++-14 + other_pkgs: clang-14 + # Clang 14 + C++17 + - cxx: clang++-14 build_type: Debug std: 17 - other_pkgs: clang-10 - - cxx: clang++-10 + other_pkgs: clang-14 + - cxx: clang++-14 build_type: Release std: 17 - other_pkgs: clang-10 - - cxx: clang++-10 + other_pkgs: clang-14 + - cxx: clang++-14 build_type: Debug std: 20 - other_pkgs: clang-10 - - cxx: clang++-10 + other_pkgs: clang-14 + - cxx: clang++-14 build_type: Release std: 20 - other_pkgs: clang-10 - - cxx: g++-10 + other_pkgs: clang-14 + - cxx: g++-11 build_type: Debug std: 20 - other_pkgs: g++-10 - - cxx: g++-10 + other_pkgs: g++-11 + - cxx: g++-11 build_type: Release std: 20 - other_pkgs: g++-10 + other_pkgs: g++-11 steps: - uses: actions/checkout@v4 - - name: Add repositories for older GCC + - name: Add repositories for older compilers run: | - sudo apt-add-repository 'deb http://azure.archive.ubuntu.com/ubuntu/ bionic main' - sudo apt-add-repository 'deb http://azure.archive.ubuntu.com/ubuntu/ bionic universe' - if: ${{ matrix.cxx == 'g++-5' || matrix.cxx == 'g++-6' }} + sudo apt-add-repository 'deb http://azure.archive.ubuntu.com/ubuntu/ focal main' + sudo apt-add-repository 'deb http://azure.archive.ubuntu.com/ubuntu/ focal universe' - name: Prepare environment run: | sudo apt-get update sudo apt-get install -y ninja-build ${{matrix.other_pkgs}} - - name: Configure build - working-directory: ${{runner.workspace}} - env: - CXX: ${{matrix.cxx}} - CXXFLAGS: ${{matrix.cxxflags}} - # Note: $GITHUB_WORKSPACE is distinct from ${{runner.workspace}}. - # This is important + - name: Configure run: | - cmake -Bbuild -H$GITHUB_WORKSPACE \ + cmake --preset basic-tests -GNinja \ -DCMAKE_BUILD_TYPE=${{matrix.build_type}} \ - -DCMAKE_CXX_STANDARD=${{matrix.std}} \ - -DCMAKE_CXX_STANDARD_REQUIRED=ON \ - -DCMAKE_CXX_EXTENSIONS=OFF \ - -DCATCH_DEVELOPMENT_BUILD=ON \ - -G Ninja + -DCMAKE_CXX_COMPILER=${{matrix.cxx}} \ + -DCMAKE_CXX_STANDARD=${{matrix.std}} - - name: Build tests + lib - working-directory: ${{runner.workspace}}/build - run: ninja + - name: Build + run: cmake --build build - - name: Run tests - env: - CTEST_OUTPUT_ON_FAILURE: 1 - working-directory: ${{runner.workspace}}/build - run: ctest -C ${{matrix.build_type}} -j `nproc` + - name: Test + run: ctest --test-dir build -j --output-on-failure diff --git a/catch2/.github/workflows/mac-builds-m1.yml b/catch2/.github/workflows/mac-builds-m1.yml deleted file mode 100644 index 45629cd..0000000 --- a/catch2/.github/workflows/mac-builds-m1.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: Arm Mac builds - -on: [push, pull_request] - -jobs: - build: - runs-on: macos-14 - strategy: - matrix: - cxx: - - clang++ - build_type: [Debug, Release] - std: [14, 17] - include: - - build_type: Debug - examples: ON - extra_tests: ON - - steps: - - uses: actions/checkout@v4 - - - name: Configure build - working-directory: ${{runner.workspace}} - env: - CXX: ${{matrix.cxx}} - CXXFLAGS: ${{matrix.cxxflags}} - run: | - cmake -Bbuild -H$GITHUB_WORKSPACE \ - -DCMAKE_BUILD_TYPE=${{matrix.build_type}} \ - -DCMAKE_CXX_STANDARD=${{matrix.std}} \ - -DCMAKE_CXX_STANDARD_REQUIRED=ON \ - -DCATCH_DEVELOPMENT_BUILD=ON \ - -DCATCH_BUILD_EXAMPLES=${{matrix.examples}} \ - -DCATCH_BUILD_EXTRA_TESTS=${{matrix.examples}} - - - name: Build tests + lib - working-directory: ${{runner.workspace}}/build - run: make -j `sysctl -n hw.ncpu` - - - name: Run tests - env: - CTEST_OUTPUT_ON_FAILURE: 1 - working-directory: ${{runner.workspace}}/build - run: ctest -C ${{matrix.build_type}} -j `sysctl -n hw.ncpu` diff --git a/catch2/.github/workflows/mac-builds.yml b/catch2/.github/workflows/mac-builds.yml index fb41f5d..6ac4c2a 100644 --- a/catch2/.github/workflows/mac-builds.yml +++ b/catch2/.github/workflows/mac-builds.yml @@ -1,48 +1,32 @@ -name: Intel Mac builds +name: Mac Builds on: [push, pull_request] jobs: build: # From macos-14 forward, the baseline "macos-X" image is Arm based, - # and not Intel based. Thus this is the newest image we can use for - # Intel MacOS CI, and there don't seem to be any plans to keep providing - # the Intel based images for free to OSS projects. - runs-on: macos-13 + # and not Intel based. + runs-on: ${{matrix.image}} strategy: + fail-fast: false matrix: - cxx: - - clang++ + image: [macos-13, macos-14, macos-15] build_type: [Debug, Release] std: [14, 17] - include: - - build_type: Debug - examples: ON - extra_tests: ON steps: - uses: actions/checkout@v4 - - name: Configure build - working-directory: ${{runner.workspace}} - env: - CXX: ${{matrix.cxx}} - CXXFLAGS: ${{matrix.cxxflags}} + - name: Configure run: | - cmake -Bbuild -H$GITHUB_WORKSPACE \ + cmake --preset basic-tests -GNinja \ -DCMAKE_BUILD_TYPE=${{matrix.build_type}} \ -DCMAKE_CXX_STANDARD=${{matrix.std}} \ - -DCMAKE_CXX_STANDARD_REQUIRED=ON \ - -DCATCH_DEVELOPMENT_BUILD=ON \ - -DCATCH_BUILD_EXAMPLES=${{matrix.examples}} \ - -DCATCH_BUILD_EXTRA_TESTS=${{matrix.examples}} + -DCATCH_BUILD_EXAMPLES=ON \ + -DCATCH_BUILD_EXTRA_TESTS=ON - - name: Build tests + lib - working-directory: ${{runner.workspace}}/build - run: make -j `sysctl -n hw.ncpu` + - name: Build + run: cmake --build build - - name: Run tests - env: - CTEST_OUTPUT_ON_FAILURE: 1 - working-directory: ${{runner.workspace}}/build - run: ctest -C ${{matrix.build_type}} -j `sysctl -n hw.ncpu` + - name: Test + run: ctest --test-dir build -j --output-on-failure diff --git a/catch2/.github/workflows/package-manager-builds.yaml b/catch2/.github/workflows/package-manager-builds.yaml index 6d90d14..74704c6 100644 --- a/catch2/.github/workflows/package-manager-builds.yaml +++ b/catch2/.github/workflows/package-manager-builds.yaml @@ -5,7 +5,7 @@ on: [push, pull_request] jobs: conan_builds: name: Conan ${{matrix.conan_version}} - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 strategy: matrix: conan_version: diff --git a/catch2/.github/workflows/validate-header-guards.yml b/catch2/.github/workflows/validate-header-guards.yml index fa9d157..13dac2a 100644 --- a/catch2/.github/workflows/validate-header-guards.yml +++ b/catch2/.github/workflows/validate-header-guards.yml @@ -5,7 +5,7 @@ on: [push, pull_request] jobs: build: # Set the type of machine to run on - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - name: Checkout source code diff --git a/catch2/.github/workflows/windows-simple-builds.yml b/catch2/.github/workflows/windows-simple-builds.yml index 5fb7b8f..e6d852b 100644 --- a/catch2/.github/workflows/windows-simple-builds.yml +++ b/catch2/.github/workflows/windows-simple-builds.yml @@ -1,4 +1,4 @@ -name: Windows builds (basic) +name: Windows Builds (Basic) on: [push, pull_request] @@ -7,8 +7,9 @@ jobs: name: ${{matrix.os}}, ${{matrix.std}}, ${{matrix.build_type}}, ${{matrix.platform}} runs-on: ${{matrix.os}} strategy: + fail-fast: false matrix: - os: [windows-2019, windows-2022] + os: [windows-2022, windows-2025] platform: [Win32, x64] build_type: [Debug, Release] std: [14, 17] @@ -16,22 +17,15 @@ jobs: - uses: actions/checkout@v4 - name: Configure build - working-directory: ${{runner.workspace}} run: | - cmake -S $Env:GITHUB_WORKSPACE ` - -B ${{runner.workspace}}/build ` - -DCMAKE_CXX_STANDARD=${{matrix.std}} ` - -A ${{matrix.platform}} ` - --preset all-tests + cmake --preset all-tests ` + -A ${{matrix.platform}} ` + -DCMAKE_CXX_STANDARD=${{matrix.std}} ` - name: Build tests - working-directory: ${{runner.workspace}} run: cmake --build build --config ${{matrix.build_type}} --parallel %NUMBER_OF_PROCESSORS% shell: cmd - name: Run tests - working-directory: ${{runner.workspace}}/build - env: - CTEST_OUTPUT_ON_FAILURE: 1 - run: ctest -C ${{matrix.build_type}} -j %NUMBER_OF_PROCESSORS% + run: ctest --test-dir build -C ${{matrix.build_type}} -j %NUMBER_OF_PROCESSORS% --output-on-failure shell: cmd diff --git a/catch2/BUILD.bazel b/catch2/BUILD.bazel index d96c7fa..eb484e4 100644 --- a/catch2/BUILD.bazel +++ b/catch2/BUILD.bazel @@ -1,4 +1,20 @@ load("@bazel_skylib//rules:expand_template.bzl", "expand_template") +load("@rules_cc//cc:cc_library.bzl", "cc_library") +load("@rules_license//rules:license.bzl", "license") + +package( + default_applicable_licenses = [":license"], +) + +exports_files([ + "LICENSE.MIT", +]) + +license( + name = "license", + license_kinds = ["@rules_license//licenses/spdx:BSL-1.0"], + license_text = "LICENSE.MIT", +) expand_template( name = "catch_user_config", @@ -16,6 +32,7 @@ expand_template( "#cmakedefine CATCH_CONFIG_CPP17_STRING_VIEW": "", "#cmakedefine CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS": "", "#cmakedefine CATCH_CONFIG_CPP17_VARIANT": "", + "#cmakedefine CATCH_CONFIG_DEPRECATION_ANNOTATIONS": "", "#cmakedefine CATCH_CONFIG_DISABLE_EXCEPTIONS_CUSTOM_HANDLER": "", "#cmakedefine CATCH_CONFIG_DISABLE_EXCEPTIONS": "", "#cmakedefine CATCH_CONFIG_DISABLE_STRINGIFICATION": "", @@ -39,6 +56,7 @@ expand_template( "#cmakedefine CATCH_CONFIG_NO_CPP17_STRING_VIEW": "", "#cmakedefine CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS": "", "#cmakedefine CATCH_CONFIG_NO_CPP17_VARIANT": "", + "#cmakedefine CATCH_CONFIG_NO_DEPRECATION_ANNOTATIONS": "", "#cmakedefine CATCH_CONFIG_NO_GETENV": "", "#cmakedefine CATCH_CONFIG_NO_GLOBAL_NEXTAFTER": "", "#cmakedefine CATCH_CONFIG_NO_POSIX_SIGNALS": "", @@ -58,6 +76,8 @@ expand_template( "#cmakedefine CATCH_CONFIG_WINDOWS_SEH": "", "#cmakedefine CATCH_CONFIG_USE_BUILTIN_CONSTANT_P": "", "#cmakedefine CATCH_CONFIG_NO_USE_BUILTIN_CONSTANT_P": "", + "#cmakedefine CATCH_CONFIG_EXPERIMENTAL_THREAD_SAFE_ASSERTIONS": "", + "#cmakedefine CATCH_CONFIG_NO_EXPERIMENTAL_THREAD_SAFE_ASSERTIONS": "", }, template = "src/catch2/catch_user_config.hpp.in", ) @@ -68,7 +88,7 @@ expand_template( cc_library( name = "catch2_generated", hdrs = ["catch2/catch_user_config.hpp"], - include_prefix = ".", # to manipulate -I of dependenices + include_prefix = ".", # to manipulate -I of dependencies visibility = ["//visibility:public"], ) diff --git a/catch2/CMake/Catch2Config.cmake.in b/catch2/CMake/Catch2Config.cmake.in index c485219..9268138 100644 --- a/catch2/CMake/Catch2Config.cmake.in +++ b/catch2/CMake/Catch2Config.cmake.in @@ -1,10 +1,9 @@ @PACKAGE_INIT@ - # Avoid repeatedly including the targets if(NOT TARGET Catch2::Catch2) - # Provide path for scripts - list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") + # Provide path for scripts + list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") - include(${CMAKE_CURRENT_LIST_DIR}/Catch2Targets.cmake) + include(${CMAKE_CURRENT_LIST_DIR}/Catch2Targets.cmake) endif() diff --git a/catch2/CMake/CatchConfigOptions.cmake b/catch2/CMake/CatchConfigOptions.cmake index a2f2870..3621fac 100644 --- a/catch2/CMake/CatchConfigOptions.cmake +++ b/catch2/CMake/CatchConfigOptions.cmake @@ -14,7 +14,6 @@ # # For detailed docs look into docs/configuration.md - macro(AddOverridableConfigOption OptionBaseName) option(CATCH_CONFIG_${OptionBaseName} "Read docs/configuration.md for details" OFF) option(CATCH_CONFIG_NO_${OptionBaseName} "Read docs/configuration.md for details" OFF) @@ -45,6 +44,8 @@ set(_OverridableOptions "GETENV" "EXPERIMENTAL_STATIC_ANALYSIS_SUPPORT" "USE_BUILTIN_CONSTANT_P" + "DEPRECATION_ANNOTATIONS" + "EXPERIMENTAL_THREAD_SAFE_ASSERTIONS" ) foreach(OptionName ${_OverridableOptions}) @@ -74,9 +75,9 @@ foreach(OptionName ${_OtherConfigOptions}) AddConfigOption(${OptionName}) endforeach() if(DEFINED BUILD_SHARED_LIBS) - set(CATCH_CONFIG_SHARED_LIBRARY ${BUILD_SHARED_LIBS}) + set(CATCH_CONFIG_SHARED_LIBRARY ${BUILD_SHARED_LIBS}) else() - set(CATCH_CONFIG_SHARED_LIBRARY "") + set(CATCH_CONFIG_SHARED_LIBRARY "") endif() set(CATCH_CONFIG_DEFAULT_REPORTER "console" CACHE STRING "Read docs/configuration.md for details. The name of the reporter should be without quotes.") diff --git a/catch2/CMake/CatchMiscFunctions.cmake b/catch2/CMake/CatchMiscFunctions.cmake index 05bc83c..d1cf5fc 100644 --- a/catch2/CMake/CatchMiscFunctions.cmake +++ b/catch2/CMake/CatchMiscFunctions.cmake @@ -8,108 +8,107 @@ include(CheckCXXCompilerFlag) function(add_cxx_flag_if_supported_to_targets flagname targets) - string(MAKE_C_IDENTIFIER ${flagname} flag_identifier ) - check_cxx_compiler_flag("${flagname}" HAVE_FLAG_${flag_identifier}) + string(MAKE_C_IDENTIFIER ${flagname} flag_identifier) + check_cxx_compiler_flag("${flagname}" HAVE_FLAG_${flag_identifier}) - if (HAVE_FLAG_${flag_identifier}) - foreach(target ${targets}) - target_compile_options(${target} PRIVATE ${flagname}) - endforeach() - endif() + if(HAVE_FLAG_${flag_identifier}) + foreach(target ${targets}) + target_compile_options(${target} PRIVATE ${flagname}) + endforeach() + endif() endfunction() # Assumes that it is only called for development builds, where warnings # and Werror is desired, so it also enables Werror. function(add_warnings_to_targets targets) - LIST(LENGTH targets TARGETS_LEN) - # For now we just assume 2 possibilities: msvc and msvc-like compilers, - # and other. - if (MSVC) - foreach(target ${targets}) - # Force MSVC to consider everything as encoded in utf-8 - target_compile_options( ${target} PRIVATE /utf-8 ) - # Enable Werror equivalent - if (CATCH_ENABLE_WERROR) - target_compile_options( ${target} PRIVATE /WX ) - endif() - - # MSVC is currently handled specially - if ( CMAKE_CXX_COMPILER_ID MATCHES "MSVC" ) - STRING(REGEX REPLACE "/W[0-9]" "/W4" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) # override default warning level - target_compile_options( ${target} PRIVATE /w44265 /w44061 /w44062 /w45038 ) - endif() - endforeach() + LIST(LENGTH targets TARGETS_LEN) + # For now we just assume 2 possibilities: msvc and msvc-like compilers, + # and other. + if(MSVC) + foreach(target ${targets}) + # Force MSVC to consider everything as encoded in utf-8 + target_compile_options(${target} PRIVATE /utf-8) + # Enable Werror equivalent + if(CATCH_ENABLE_WERROR) + target_compile_options(${target} PRIVATE /WX) + endif() - endif() + # MSVC is currently handled specially + if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") + STRING(REGEX REPLACE "/W[0-9]" "/W4" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) # override default warning level + target_compile_options(${target} PRIVATE /w44265 /w44061 /w44062 /w45038) + endif() + endforeach() + endif() - if (NOT MSVC) - set(CHECKED_WARNING_FLAGS - "-Wabsolute-value" - "-Wall" - "-Wcall-to-pure-virtual-from-ctor-dtor" - "-Wcast-align" - "-Wcatch-value" - "-Wdangling" - "-Wdeprecated" - "-Wdeprecated-register" - "-Wexceptions" - "-Wexit-time-destructors" - "-Wextra" - "-Wextra-semi" - "-Wfloat-equal" - "-Wglobal-constructors" - "-Winit-self" - "-Wmisleading-indentation" - "-Wmismatched-new-delete" - "-Wmismatched-return-types" - "-Wmismatched-tags" - "-Wmissing-braces" - "-Wmissing-declarations" - "-Wmissing-noreturn" - "-Wmissing-prototypes" - "-Wmissing-variable-declarations" - "-Wnon-virtual-dtor" - "-Wnull-dereference" - "-Wold-style-cast" - "-Woverloaded-virtual" - "-Wparentheses" - "-Wpedantic" - "-Wredundant-decls" - "-Wreorder" - "-Wreturn-std-move" - "-Wshadow" - "-Wstrict-aliasing" - "-Wsubobject-linkage" - "-Wsuggest-destructor-override" - "-Wsuggest-override" - "-Wundef" - "-Wuninitialized" - "-Wunneeded-internal-declaration" - "-Wunreachable-code-aggressive" - "-Wunused" - "-Wunused-function" - "-Wunused-parameter" - "-Wvla" - "-Wweak-vtables" + if(NOT MSVC) + set(CHECKED_WARNING_FLAGS + "-Wabsolute-value" + "-Wall" + "-Wcall-to-pure-virtual-from-ctor-dtor" + "-Wcast-align" + "-Wcatch-value" + "-Wdangling" + "-Wdeprecated" + "-Wdeprecated-register" + "-Wexceptions" + "-Wexit-time-destructors" + "-Wextra" + "-Wextra-semi" + "-Wfloat-equal" + "-Wglobal-constructors" + "-Winit-self" + "-Wmisleading-indentation" + "-Wmismatched-new-delete" + "-Wmismatched-return-types" + "-Wmismatched-tags" + "-Wmissing-braces" + "-Wmissing-declarations" + "-Wmissing-noreturn" + "-Wmissing-prototypes" + "-Wmissing-variable-declarations" + "-Wnon-virtual-dtor" + "-Wnull-dereference" + "-Wold-style-cast" + "-Woverloaded-virtual" + "-Wparentheses" + "-Wpedantic" + "-Wredundant-decls" + "-Wreorder" + "-Wreturn-std-move" + "-Wshadow" + "-Wstrict-aliasing" + "-Wsubobject-linkage" + "-Wsuggest-destructor-override" + "-Wsuggest-override" + "-Wundef" + "-Wuninitialized" + "-Wunneeded-internal-declaration" + "-Wunreachable-code-aggressive" + "-Wunused" + "-Wunused-function" + "-Wunused-parameter" + "-Wvla" + "-Wweak-vtables" - # This is a useful warning, but our tests sometimes rely on - # functions being present, but not picked (e.g. various checks - # for stringification implementation ordering). - # Ergo, we should use it every now and then, but we cannot - # enable it by default. - # "-Wunused-member-function" - ) - foreach(warning ${CHECKED_WARNING_FLAGS}) - add_cxx_flag_if_supported_to_targets(${warning} "${targets}") - endforeach() + # This is a useful warning, but our tests sometimes rely on + # functions being present, but not picked (e.g. various checks + # for stringification implementation ordering). + # Ergo, we should use it every now and then, but we cannot + # enable it by default. + # "-Wunused-member-function" + ) + foreach(warning ${CHECKED_WARNING_FLAGS}) + add_cxx_flag_if_supported_to_targets(${warning} "${targets}") + endforeach() - if (CATCH_ENABLE_WERROR) - foreach(target ${targets}) - # Enable Werror equivalent - target_compile_options( ${target} PRIVATE -Werror ) - endforeach() - endif() + if(CATCH_ENABLE_WERROR) + foreach(target ${targets}) + # Enable Werror equivalent + target_compile_options(${target} PRIVATE -Werror) + endforeach() endif() + endif() endfunction() # Adds flags required for reproducible build to the target diff --git a/catch2/CMake/catch2-with-main.pc.in b/catch2/CMake/catch2-with-main.pc.in index 69a790b..eeac3e3 100644 --- a/catch2/CMake/catch2-with-main.pc.in +++ b/catch2/CMake/catch2-with-main.pc.in @@ -1,10 +1,10 @@ -includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ -libdir=@CMAKE_INSTALL_FULL_LIBDIR@ +prefix=@CMAKE_INSTALL_PREFIX@ +libdir=${prefix}/@lib_dir@ pkg_version=@Catch2_VERSION@ -Name: Catch2-With-Main +Name: Catch2 with main function Description: A modern, C++-native test framework for C++14 and above (links in default main) +URL: https://github.com/catchorg/Catch2 Version: ${pkg_version} Requires: catch2 = ${pkg_version} -Cflags: -I${includedir} -Libs: -L${libdir} -lCatch2Main +Libs: -L${libdir} -l@lib_name@ diff --git a/catch2/CMake/catch2.pc.in b/catch2/CMake/catch2.pc.in index bd1c95a..74e22c1 100644 --- a/catch2/CMake/catch2.pc.in +++ b/catch2/CMake/catch2.pc.in @@ -1,11 +1,11 @@ prefix=@CMAKE_INSTALL_PREFIX@ exec_prefix=${prefix} -includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ -libdir=@CMAKE_INSTALL_FULL_LIBDIR@ +includedir=${prefix}/@include_dir@ +libdir=${prefix}/@lib_dir@ Name: Catch2 Description: A modern, C++-native, test framework for C++14 and above URL: https://github.com/catchorg/Catch2 Version: @Catch2_VERSION@ Cflags: -I${includedir} -Libs: -L${libdir} -lCatch2 +Libs: -L${libdir} -l@lib_name@ diff --git a/catch2/CMakeLists.txt b/catch2/CMakeLists.txt index 0d8226b..918927c 100644 --- a/catch2/CMakeLists.txt +++ b/catch2/CMakeLists.txt @@ -20,22 +20,22 @@ cmake_dependent_option(CATCH_BUILD_TESTING "Build the SelfTest project" ON "CATC cmake_dependent_option(CATCH_BUILD_EXAMPLES "Build code examples" OFF "CATCH_DEVELOPMENT_BUILD" OFF) cmake_dependent_option(CATCH_BUILD_EXTRA_TESTS "Build extra tests" OFF "CATCH_DEVELOPMENT_BUILD" OFF) cmake_dependent_option(CATCH_BUILD_FUZZERS "Build fuzzers" OFF "CATCH_DEVELOPMENT_BUILD" OFF) +cmake_dependent_option(CATCH_BUILD_BENCHMARKS "Build the benchmarks" OFF "CATCH_DEVELOPMENT_BUILD" OFF) cmake_dependent_option(CATCH_ENABLE_COVERAGE "Generate coverage for codecov.io" OFF "CATCH_DEVELOPMENT_BUILD" OFF) cmake_dependent_option(CATCH_ENABLE_WERROR "Enables Werror during build" ON "CATCH_DEVELOPMENT_BUILD" OFF) cmake_dependent_option(CATCH_BUILD_SURROGATES "Enable generating and building surrogate TUs for the main headers" OFF "CATCH_DEVELOPMENT_BUILD" OFF) cmake_dependent_option(CATCH_ENABLE_CONFIGURE_TESTS "Enable CMake configuration tests. WARNING: VERY EXPENSIVE" OFF "CATCH_DEVELOPMENT_BUILD" OFF) cmake_dependent_option(CATCH_ENABLE_CMAKE_HELPER_TESTS "Enable CMake helper tests. WARNING: VERY EXPENSIVE" OFF "CATCH_DEVELOPMENT_BUILD" OFF) - # Catch2's build breaks if done in-tree. You probably should not build # things in tree anyway, but we can allow projects that include Catch2 # as a subproject to build in-tree as long as it is not in our tree. -if (CMAKE_BINARY_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) - message(FATAL_ERROR "Building in-source is not supported! Create a build dir and remove ${CMAKE_SOURCE_DIR}/CMakeCache.txt") +if(CMAKE_BINARY_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + message(FATAL_ERROR "Building in-source is not supported! Create a build dir and remove ${CMAKE_SOURCE_DIR}/CMakeCache.txt") endif() project(Catch2 - VERSION 3.8.1 # CML version placeholder, don't delete + VERSION 3.11.0 # CML version placeholder, don't delete LANGUAGES CXX HOMEPAGE_URL "https://github.com/catchorg/Catch2" DESCRIPTION "A modern, C++-native, unit test framework." @@ -46,7 +46,7 @@ project(Catch2 # Then we also add path that we use to configure the project, but is of # no use to top level projects. list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/extras") -if (NOT NOT_SUBPROJECT) +if(NOT NOT_SUBPROJECT) set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" PARENT_SCOPE) endif() list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake") @@ -67,10 +67,9 @@ set(CATCH_CMAKE_CONFIG_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Catch2") # are built during these tests, so this is required here, before # the subdirectories are added. if(CATCH_TEST_USE_WMAIN) - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ENTRY:wmainCRTStartup") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ENTRY:wmainCRTStartup") endif() - # Basic paths set(CATCH_DIR ${CMAKE_CURRENT_SOURCE_DIR}) set(SOURCES_DIR ${CATCH_DIR}/src/catch2) @@ -79,120 +78,153 @@ set(SELF_TEST_DIR ${CATCH_DIR}/tests/SelfTest) # We need to bring-in the variables defined there to this scope add_subdirectory(src) +if (CATCH_BUILD_BENCHMARKS) + set(CMAKE_FOLDER "benchmarks") + add_subdirectory(benchmarks) +endif() + # Build tests only if requested -if (BUILD_TESTING AND CATCH_BUILD_TESTING AND NOT_SUBPROJECT) - find_package(PythonInterp 3 REQUIRED) - if (NOT PYTHONINTERP_FOUND) - message(FATAL_ERROR "Python not found, but required for tests") - endif() - set(CMAKE_FOLDER "tests") - add_subdirectory(tests) +if(BUILD_TESTING AND CATCH_BUILD_TESTING AND NOT_SUBPROJECT) + find_package(Python3 REQUIRED COMPONENTS Interpreter) + if(NOT TARGET Python3::Interpreter) + message(FATAL_ERROR "Python not found, but required for tests") + endif() + set(CMAKE_FOLDER "tests") + add_subdirectory(tests) endif() if(CATCH_BUILD_EXAMPLES) - set(CMAKE_FOLDER "Examples") - add_subdirectory(examples) + set(CMAKE_FOLDER "Examples") + add_subdirectory(examples) endif() if(CATCH_BUILD_EXTRA_TESTS) - set(CMAKE_FOLDER "tests/ExtraTests") - add_subdirectory(tests/ExtraTests) + set(CMAKE_FOLDER "tests/ExtraTests") + add_subdirectory(tests/ExtraTests) endif() if(CATCH_BUILD_FUZZERS) - set(CMAKE_FOLDER "fuzzing") - add_subdirectory(fuzzing) + set(CMAKE_FOLDER "fuzzing") + add_subdirectory(fuzzing) endif() -if (CATCH_DEVELOPMENT_BUILD) - add_warnings_to_targets("${CATCH_WARNING_TARGETS}") +if(CATCH_DEVELOPMENT_BUILD) + set(CATCH_ALL_TARGETS ${CATCH_IMPL_TARGETS} ${CATCH_TEST_TARGETS}) + add_warnings_to_targets("${CATCH_ALL_TARGETS}") + # After we added the noreturn hint to FAIL and SKIP, Clang became + # extremely good at diagnosing tests that test these macros as being + # noreturn, but not marked as such. This made the warning useless for + # our test files. + add_cxx_flag_if_supported_to_targets("-Wno-missing-noreturn" "${CATCH_TEST_TARGETS}") endif() # Only perform the installation steps when Catch is not being used as # a subproject via `add_subdirectory`, or the destinations will break, # see https://github.com/catchorg/Catch2/issues/1373 -if (NOT_SUBPROJECT) - configure_package_config_file( - ${CMAKE_CURRENT_LIST_DIR}/CMake/Catch2Config.cmake.in - ${CMAKE_CURRENT_BINARY_DIR}/Catch2Config.cmake - INSTALL_DESTINATION - ${CATCH_CMAKE_CONFIG_DESTINATION} - ) - - write_basic_package_version_file( +if(NOT_SUBPROJECT) + configure_package_config_file( + ${CMAKE_CURRENT_LIST_DIR}/CMake/Catch2Config.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/Catch2Config.cmake + INSTALL_DESTINATION + ${CATCH_CMAKE_CONFIG_DESTINATION} + ) + + write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/Catch2ConfigVersion.cmake" + COMPATIBILITY + SameMajorVersion + ) + + install( + FILES + "${CMAKE_CURRENT_BINARY_DIR}/Catch2Config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/Catch2ConfigVersion.cmake" - COMPATIBILITY - SameMajorVersion + DESTINATION + ${CATCH_CMAKE_CONFIG_DESTINATION} + ) + + # Install documentation + if(CATCH_INSTALL_DOCS) + install( + DIRECTORY + docs/ + DESTINATION + "${CMAKE_INSTALL_DOCDIR}" + PATTERN "doxygen" EXCLUDE ) + endif() + if(CATCH_INSTALL_EXTRAS) + # Install CMake scripts install( FILES - "${CMAKE_CURRENT_BINARY_DIR}/Catch2Config.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/Catch2ConfigVersion.cmake" + "extras/ParseAndAddCatchTests.cmake" + "extras/Catch.cmake" + "extras/CatchAddTests.cmake" + "extras/CatchShardTests.cmake" + "extras/CatchShardTestsImpl.cmake" DESTINATION ${CATCH_CMAKE_CONFIG_DESTINATION} ) - # Install documentation - if(CATCH_INSTALL_DOCS) - install( - DIRECTORY - docs/ - DESTINATION - "${CMAKE_INSTALL_DOCDIR}" - PATTERN "doxygen" EXCLUDE - ) - endif() - - if(CATCH_INSTALL_EXTRAS) - # Install CMake scripts - install( - FILES - "extras/ParseAndAddCatchTests.cmake" - "extras/Catch.cmake" - "extras/CatchAddTests.cmake" - "extras/CatchShardTests.cmake" - "extras/CatchShardTestsImpl.cmake" - DESTINATION - ${CATCH_CMAKE_CONFIG_DESTINATION} - ) - - # Install debugger helpers - install( - FILES - "extras/gdbinit" - "extras/lldbinit" - DESTINATION - ${CMAKE_INSTALL_DATAROOTDIR}/Catch2 - ) - endif() - - ## Provide some pkg-config integration - set(PKGCONFIG_INSTALL_DIR - "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig" - CACHE PATH "Path where catch2.pc is installed" - ) - configure_file( - ${CMAKE_CURRENT_SOURCE_DIR}/CMake/catch2.pc.in - ${CMAKE_CURRENT_BINARY_DIR}/catch2.pc - @ONLY - ) - configure_file( - ${CMAKE_CURRENT_SOURCE_DIR}/CMake/catch2-with-main.pc.in - ${CMAKE_CURRENT_BINARY_DIR}/catch2-with-main.pc - @ONLY - ) + # Install debugger helpers install( FILES - "${CMAKE_CURRENT_BINARY_DIR}/catch2.pc" - "${CMAKE_CURRENT_BINARY_DIR}/catch2-with-main.pc" + "extras/gdbinit" + "extras/lldbinit" DESTINATION - ${PKGCONFIG_INSTALL_DIR} + ${CMAKE_INSTALL_DATAROOTDIR}/Catch2 ) - - set(CPACK_PACKAGE_CONTACT "https://github.com/catchorg/Catch2/") - - - include( CPack ) - + endif() + + ## Provide some pkg-config integration + set(PKGCONFIG_INSTALL_DIR + "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig" + CACHE PATH "Path where catch2.pc is installed" + ) + + # Generate the pkg-config files + # To understand the script below, you have to understand that it works in two steps. + # 1) A CMake script is generated at configuration time + # 2) It is executed at install time. + # And both of these have access to different parts of the information we need. + # + # Further, the variables before "[[" are expanded at configuration time, + # while the ones inside the [[]] block are expanded at script execution (install) time. + string( + JOIN "\n" + install_script + "set(install_pkgconfdir \"${PKGCONFIG_INSTALL_DIR}\")" + "set(impl_pc_file \"${CMAKE_CURRENT_SOURCE_DIR}/CMake/catch2.pc.in\")" + "set(main_pc_file \"${CMAKE_CURRENT_SOURCE_DIR}/CMake/catch2-with-main.pc.in\")" + "set(Catch2_VERSION ${Catch2_VERSION})" + "set(include_dir \"${CMAKE_INSTALL_INCLUDEDIR}\")" + "set(lib_dir \"${CMAKE_INSTALL_LIBDIR}\")" + [[ + message(STATUS "DESTDIR: $ENV{DESTDIR}") + set(DESTDIR_PREFIX "") + if (DEFINED ENV{DESTDIR}) + set(DESTDIR_PREFIX "$ENV{DESTDIR}") + endif () + message(STATUS "PREFIX: ${DESTDIR_PREFIX}") + set(lib_name "$") + configure_file( + "${impl_pc_file}" + "${DESTDIR_PREFIX}${CMAKE_INSTALL_PREFIX}/${install_pkgconfdir}/catch2.pc" + @ONLY + ) + + set(lib_name "$") + configure_file( + "${main_pc_file}" + "${DESTDIR_PREFIX}${CMAKE_INSTALL_PREFIX}/${install_pkgconfdir}/catch2-with-main.pc" + @ONLY + ) + ]] + ) + install(CODE "${install_script}") + + set(CPACK_PACKAGE_CONTACT "https://github.com/catchorg/Catch2/") + + include(CPack) endif() diff --git a/catch2/CMakePresets.json b/catch2/CMakePresets.json index 8854128..ffc6e24 100644 --- a/catch2/CMakePresets.json +++ b/catch2/CMakePresets.json @@ -3,21 +3,35 @@ "configurePresets": [ { "name": "basic-tests", + "binaryDir": "build", + "installDir": "build/install", "displayName": "Basic development build", "description": "Enables development build with basic tests that are cheap to build and run", "cacheVariables": { + "CMAKE_CXX_EXTENSIONS": "OFF", + "CMAKE_CXX_STANDARD_REQUIRED": "ON", + "CMAKE_EXPORT_COMPILE_COMMANDS": "ON", "CATCH_DEVELOPMENT_BUILD": "ON" } }, { - "name": "all-tests", + "name": "most-tests", "inherits": "basic-tests", "displayName": "Full development build", - "description": "Enables development build with examples and ALL tests", + "description": "Enables development build with extended set of tests (still relatively cheap to build)", "cacheVariables": { "CATCH_BUILD_EXAMPLES": "ON", "CATCH_BUILD_EXTRA_TESTS": "ON", "CATCH_BUILD_SURROGATES": "ON", + "CATCH_BUILD_BENCHMARKS": "ON" + } + }, + { + "name": "all-tests", + "inherits": "most-tests", + "displayName": "Full development build", + "description": "Enables development build with examples and ALL tests", + "cacheVariables": { "CATCH_ENABLE_CONFIGURE_TESTS": "ON", "CATCH_ENABLE_CMAKE_HELPER_TESTS": "ON" } diff --git a/catch2/MAINTAINERS.md b/catch2/MAINTAINERS.md new file mode 100644 index 0000000..574418a --- /dev/null +++ b/catch2/MAINTAINERS.md @@ -0,0 +1,11 @@ + +# Catch2 Maintainers + +## Current + +* Chris Thrasher ([@christhrasher](https://github.com/ChrisThrasher)), gpg key: 56FB686C9DFC8E2C +* Martin Hořeňovský ([@horenmar](https://github.com/horenmar)), gpg key: E29C46F3B8A7502860793B7DECC9C20E314B2360 + +## Retired + +* Phil Nash ([@philsquared](https://github.com/philsquared)) diff --git a/catch2/MODULE.bazel b/catch2/MODULE.bazel index 628d77a..8ee125b 100644 --- a/catch2/MODULE.bazel +++ b/catch2/MODULE.bazel @@ -1,4 +1,5 @@ module(name = "catch2") bazel_dep(name = "bazel_skylib", version = "1.7.1") -bazel_dep(name = "rules_cc", version = "0.0.17") +bazel_dep(name = "rules_cc", version = "0.1.1") +bazel_dep(name = "rules_license", version = "1.0.0") diff --git a/catch2/README.md b/catch2/README.md index 3ea54a5..ebd6bfd 100644 --- a/catch2/README.md +++ b/catch2/README.md @@ -1,5 +1,16 @@ -![Catch2 logo](data/artwork/catch2-logo-small-with-background.png) + + + + + + +
+
+
Special thanks to:
+ +
+
[![Github Releases](https://img.shields.io/github/release/catchorg/catch2.svg)](https://github.com/catchorg/catch2/releases) [![Linux build status](https://github.com/catchorg/Catch2/actions/workflows/linux-simple-builds.yml/badge.svg)](https://github.com/catchorg/Catch2/actions/workflows/linux-simple-builds.yml) diff --git a/catch2/benchmarks/CMakeLists.txt b/catch2/benchmarks/CMakeLists.txt new file mode 100644 index 0000000..6883778 --- /dev/null +++ b/catch2/benchmarks/CMakeLists.txt @@ -0,0 +1,16 @@ +include(CatchMiscFunctions) + +add_executable(AssertionsFastPath + runtime_assertion_benches.cpp +) + +add_executable(AssertionsSlowPath + runtime_assertion_benches.cpp + assertion_listener.cpp +) + +target_link_libraries(AssertionsFastPath PRIVATE Catch2::Catch2WithMain) +target_link_libraries(AssertionsSlowPath PRIVATE Catch2::Catch2WithMain) + +list(APPEND CATCH_TEST_TARGETS AssertionsFastPath AssertionsSlowPath) +set(CATCH_TEST_TARGETS ${CATCH_TEST_TARGETS} PARENT_SCOPE) diff --git a/catch2/benchmarks/assertion_listener.cpp b/catch2/benchmarks/assertion_listener.cpp new file mode 100644 index 0000000..2aa65b4 --- /dev/null +++ b/catch2/benchmarks/assertion_listener.cpp @@ -0,0 +1,28 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +#include +#include + +/** + * Event listener that listens to all assertions, forcing assertion slow path + */ +class AssertionSlowPathListener : public Catch::EventListenerBase { +public: + static std::string getDescription() { + return "Validates ordering of Catch2's listener events"; + } + + AssertionSlowPathListener(Catch::IConfig const* config) : + EventListenerBase(config) { + m_preferences.shouldReportAllAssertions = true; + m_preferences.shouldReportAllAssertionStarts = true; + } +}; + +CATCH_REGISTER_LISTENER( AssertionSlowPathListener ) diff --git a/catch2/benchmarks/runtime_assertion_benches.cpp b/catch2/benchmarks/runtime_assertion_benches.cpp new file mode 100644 index 0000000..6a28e3f --- /dev/null +++ b/catch2/benchmarks/runtime_assertion_benches.cpp @@ -0,0 +1,27 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +#include + +TEST_CASE("Simple REQUIRE - 10M") { + for (size_t i = 0; i < 10'000'000; ++i) { + REQUIRE(true); + } +} + +TEST_CASE("Simple NOTHROW - 10M") { + for (size_t i = 0; i < 10'000'000; ++i) { + REQUIRE_NOTHROW([](){}()); + } +} + +TEST_CASE("Simple THROWS - 10M") { + for (size_t i = 0; i < 10'000'000; ++i) { + REQUIRE_THROWS([]() { throw 1; }()); + } +} diff --git a/catch2/data/artwork/catch2-c-logo.png b/catch2/data/artwork/catch2-c-logo.png deleted file mode 100644 index b1066b8..0000000 Binary files a/catch2/data/artwork/catch2-c-logo.png and /dev/null differ diff --git a/catch2/data/artwork/catch2-c-logo.svg b/catch2/data/artwork/catch2-c-logo.svg new file mode 100644 index 0000000..2c73698 --- /dev/null +++ b/catch2/data/artwork/catch2-c-logo.svg @@ -0,0 +1,105 @@ + + + + diff --git a/catch2/data/artwork/catch2-hand-logo.png b/catch2/data/artwork/catch2-hand-logo.png deleted file mode 100644 index ab857ea..0000000 Binary files a/catch2/data/artwork/catch2-hand-logo.png and /dev/null differ diff --git a/catch2/data/artwork/catch2-hand-logo.svg b/catch2/data/artwork/catch2-hand-logo.svg new file mode 100644 index 0000000..3b24df1 --- /dev/null +++ b/catch2/data/artwork/catch2-hand-logo.svg @@ -0,0 +1,83 @@ + + + + diff --git a/catch2/data/artwork/catch2-logo-full-with-background.svg b/catch2/data/artwork/catch2-logo-full-with-background.svg new file mode 100644 index 0000000..fce859d --- /dev/null +++ b/catch2/data/artwork/catch2-logo-full-with-background.svg @@ -0,0 +1,104 @@ + + + + diff --git a/catch2/data/artwork/catch2-logo-full.svg b/catch2/data/artwork/catch2-logo-full.svg new file mode 100644 index 0000000..03bf15b --- /dev/null +++ b/catch2/data/artwork/catch2-logo-full.svg @@ -0,0 +1,88 @@ + + + + diff --git a/catch2/data/artwork/catch2-logo-small-with-background.png b/catch2/data/artwork/catch2-logo-small-with-background.png deleted file mode 100644 index 963eaf4..0000000 Binary files a/catch2/data/artwork/catch2-logo-small-with-background.png and /dev/null differ diff --git a/catch2/data/artwork/catch2-logo-small.png b/catch2/data/artwork/catch2-logo-small.png deleted file mode 100644 index 742e81e..0000000 Binary files a/catch2/data/artwork/catch2-logo-small.png and /dev/null differ diff --git a/catch2/data/sponsors/github_repo_sponsorship.png b/catch2/data/sponsors/github_repo_sponsorship.png new file mode 100644 index 0000000..1d7be47 Binary files /dev/null and b/catch2/data/sponsors/github_repo_sponsorship.png differ diff --git a/catch2/docs/Readme.md b/catch2/docs/Readme.md index d84b4bf..f423050 100644 --- a/catch2/docs/Readme.md +++ b/catch2/docs/Readme.md @@ -32,6 +32,7 @@ Once you're up and running consider the following reference material. * [CMake integration](cmake-integration.md#top) * [Tooling integration (CI, test runners, other)](ci-and-misc.md#top) * [Known limitations](limitations.md#top) +* [Thread safety in Catch2](thread-safety.md#top) **Other:** * [Why Catch2?](why-catch.md#top) diff --git a/catch2/docs/ci-and-misc.md b/catch2/docs/ci-and-misc.md index 49bbd98..879a15f 100644 --- a/catch2/docs/ci-and-misc.md +++ b/catch2/docs/ci-and-misc.md @@ -66,17 +66,24 @@ test execution. Specifically it understands * JUnit output path via `XML_OUTPUT_FILE` * Test filtering via `TESTBRIDGE_TEST_ONLY` * Test sharding via `TEST_SHARD_INDEX`, `TEST_TOTAL_SHARDS`, and `TEST_SHARD_STATUS_FILE` + * Creating a file to signal premature test exit via `TEST_PREMATURE_EXIT_FILE` + * Setting the RNG seed via `TEST_RANDOM_SEED` > Support for `XML_OUTPUT_FILE` was [introduced](https://github.com/catchorg/Catch2/pull/2399) in Catch2 3.0.1 > Support for `TESTBRIDGE_TEST_ONLY` and sharding was introduced in Catch2 3.2.0 +> Support for `TEST_PREMATURE_EXIT_FILE` and `TEST_RANDOM_SEED` was introduced in Catch2 3.11.0 + This integration is enabled via either a [compile time configuration option](configuration.md#bazel-support), or via `BAZEL_TEST` environment variable set to "1". > Support for `BAZEL_TEST` was [introduced](https://github.com/catchorg/Catch2/pull/2459) in Catch2 3.1.0 +Note that if both the Bazel environment var and command line option for +something are used, the environment variable wins. + ## Low-level tools diff --git a/catch2/docs/cmake-integration.md b/catch2/docs/cmake-integration.md index cfb9853..e63e67f 100644 --- a/catch2/docs/cmake-integration.md +++ b/catch2/docs/cmake-integration.md @@ -52,7 +52,7 @@ Include(FetchContent) FetchContent_Declare( Catch2 GIT_REPOSITORY https://github.com/catchorg/Catch2.git - GIT_TAG v3.4.0 # or a later release + GIT_TAG v3.8.1 # or a later release ) FetchContent_MakeAvailable(Catch2) diff --git a/catch2/docs/command-line.md b/catch2/docs/command-line.md index 7e69bf1..690dcaa 100644 --- a/catch2/docs/command-line.md +++ b/catch2/docs/command-line.md @@ -32,6 +32,7 @@ [Test Sharding](#test-sharding)
[Allow running the binary without tests](#allow-running-the-binary-without-tests)
[Output verbosity](#output-verbosity)
+[Create file to guard against silent early termination](#create-file-to-guard-against-silent-early-termination)
Catch works quite nicely without any command line options at all - but for those times when you want greater control the following options are available. Click one of the following links to take you straight to that option - or scroll on to browse the available options. @@ -123,7 +124,7 @@ specs. You can: This allows test cases that are tagged with **either** "[some-tag]" **or** "[other-tag]". A test case with both will obviously also pass the filter. - Note that commas take precendence over simple concatenation. This means + Note that commas take precedence over simple concatenation. This means that `[a][b],[c]` accepts tests that are tagged with either both "[a]" and "[b]", or tests that are tagged with just "[c]". @@ -398,18 +399,24 @@ use test specs to filter this list down to what you want first. Test cases are ordered one of three ways: ### decl -Declaration order (this is the default order if no --order argument is provided). +Declaration order. + Tests in the same translation unit are sorted using their declaration orders, different TUs are sorted in an implementation (linking) dependent order. ### lex -Lexicographic order. Tests are sorted by their name, their tags are ignored. +Lexicographic order. + +Tests are sorted by their name, their tags are ignored. ### rand +Randomized order. The default order. -Randomly ordered. The order is dependent on Catch2's random seed (see +> Randomized order has been made default in Catch2 3.9.0 + +The order is dependent on Catch2's random seed (see [`--rng-seed`](#rng-seed)), and is subset invariant. What this means is that as long as the random seed is fixed, running only some tests (e.g. via tag) does not change their relative order. @@ -643,6 +650,21 @@ ignored. Verbosity defaults to _normal_. +## Create file to guard against silent early termination +
--premature-exit-guard-file <path>
+ +> Introduced in Catch2 3.11.0 + +Tells Catch2 to create an empty file at specified path before the tests +start, and delete it after the tests finish. If the file is present after +the process stops, it can be assumed that the testing binary exited +prematurely, e.g. due to the OOM killer. + +All directories in the path must already exist. If this option is used +and Catch2 cannot create the file (e.g. the location is not writable), +the test run will fail. + + --- [Home](Readme.md#top) diff --git a/catch2/docs/configuration.md b/catch2/docs/configuration.md index f268ba5..f63a6d4 100644 --- a/catch2/docs/configuration.md +++ b/catch2/docs/configuration.md @@ -14,8 +14,10 @@ [Other toggles](#other-toggles)
[Enabling stringification](#enabling-stringification)
[Disabling exceptions](#disabling-exceptions)
+[Disabling deprecation warnings](#disabling-deprecation-warnings)
[Overriding Catch's debug break (`-b`)](#overriding-catchs-debug-break--b)
[Static analysis support](#static-analysis-support)
+[Experimental thread safety](#experimental-thread-safety)
Catch2 is designed to "just work" as much as possible, and most of the configuration options below are changed automatically during compilation, @@ -164,7 +166,7 @@ by using `_NO_` in the macro, e.g. `CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS`. > `CATCH_CONFIG_GETENV` was [introduced](https://github.com/catchorg/Catch2/pull/2562) in Catch2 3.2.0 -> `CATCH_CONFIG_USE_BUILTIN_CONSTANT_P` was introduced in Catch2 vX.Y.Z +> `CATCH_CONFIG_USE_BUILTIN_CONSTANT_P` was introduced in Catch2 3.8.0 Currently Catch enables `CATCH_CONFIG_WINDOWS_SEH` only when compiled with MSVC, because some versions of MinGW do not have the necessary Win32 API support. @@ -263,6 +265,21 @@ namespace Catch { } ``` + +## Disabling deprecation warnings + +> Introduced in Catch2 3.9.0 + +Catch2 has started using the C++ macro `[[deprecated]]` to mark things +that are deprecated and should not be used any more. If you need to +temporarily disable these warnings, use + + CATCH_CONFIG_NO_DEPRECATION_ANNOTATIONS + +Catch2 currently does not support more fine-grained deprecation warning +control, nor do we plan to. + + ## Overriding Catch's debug break (`-b`) > [Introduced](https://github.com/catchorg/Catch2/pull/1846) in Catch2 2.11.2. @@ -299,6 +316,21 @@ no backwards compatibility guarantees._ are not meant to be runnable, only "scannable". +## Experimental thread safety + +> Introduced in Catch2 3.9.0 + +Catch2 can optionally support thread-safe assertions, that means, multiple +user-spawned threads can use the assertion macros at the same time. Due +to the performance cost this imposes even on single-threaded usage, Catch2 +defaults to non-thread-safe assertions. + + CATCH_CONFIG_EXPERIMENTAL_THREAD_SAFE_ASSERTIONS // enables thread safe assertions + CATCH_CONFIG_NO_EXPERIMENTAL_THREAD_SAFE_ASSERTIONS // force-disables thread safe assertions + +See [the documentation on thread safety in Catch2](thread-safety.md#top) +for details on which macros are safe and other notes. + --- diff --git a/catch2/docs/deprecations.md b/catch2/docs/deprecations.md index 0b5bee1..20312cd 100644 --- a/catch2/docs/deprecations.md +++ b/catch2/docs/deprecations.md @@ -38,7 +38,7 @@ macro](skipping-passing-failing.md#top). ### Non-const function for `TEST_CASE_METHOD` -> Deprecated in Catch2 vX.Y.Z +> Deprecated in Catch2 3.7.0 Currently, the member function generated for `TEST_CASE_METHOD` is not `const` qualified. In the future, the generated member function will diff --git a/catch2/docs/generators.md b/catch2/docs/generators.md index eb1a255..000b200 100644 --- a/catch2/docs/generators.md +++ b/catch2/docs/generators.md @@ -21,7 +21,10 @@ The "Generators" `TEST_CASE` will be entered 3 times, and the value of `i` will be 1, 3, and 5 in turn. `GENERATE`s can also be used multiple times at the same scope, in which case the result will be a cartesian product of all elements in the generators. This means that in the snippet -below, the test case will be run 6 (2\*3) times. +below, the test case will be run 6 (2\*3) times. The `GENERATE` macro +is defined in the `catch_generators.hpp` header, so compiling +the code examples below also requires +`#include `. ```cpp TEST_CASE("Generators") { @@ -103,7 +106,7 @@ a test case, * 2 fundamental generators * `SingleValueGenerator` -- contains only single element * `FixedValuesGenerator` -- contains multiple elements -* 5 generic generators that modify other generators +* 5 generic generators that modify other generators (defined in `catch2/generators/catch_generators_adapters.hpp`) * `FilterGenerator` -- filters out elements from a generator for which the predicate returns "false" * `TakeGenerator` -- takes first `n` elements from a generator @@ -111,9 +114,10 @@ a test case, * `MapGenerator` -- returns the result of applying `Func` on elements from a different generator * `ChunkGenerator` -- returns chunks (inside `std::vector`) of n elements from a generator -* 4 specific purpose generators +* 2 random generators (defined in `catch2/generators/catch_generators_random.hpp`) * `RandomIntegerGenerator` -- generates random Integrals from range * `RandomFloatGenerator` -- generates random Floats from range +* 2 range generators (defined in `catch2/generators/catch_generators_range.hpp`) * `RangeGenerator(first, last)` -- generates all values inside a `[first, last)` arithmetic range * `IteratorGenerator` -- copies and returns values from an iterator range @@ -216,8 +220,8 @@ For floating point generators, the situation is much more complex. Generally Catch2 only promises reproducibility (or even just correctness!) on platforms that obey the IEEE-754 standard. Furthermore, reproducibility only applies between binaries that perform floating point math in the -same way, e.g. if you compile a binary targetting the x87 FPU and another -one targetting SSE2 for floating point math, their results will vary. +same way, e.g. if you compile a binary targeting the x87 FPU and another +one targeting SSE2 for floating point math, their results will vary. Similarly, binaries compiled with compiler flags that relax the IEEE-754 adherence, e.g. `-ffast-math`, might provide different results than those compiled for strict IEEE-754 adherence. diff --git a/catch2/docs/limitations.md b/catch2/docs/limitations.md index f5f60ba..67085a8 100644 --- a/catch2/docs/limitations.md +++ b/catch2/docs/limitations.md @@ -57,40 +57,6 @@ again. ## Features This section outlines some missing features, what is their status and their possible workarounds. -### Thread safe assertions -Catch2's assertion macros are not thread safe. This does not mean that -you cannot use threads inside Catch's test, but that only single thread -can interact with Catch's assertions and other macros. - -This means that this is ok -```cpp - std::vector threads; - std::atomic cnt{ 0 }; - for (int i = 0; i < 4; ++i) { - threads.emplace_back([&]() { - ++cnt; ++cnt; ++cnt; ++cnt; - }); - } - for (auto& t : threads) { t.join(); } - REQUIRE(cnt == 16); -``` -because only one thread passes the `REQUIRE` macro and this is not -```cpp - std::vector threads; - std::atomic cnt{ 0 }; - for (int i = 0; i < 4; ++i) { - threads.emplace_back([&]() { - ++cnt; ++cnt; ++cnt; ++cnt; - CHECK(cnt == 16); - }); - } - for (auto& t : threads) { t.join(); } - REQUIRE(cnt == 16); -``` - -We currently do not plan to support thread-safe assertions. - - ### Process isolation in a test Catch does not support running tests in isolated (forked) processes. While this might in the future, the fact that Windows does not support forking and only allows full-on process creation and the desire to keep code as similar as possible across platforms, mean that this is likely to take significant development time, that is not currently available. @@ -187,5 +153,5 @@ but only when compiled with a C++20 conforming compiler. MSVC is currently not conformant enough, but `clang-cl` will compile the assertion above using MSVC STL without problem. -This change got in with MSVC v19.37](https://godbolt.org/z/KG9obzdvE). +[This change got in with MSVC v19.37](https://godbolt.org/z/KG9obzdvE). diff --git a/catch2/docs/logging.md b/catch2/docs/logging.md index 7970938..1da9774 100644 --- a/catch2/docs/logging.md +++ b/catch2/docs/logging.md @@ -1,32 +1,30 @@ # Logging macros -Additional messages can be logged during a test case. Note that the messages logged with `INFO` are scoped and thus will not be reported if failure occurs in scope preceding the message declaration. An example: +Catch2 provides various macros for logging extra information when +running a test. These macros default to being scoped, and associate with +all assertions in the scope, regardless of whether they pass or fail. +**example** ```cpp -TEST_CASE("Foo") { +TEST_CASE("Simple info") { INFO("Test case start"); - for (int i = 0; i < 2; ++i) { - INFO("The number is " << i); - CHECK(i == 0); + SECTION("A") { + INFO("Section A"); + CHECK(false); // 1 } -} - -TEST_CASE("Bar") { - INFO("Test case start"); - for (int i = 0; i < 2; ++i) { - INFO("The number is " << i); - CHECK(i == i); + SECTION("B") { + INFO("Section B"); + CHECK(false); // 2 } - CHECK(false); + CHECK(false); // 3 } ``` -When the `CHECK` fails in the "Foo" test case, then two messages will be printed. -``` -Test case start -The number is 1 -``` -When the last `CHECK` fails in the "Bar" test case, then only one message will be printed: `Test case start`. +The first assertion will report messages "Test case start", and "Section A" +as extra information. The second one will report messages "Test case +started" and "Section B", while the third one will only report "Test case +started" as the extra info. + ## Logging without local scope diff --git a/catch2/docs/own-main.md b/catch2/docs/own-main.md index 26dfa86..4cc21b1 100644 --- a/catch2/docs/own-main.md +++ b/catch2/docs/own-main.md @@ -57,17 +57,18 @@ int main( int argc, char* argv[] ) { int returnCode = session.applyCommandLine( argc, argv ); if( returnCode != 0 ) // Indicates a command line error - return returnCode; + return returnCode; // writing to session.configData() or session.Config() here // overrides command line args // only do this if you know you need to - int numFailed = session.run(); + returnCode = session.run(); + + // returnCode encodes the type of error that occured. See the + // integer constants in catch_session.hpp for more information + // on what each return code means. - // numFailed is clamped to 255 as some unices only use the lower 8 bits. - // This clamping has already been applied, so just return it here - // You can also do any post run clean-up here return numFailed; } ``` diff --git a/catch2/docs/release-notes.md b/catch2/docs/release-notes.md index a393a52..9da1a2e 100644 --- a/catch2/docs/release-notes.md +++ b/catch2/docs/release-notes.md @@ -2,6 +2,10 @@ # Release notes **Contents**
+[3.11.0](#3110)
+[3.10.0](#3100)
+[3.9.1](#391)
+[3.9.0](#390)
[3.8.1](#381)
[3.8.0](#380)
[3.7.1](#371)
@@ -67,6 +71,93 @@ [Even Older versions](#even-older-versions)
+## 3.11.0 + +### Fixes +* Fixed building on non-desktop GDK platforms (#3029) +* Fixed message macros being susceptible to race in specific scenario (#3031) +* Catch2's SEH filter will call the previously installed filter after reporting the error (#3033) + +### Improvements +* Handling of scoped messages (e.g. `CAPTURE`) is a bit faster. +* Better out-of-the-box support for QNX (#2953) +* Improved performance of assertions by up-to 10% + * Release mode assertion fast-path sees the biggest improvement. +* Faster processing of non-escaped strings in `--invisibles` mode. +* Added support for Bazel's `TEST_RANDOM_SEED` env var (#3021) +* Added support for Bazel's `TEST_PREMATURE_EXIT_FILE` env var (#3020) + * This creates a file that is deleted if the tests exit normally, but stays around if the process dies unexpectedly. + * This functionality is also exposed through CLI as `--premature-exit-guard-file` + +### Miscellaneous +* **[Tuple.app](https://tuple.app/catch2) has sponsored Catch2** + + +## 3.10.0 + +### Fixes +* pkg-config files will take `DESTDIR` env var into account when selecting install destination (#3006, #3019) +* Changed `filter` to store the provided predicate by value (#3002, #3005) + * This is done to avoid dangling-by-default behaviour when `filter` is used inside `GENERATE_COPY`/`GENERATE_REF`. + +### Improvements +* Escaping XML and JSON output is faster when the strings do not need escaping. + * The improvement starts at about 3x throughput, up to 10x for long strings. +* Message macros (`INFO`, `CAPTURE`, `WARN`, `SUCCEED`, etc) are now thread safe. + + +## 3.9.1 + +### Fixes +* Fixed bad error reporting for multiple nested assertions (#1292) +* Fixed W4702 (unreachable code) in the polyfill for std::unreachable (#3007) +* Fixed decomposition of assertions comparing enum-backed bitfields (#3001) +* Fixed StringMaker specialization for `time_point` with non-default duration type (#2685) + +### Improvements +* Exceptions thrown during stringification of decomposed expression no longer fail the assertion (#2980) +* The selection logic for `CATCH_TRAP` prefers `__builtin_debugtrap` on all platforms when Catch2 is compiled with Clang + + +## 3.9.0 + +### Improvements +* **Added experimental opt-in support for thread safe assertions** + * Read the documentation for full details +* **The default test run order has been changed to random** +* Passing assertions are significantly faster when the reporter does not ask for `assertionEnded` events on passing assertions. + * This is the default behaviour of e.g. Console or Compact reporter + * Simple `REQUIRE(true)` is 60% faster in Release and 80% faster in Debug build configuration + * Simple `REQUIRE_NOTHROW` is 230% faster in Release and 430% faster in Debug build configuration + * Simple `REQUIRE_THROWS` is ~3% faster in Release and 20% faster in Debug build configuration (throwing introduces enough overhead that the optimizations inside Catch2 are mostly irrelevant) +* Small (2-5%) improvement if the reporter asks for `assertionEnded` events for passing assertions. +* The exit code constants are part of the Session API. (#2955, #2976) +* Suppressed unsigned integer overflow checking in locations with intended overflow (#2965) +* Reporters flush output after writing metadata, e.g. rng seed (#2964) +* Added unreachable after `FAIL` and `SKIP` macros (#2941) + * This allows the compiler to understand that the execution does not continue past the macro, and avoids warnings. +* Added fast path for `assertionStarting` event when no reporter requires it + * For backwards compatibility, this fast path is opt-in + * A reporter can opt in by changing its `ReporterPreferences::shouldReportAllAssertionStarts` +* Improved last seen source location tracking to be more precise + * This is used when reporting unexpected exceptions from tests + +### Fixes +* Fixed formatting of tags with more than 100 tests in the default `--list-tags` output (#2963) +* Fixed Clang-Tidy's `readability-static-accessed-through-instance` in tests +* Fixed most of Clang-Tidy's `cppcoreguidelines-avoid-non-const-global-variables` (#2582) +* The lifetime of scoped messages now strictly obeys their scope (#1759, #2019, #2959) + * Previously Catch2 would try to keep them around during unexpected exception, to provide helpful context. + * The amount of surprises the irregularities caused was not worth the occasional utility provided. +* `TEMPLATE_TEST_CASE_SIG` can handle signatures consisting of only types (#2680, #2995) +* Moved `catch_test_run_info.hpp` up from `internal/` subfolder into the main one (#2972) + +### Miscellaneous +* pkg-config files are now generated at install time (#2979) + * This fixes missing debug suffix in library names + * This fixes install prefix mismatch between build config and actuall installation + + ## 3.8.1 ### Fixes @@ -93,7 +184,7 @@ * Removed redundant `CTEST_FILE` param when creating the indirection file for `PRE_TEST` discovery mode (#2936) * Rewrote the test discovery logic to use output from the JSON reporter * This means that `catch_discover_tests` now requires CMake 3.19 or newer - * Added `ADD_TAGS_AS_LABELS` option. If specified, each CTest test will be labeled with corrensponding Catch2's test tag + * Added `ADD_TAGS_AS_LABELS` option. If specified, each CTest test will be labeled with corresponding Catch2's test tag * Bumped up the minimum required CMake version to build Catch2 to 3.16 * Meson build now provides option to avoid installing Catch2 * Bazel build is moved to Bzlmod. @@ -175,7 +266,7 @@ ### Improvements * Reintroduced support for GCC 5 and 6 (#2836) * As with VS2017, if they start causing trouble again, they will be dropped again. -* Added workaround for targetting newest MacOS (Sonoma) using GCC (#2837, #2839) +* Added workaround for targeting newest MacOS (Sonoma) using GCC (#2837, #2839) * `CATCH_CONFIG_DEFAULT_REPORTER` can now be an arbitrary reporter spec * Previously it could only be a plain reporter name, so it was impossible to compile in custom arguments to the reporter. * Improved performance of generating 64bit random integers by 20+% diff --git a/catch2/docs/reporters.md b/catch2/docs/reporters.md index 20ef5e5..d42648c 100644 --- a/catch2/docs/reporters.md +++ b/catch2/docs/reporters.md @@ -154,7 +154,7 @@ and calls itself "partial" reporter, so it can be invoked with Each reporter instance contains instance of `ReporterPreferences`, a type that holds flags for the behaviour of Catch2 when this reporter run. -Currently there are two customization options: +Currently there are three customization options: * `shouldRedirectStdOut` - whether the reporter wants to handle writes to stdout/stderr from user code, or not. This is useful for @@ -165,6 +165,11 @@ Currently there are two customization options: assertions. Usually reporters do not report successful assertions and don't need them for their output, but sometimes the desired output format includes passing assertions even without the `-s` flag. +* `shouldReportAllAssertionStarts` - whether the reporter wants to handle + `assertionStarting` events. Most reporters do not, and opting out + explicitly enables a fast-path in Catch2's handling of assertions. + +> `shouldReportAllAssertionStarts` was introduced in Catch2 3.9.0 ### Per-reporter configuration diff --git a/catch2/docs/skipping-passing-failing.md b/catch2/docs/skipping-passing-failing.md index 52bb18f..1bdc1f0 100644 --- a/catch2/docs/skipping-passing-failing.md +++ b/catch2/docs/skipping-passing-failing.md @@ -52,6 +52,20 @@ TEST_CASE("failing test") { } ``` +Same applies for a `SKIP` nested inside an assertion: + +```cpp +static bool do_skip() { + SKIP(); + return true; +} + +TEST_CASE("Another failing test") { + CHECK(do_skip()); +} +``` + + ### Interaction with Sections and Generators Sections, nested sections as well as specific outputs from [generators](generators.md#top) diff --git a/catch2/docs/test-fixtures.md b/catch2/docs/test-fixtures.md index 653b50e..9496dd1 100644 --- a/catch2/docs/test-fixtures.md +++ b/catch2/docs/test-fixtures.md @@ -4,7 +4,7 @@ **Contents**
[Non-Templated test fixtures](#non-templated-test-fixtures)
[Templated test fixtures](#templated-test-fixtures)
-[Signature-based parameterised test fixtures](#signature-based-parametrised-test-fixtures)
+[Signature-based parameterised test fixtures](#signature-based-parameterised-test-fixtures)
[Template fixtures with types specified in template type lists](#template-fixtures-with-types-specified-in-template-type-lists)
## Non-Templated test fixtures @@ -130,7 +130,7 @@ TEST_CASE_PERSISTENT_FIXTURE( MyFixture, "Tests with MyFixture" ) { } ``` -This example demonstates two possible use-cases of this fixture type: +This example demonstrates two possible use-cases of this fixture type: 1. Improve test run times by reducing the amount of expensive and redundant setup and tear-down required. 2. Reusing results from the previous partial run, in the current diff --git a/catch2/docs/thread-safety.md b/catch2/docs/thread-safety.md new file mode 100644 index 0000000..e0092de --- /dev/null +++ b/catch2/docs/thread-safety.md @@ -0,0 +1,229 @@ + +# Thread safety in Catch2 + +**Contents**
+[Using assertion macros from spawned threads](#using-assertion-macros-from-spawned-threads)
+[Assertion-like message macros and spawned threads](#assertion-like-message-macros-and-spawned-threads)
+[Message macros and spawned threads](#message-macros-and-spawned-threads)
+[examples](#examples)
+[`STATIC_REQUIRE` and `STATIC_CHECK`](#static_require-and-static_check)
+[Fatal errors and multiple threads](#fatal-errors-and-multiple-threads)
+[Performance overhead](#performance-overhead)
+ +> Thread safe assertions were introduced in Catch2 3.9.0 + +Thread safety in Catch2 is currently limited to all the assertion macros, +and to message or message-adjacent macros (e.g. `INFO` or `WARN`). + +Interacting with benchmark macros, sections macros, generator macros, or +test case macros is not thread-safe. The way sections define paths through +the test is incompatible with user spawning threads arbitrarily, so this +limitation is here to stay. + +**Important: thread safety in Catch2 is [opt-in](configuration.md#experimental-thread-safety)** + + +## Using assertion macros from spawned threads + +The full set of Catch2's runtime assertion macros is thread-safe. However, +it is important to keep in mind that their semantics might not support +being used from user-spawned threads. + +Specifically, the `REQUIRE` family of assertion macros have semantics +of stopping the test execution on failure. This is done by throwing +an exception, but since the user-spawned thread will not have the test-level +try-catch block ready to catch the test failure exception, failing a +`REQUIRE` assertion inside user-spawned thread will terminate the process. + +The `CHECK` family of assertions does not have this issue, because it +does not try to stop the test execution. + +Note that `CHECKED_IF` and `CHECKED_ELSE` are also thread safe (internally +they are assertion macro + an if). + + +## Assertion-like message macros and spawned threads + +> Assertion-like messages were made thread safe in Catch2 3.10.0 + +Similarly to assertion macros, not all assertion-like message macros can +be used from spawned thread. + +`SKIP` and `FAIL` macros stop the test execution. Just like with `REQUIRE`, +this means that they cannot be used inside user-spawned threads. `SUCCEED`, +`FAIL_CHECK` and `WARN` do not attempt to stop the test execution and +thus can be used from any thread. + + +## Message macros and spawned threads + +> Message macros were made thread safe in Catch2 3.10.0 + +Macros that add extra messages to following assertion, such as `INFO` +or `CAPTURE`, are all thread safe and can be used in any thread. Note +that these messages are per-thread, and thus `INFO` inside a user-spawned +thread will not be seen by the main thread, and vice versa. + + +## examples + +### `REQUIRE` from the main thread, `CHECK` from spawned threads + +```cpp +TEST_CASE( "Failed REQUIRE in the main thread is fine" ) { + std::vector threads; + for ( size_t t = 0; t < 16; ++t) { + threads.emplace_back( []() { + for (size_t i = 0; i < 10'000; ++i) { + CHECK( true ); + CHECK( false ); + } + } ); + } + + REQUIRE( false ); +} +``` +This will work as expected, that is, the process will finish running +normally, the test case will fail and there will be the correct count of +passing and failing assertions (160000 and 160001 respectively). However, +it is important to understand that when the main thread fails its assertion, +the spawned threads will keep running. + + +### `REQUIRE` from spawned threads + +```cpp +TEST_CASE( "Successful REQUIRE in spawned thread is fine" ) { + std::vector threads; + for ( size_t t = 0; t < 16; ++t) { + threads.emplace_back( []() { + for (size_t i = 0; i < 10'000; ++i) { + REQUIRE( true ); + } + } ); + } +} +``` +This will also work as expected, because the `REQUIRE` is successful. + +```cpp +TEST_CASE( "Failed REQUIRE in spawned thread kills the process" ) { + std::vector threads; + for ( size_t t = 0; t < 16; ++t) { + threads.emplace_back( []() { + for (size_t i = 0; i < 10'000; ++i) { + REQUIRE( false ); + } + } ); + } +} +``` +This will fail catastrophically and terminate the process. + + +### INFO across threads + +```cpp +TEST_CASE( "messages don't cross threads" ) { + std::jthread t1( [&]() { + for ( size_t i = 0; i < 100; ++i ) { + INFO( "spawned thread #1" ); + CHECK( 1 == 1 ); + } + } ); + + std::thread t2( [&]() { + for (size_t i = 0; i < 100; ++i) { + UNSCOPED_INFO( "spawned thread #2" ); + } + } ); + + for (size_t i = 0; i < 100; ++i) { + CHECK( 1 == 2 ); + } +} +``` +None of the failed checks will show the "spawned thread #1" message, as +that message is for the `t1` thread. If the reporter shows passing +assertions (e.g. due to the tests being run with `-s`), you will see the +"spawned thread #1" message alongside the passing `CHECK( 1 == 1 )` assertion. + +The message "spawned thread #2" will never be shown, because there are no +assertions in `t2`. + + +### FAIL/SKIP from the main thread + +```cpp +TEST_CASE( "FAIL in the main thread is fine" ) { + std::vector threads; + for ( size_t t = 0; t < 16; ++t) { + threads.emplace_back( []() { + for (size_t i = 0; i < 10; ++i) { + CHECK( true ); + CHECK( false ); + } + } ); + } + + FAIL(); +} +``` + +This will work as expected, that is, the process will finish running +normally, the test case will fail and there will be 321 total assertions, +160 passing and 161 failing (`FAIL` counts as failed assertion). + +However, when the main thread hits `FAIL`, it will wait for the other +threads to finish due to `std::jthread`'s destructor joining the spawned +thread. Due to this, using `SKIP` is not recommended once more threads +are spawned; while the main thread will bail from the test execution, +the spawned threads will keep running and may fail the test case. + + +### FAIL/SKIP from spawned threads + +```cpp +TEST_CASE( "FAIL/SKIP in spawned thread kills the process" ) { + std::vector threads; + for ( size_t t = 0; t < 16; ++t) { + threads.emplace_back( []() { + for (size_t i = 0; i < 10'000; ++i) { + FAIL(); + } + } ); + } +} +``` +As with failing `REQUIRE`, both `FAIL` and `SKIP` in spawned threads +terminate the process. + + +## `STATIC_REQUIRE` and `STATIC_CHECK` + +All of `STATIC_REQUIRE`, `STATIC_REQUIRE_FALSE`, `STATIC_CHECK`, and +`STATIC_CHECK_FALSE` are thread safe in the delayed evaluation configuration. + + +## Fatal errors and multiple threads + +By default, Catch2 tries to catch fatal errors (POSIX signals/Windows +Structured Exceptions) and report something useful to the user. This +always happened on a best-effort basis, but in presence of multiple +threads and locks the chance of it working decreases. If this starts +being an issue for you, [you can disable it](configuration.md#other-toggles). + + +## Performance overhead + +In the worst case, which is optimized build and assertions using the +fast path for successful assertions, the performance overhead of using +the thread-safe assertion implementation can reach 40%. In other cases, +the overhead will be smaller, between 4% and 20%. + + + +--- + +[Home](Readme.md#top) diff --git a/catch2/examples/210-Evt-EventListeners.cpp b/catch2/examples/210-Evt-EventListeners.cpp index d05dfaa..d1cfdb4 100644 --- a/catch2/examples/210-Evt-EventListeners.cpp +++ b/catch2/examples/210-Evt-EventListeners.cpp @@ -307,7 +307,7 @@ void print( std::ostream& os, int const level, std::string const& title, Catch:: // 2. My listener and registration: // -char const * dashed_line = +char const * const dashed_line = "--------------------------------------------------------------------------"; diff --git a/catch2/examples/CMakeLists.txt b/catch2/examples/CMakeLists.txt index d45ddfc..74b6599 100644 --- a/catch2/examples/CMakeLists.txt +++ b/catch2/examples/CMakeLists.txt @@ -1,50 +1,47 @@ -cmake_minimum_required( VERSION 3.16 ) - -project( Catch2Examples LANGUAGES CXX ) - -message( STATUS "Examples included" ) +cmake_minimum_required(VERSION 3.16) +project(Catch2Examples LANGUAGES CXX) +message(STATUS "Examples included") # Some one-offs first: # 1) Tests and main in one file -add_executable( 010-TestCase +add_executable(010-TestCase 010-TestCase.cpp ) # 2) Tests and main across two files -add_executable( 020-MultiFile +add_executable(020-MultiFile 020-TestCase-1.cpp 020-TestCase-2.cpp ) add_executable(231-Cfg_OutputStreams - 231-Cfg-OutputStreams.cpp + 231-Cfg-OutputStreams.cpp ) target_link_libraries(231-Cfg_OutputStreams Catch2_buildall_interface) target_compile_definitions(231-Cfg_OutputStreams PUBLIC CATCH_CONFIG_NOSTDOUT) # These examples use the standard separate compilation -set( SOURCES_IDIOMATIC_EXAMPLES - 030-Asn-Require-Check.cpp - 100-Fix-Section.cpp - 110-Fix-ClassFixture.cpp - 111-Fix-PersistentFixture.cpp - 120-Bdd-ScenarioGivenWhenThen.cpp - 210-Evt-EventListeners.cpp - 232-Cfg-CustomMain.cpp - 300-Gen-OwnGenerator.cpp - 301-Gen-MapTypeConversion.cpp - 302-Gen-Table.cpp - 310-Gen-VariablesInGenerators.cpp - 311-Gen-CustomCapture.cpp +set(SOURCES_IDIOMATIC_EXAMPLES + 030-Asn-Require-Check.cpp + 100-Fix-Section.cpp + 110-Fix-ClassFixture.cpp + 111-Fix-PersistentFixture.cpp + 120-Bdd-ScenarioGivenWhenThen.cpp + 210-Evt-EventListeners.cpp + 232-Cfg-CustomMain.cpp + 300-Gen-OwnGenerator.cpp + 301-Gen-MapTypeConversion.cpp + 302-Gen-Table.cpp + 310-Gen-VariablesInGenerators.cpp + 311-Gen-CustomCapture.cpp ) -string( REPLACE ".cpp" "" BASENAMES_IDIOMATIC_EXAMPLES "${SOURCES_IDIOMATIC_EXAMPLES}" ) -set( TARGETS_IDIOMATIC_EXAMPLES ${BASENAMES_IDIOMATIC_EXAMPLES} ) +string(REPLACE ".cpp" "" BASENAMES_IDIOMATIC_EXAMPLES "${SOURCES_IDIOMATIC_EXAMPLES}") +set(TARGETS_IDIOMATIC_EXAMPLES ${BASENAMES_IDIOMATIC_EXAMPLES}) - -foreach( name ${TARGETS_IDIOMATIC_EXAMPLES} ) - add_executable( ${name} ${name}.cpp ) +foreach(name ${TARGETS_IDIOMATIC_EXAMPLES}) + add_executable(${name} ${name}.cpp) endforeach() set(ALL_EXAMPLE_TARGETS @@ -53,10 +50,9 @@ set(ALL_EXAMPLE_TARGETS 020-MultiFile ) -foreach( name ${ALL_EXAMPLE_TARGETS} ) - target_link_libraries( ${name} Catch2WithMain ) +foreach(name ${ALL_EXAMPLE_TARGETS}) + target_link_libraries(${name} Catch2WithMain) endforeach() - -list(APPEND CATCH_WARNING_TARGETS ${ALL_EXAMPLE_TARGETS}) -set(CATCH_WARNING_TARGETS ${CATCH_WARNING_TARGETS} PARENT_SCOPE) +list(APPEND CATCH_TEST_TARGETS ${ALL_EXAMPLE_TARGETS}) +set(CATCH_TEST_TARGETS ${CATCH_TEST_TARGETS} PARENT_SCOPE) diff --git a/catch2/extras/Catch.cmake b/catch2/extras/Catch.cmake index 3d93fe2..fcdebd6 100644 --- a/catch2/extras/Catch.cmake +++ b/catch2/extras/Catch.cmake @@ -165,7 +165,7 @@ function(catch_discover_tests TARGET) ${ARGN} ) - if (${CMAKE_VERSION} VERSION_LESS "3.19") + if(${CMAKE_VERSION} VERSION_LESS "3.19") message(FATAL_ERROR "This script requires JSON support from CMake version 3.19 or greater.") endif() @@ -187,7 +187,7 @@ function(catch_discover_tests TARGET) endif() set(_DISCOVERY_MODE ${CMAKE_CATCH_DISCOVER_TESTS_DISCOVERY_MODE}) endif() - if (NOT _DISCOVERY_MODE MATCHES "^(POST_BUILD|PRE_TEST)$") + if(NOT _DISCOVERY_MODE MATCHES "^(POST_BUILD|PRE_TEST)$") message(FATAL_ERROR "Unknown DISCOVERY_MODE: ${_DISCOVERY_MODE}") endif() @@ -204,7 +204,7 @@ function(catch_discover_tests TARGET) TARGET ${TARGET} PROPERTY CROSSCOMPILING_EMULATOR ) - if (NOT _SKIP_IS_FAILURE) + if(NOT _SKIP_IS_FAILURE) set(_PROPERTIES ${_PROPERTIES} SKIP_RETURN_CODE 4) endif() diff --git a/catch2/extras/CatchAddTests.cmake b/catch2/extras/CatchAddTests.cmake index 2534213..90fbd5e 100644 --- a/catch2/extras/CatchAddTests.cmake +++ b/catch2/extras/CatchAddTests.cmake @@ -136,7 +136,7 @@ function(catch_discover_tests_impl) # Parse JSON output for list of tests/class names/tags string(JSON version GET "${listing_output}" "version") - if (NOT version STREQUAL "1") + if(NOT version STREQUAL "1") message(FATAL_ERROR "Unsupported catch output version: '${version}'") endif() @@ -186,11 +186,11 @@ function(catch_discover_tests_impl) ${properties} ) - if (add_tags) + if(add_tags) string(JSON num_tags LENGTH "${test_tags}") math(EXPR num_tags "${num_tags} - 1") set(tag_list "") - if (num_tags GREATER_EQUAL "0") + if(num_tags GREATER_EQUAL "0") foreach(tag_idx RANGE ${num_tags}) string(JSON a_tag GET "${test_tags}" "${tag_idx}") # Catch2's tags can contain semicolons, which are list element separators diff --git a/catch2/extras/CatchShardTests.cmake b/catch2/extras/CatchShardTests.cmake index 68228f5..89666d6 100644 --- a/catch2/extras/CatchShardTests.cmake +++ b/catch2/extras/CatchShardTests.cmake @@ -11,7 +11,7 @@ # * REPORTER - reporter spec to use for tests # * TEST_SPEC - test spec used for filtering tests function(catch_add_sharded_tests TARGET) - if (${CMAKE_VERSION} VERSION_LESS "3.10.0") + if(${CMAKE_VERSION} VERSION_LESS "3.10.0") message(FATAL_ERROR "add_sharded_catch_tests only supports CMake versions 3.10.0 and up") endif() @@ -23,7 +23,7 @@ function(catch_add_sharded_tests TARGET) ${ARGN} ) - if (NOT DEFINED _SHARD_COUNT) + if(NOT DEFINED _SHARD_COUNT) set(_SHARD_COUNT 2) endif() @@ -61,8 +61,6 @@ function(catch_add_sharded_tests TARGET) -P "${shard_impl_script_file}" VERBATIM ) - - endfunction() diff --git a/catch2/extras/CatchShardTestsImpl.cmake b/catch2/extras/CatchShardTestsImpl.cmake index bb2fc3e..83fac68 100644 --- a/catch2/extras/CatchShardTestsImpl.cmake +++ b/catch2/extras/CatchShardTestsImpl.cmake @@ -25,10 +25,10 @@ if(NOT EXISTS "${TEST_BINARY}") endif() set(other_args "") -if (TEST_SPEC) +if(TEST_SPEC) set(other_args "${other_args} ${TEST_SPEC}") endif() -if (REPORTER_SPEC) +if(REPORTER_SPEC) set(other_args "${other_args} --reporter ${REPORTER_SPEC}") endif() diff --git a/catch2/extras/ParseAndAddCatchTests.cmake b/catch2/extras/ParseAndAddCatchTests.cmake index 31fc193..d7c17ac 100644 --- a/catch2/extras/ParseAndAddCatchTests.cmake +++ b/catch2/extras/ParseAndAddCatchTests.cmake @@ -56,7 +56,7 @@ # # #==================================================================================================# -if (CMAKE_MINIMUM_REQUIRED_VERSION VERSION_LESS 2.8.8) +if(CMAKE_MINIMUM_REQUIRED_VERSION VERSION_LESS 2.8.8) message(FATAL_ERROR "ParseAndAddCatchTests requires CMake 2.8.8 or newer") endif() @@ -67,9 +67,9 @@ option(PARSE_CATCH_TESTS_ADD_TARGET_IN_TEST_NAME "Add target name to the test na option(PARSE_CATCH_TESTS_ADD_TO_CONFIGURE_DEPENDS "Add test file to CMAKE_CONFIGURE_DEPENDS property" OFF) function(ParseAndAddCatchTests_PrintDebugMessage) - if(PARSE_CATCH_TESTS_VERBOSE) - message(STATUS "ParseAndAddCatchTests: ${ARGV}") - endif() + if(PARSE_CATCH_TESTS_VERBOSE) + message(STATUS "ParseAndAddCatchTests: ${ARGV}") + endif() endfunction() # This removes the contents between @@ -90,163 +90,161 @@ endfunction() # Worker function function(ParseAndAddCatchTests_ParseFile SourceFile TestTarget) - # If SourceFile is an object library, do not scan it (as it is not a file). Exit without giving a warning about a missing file. - if(SourceFile MATCHES "\\\$") - ParseAndAddCatchTests_PrintDebugMessage("Detected OBJECT library: ${SourceFile} this will not be scanned for tests.") - return() - endif() - # According to CMake docs EXISTS behavior is well-defined only for full paths. - get_filename_component(SourceFile ${SourceFile} ABSOLUTE) - if(NOT EXISTS ${SourceFile}) - message(WARNING "Cannot find source file: ${SourceFile}") - return() + # If SourceFile is an object library, do not scan it (as it is not a file). Exit without giving a warning about a missing file. + if(SourceFile MATCHES "\\\$") + ParseAndAddCatchTests_PrintDebugMessage("Detected OBJECT library: ${SourceFile} this will not be scanned for tests.") + return() + endif() + # According to CMake docs EXISTS behavior is well-defined only for full paths. + get_filename_component(SourceFile ${SourceFile} ABSOLUTE) + if(NOT EXISTS ${SourceFile}) + message(WARNING "Cannot find source file: ${SourceFile}") + return() + endif() + ParseAndAddCatchTests_PrintDebugMessage("parsing ${SourceFile}") + file(STRINGS ${SourceFile} Contents NEWLINE_CONSUME) + + # Remove block and fullline comments + ParseAndAddCatchTests_RemoveComments(Contents) + + # Find definition of test names + # https://regex101.com/r/JygOND/1 + string(REGEX MATCHALL "[ \t]*(CATCH_)?(TEMPLATE_)?(TEST_CASE_METHOD|SCENARIO|TEST_CASE)[ \t]*\\([ \t\n]*\"[^\"]*\"[ \t\n]*(,[ \t\n]*\"[^\"]*\")?(,[ \t\n]*[^\,\)]*)*\\)[ \t\n]*\{+[ \t]*(//[^\n]*[Tt][Ii][Mm][Ee][Oo][Uu][Tt][ \t]*[0-9]+)*" Tests "${Contents}") + + if(PARSE_CATCH_TESTS_ADD_TO_CONFIGURE_DEPENDS AND Tests) + ParseAndAddCatchTests_PrintDebugMessage("Adding ${SourceFile} to CMAKE_CONFIGURE_DEPENDS property") + set_property( + DIRECTORY + APPEND + PROPERTY CMAKE_CONFIGURE_DEPENDS ${SourceFile} + ) + endif() + + # check CMP0110 policy for new add_test() behavior + if(POLICY CMP0110) + cmake_policy(GET CMP0110 _cmp0110_value) # new add_test() behavior + else() + # just to be thorough explicitly set the variable + set(_cmp0110_value) + endif() + + foreach(TestName ${Tests}) + # Strip newlines + string(REGEX REPLACE "\\\\\n|\n" "" TestName "${TestName}") + + # Get test type and fixture if applicable + string(REGEX MATCH "(CATCH_)?(TEMPLATE_)?(TEST_CASE_METHOD|SCENARIO|TEST_CASE)[ \t]*\\([^,^\"]*" TestTypeAndFixture "${TestName}") + string(REGEX MATCH "(CATCH_)?(TEMPLATE_)?(TEST_CASE_METHOD|SCENARIO|TEST_CASE)" TestType "${TestTypeAndFixture}") + string(REGEX REPLACE "${TestType}\\([ \t]*" "" TestFixture "${TestTypeAndFixture}") + + # Get string parts of test definition + string(REGEX MATCHALL "\"+([^\\^\"]|\\\\\")+\"+" TestStrings "${TestName}") + + # Strip wrapping quotation marks + string(REGEX REPLACE "^\"(.*)\"$" "\\1" TestStrings "${TestStrings}") + string(REPLACE "\";\"" ";" TestStrings "${TestStrings}") + + # Validate that a test name and tags have been provided + list(LENGTH TestStrings TestStringsLength) + if(TestStringsLength GREATER 2 OR TestStringsLength LESS 1) + message(FATAL_ERROR "You must provide a valid test name and tags for all tests in ${SourceFile}") endif() - ParseAndAddCatchTests_PrintDebugMessage("parsing ${SourceFile}") - file(STRINGS ${SourceFile} Contents NEWLINE_CONSUME) - - # Remove block and fullline comments - ParseAndAddCatchTests_RemoveComments(Contents) - - # Find definition of test names - # https://regex101.com/r/JygOND/1 - string(REGEX MATCHALL "[ \t]*(CATCH_)?(TEMPLATE_)?(TEST_CASE_METHOD|SCENARIO|TEST_CASE)[ \t]*\\([ \t\n]*\"[^\"]*\"[ \t\n]*(,[ \t\n]*\"[^\"]*\")?(,[ \t\n]*[^\,\)]*)*\\)[ \t\n]*\{+[ \t]*(//[^\n]*[Tt][Ii][Mm][Ee][Oo][Uu][Tt][ \t]*[0-9]+)*" Tests "${Contents}") - if(PARSE_CATCH_TESTS_ADD_TO_CONFIGURE_DEPENDS AND Tests) - ParseAndAddCatchTests_PrintDebugMessage("Adding ${SourceFile} to CMAKE_CONFIGURE_DEPENDS property") - set_property( - DIRECTORY - APPEND - PROPERTY CMAKE_CONFIGURE_DEPENDS ${SourceFile} - ) + # Assign name and tags + list(GET TestStrings 0 Name) + if("${TestType}" STREQUAL "SCENARIO") + set(Name "Scenario: ${Name}") endif() - - # check CMP0110 policy for new add_test() behavior - if(POLICY CMP0110) - cmake_policy(GET CMP0110 _cmp0110_value) # new add_test() behavior + if(PARSE_CATCH_TESTS_ADD_FIXTURE_IN_TEST_NAME AND "${TestType}" MATCHES "(CATCH_)?TEST_CASE_METHOD" AND TestFixture) + set(CTestName "${TestFixture}:${Name}") + else() + set(CTestName "${Name}") + endif() + if(PARSE_CATCH_TESTS_ADD_TARGET_IN_TEST_NAME) + set(CTestName "${TestTarget}:${CTestName}") + endif() + # add target to labels to enable running all tests added from this target + set(Labels ${TestTarget}) + if(TestStringsLength EQUAL 2) + list(GET TestStrings 1 Tags) + string(TOLOWER "${Tags}" Tags) + # remove target from labels if the test is hidden + if("${Tags}" MATCHES ".*\\[!?(hide|\\.)\\].*") + list(REMOVE_ITEM Labels ${TestTarget}) + endif() + string(REPLACE "]" ";" Tags "${Tags}") + string(REPLACE "[" "" Tags "${Tags}") else() - # just to be thorough explicitly set the variable - set(_cmp0110_value) + # unset tags variable from previous loop + unset(Tags) endif() - foreach(TestName ${Tests}) - # Strip newlines - string(REGEX REPLACE "\\\\\n|\n" "" TestName "${TestName}") - - # Get test type and fixture if applicable - string(REGEX MATCH "(CATCH_)?(TEMPLATE_)?(TEST_CASE_METHOD|SCENARIO|TEST_CASE)[ \t]*\\([^,^\"]*" TestTypeAndFixture "${TestName}") - string(REGEX MATCH "(CATCH_)?(TEMPLATE_)?(TEST_CASE_METHOD|SCENARIO|TEST_CASE)" TestType "${TestTypeAndFixture}") - string(REGEX REPLACE "${TestType}\\([ \t]*" "" TestFixture "${TestTypeAndFixture}") - - # Get string parts of test definition - string(REGEX MATCHALL "\"+([^\\^\"]|\\\\\")+\"+" TestStrings "${TestName}") - - # Strip wrapping quotation marks - string(REGEX REPLACE "^\"(.*)\"$" "\\1" TestStrings "${TestStrings}") - string(REPLACE "\";\"" ";" TestStrings "${TestStrings}") - - # Validate that a test name and tags have been provided - list(LENGTH TestStrings TestStringsLength) - if(TestStringsLength GREATER 2 OR TestStringsLength LESS 1) - message(FATAL_ERROR "You must provide a valid test name and tags for all tests in ${SourceFile}") - endif() - - # Assign name and tags - list(GET TestStrings 0 Name) - if("${TestType}" STREQUAL "SCENARIO") - set(Name "Scenario: ${Name}") - endif() - if(PARSE_CATCH_TESTS_ADD_FIXTURE_IN_TEST_NAME AND "${TestType}" MATCHES "(CATCH_)?TEST_CASE_METHOD" AND TestFixture ) - set(CTestName "${TestFixture}:${Name}") - else() - set(CTestName "${Name}") - endif() - if(PARSE_CATCH_TESTS_ADD_TARGET_IN_TEST_NAME) - set(CTestName "${TestTarget}:${CTestName}") - endif() - # add target to labels to enable running all tests added from this target - set(Labels ${TestTarget}) - if(TestStringsLength EQUAL 2) - list(GET TestStrings 1 Tags) - string(TOLOWER "${Tags}" Tags) - # remove target from labels if the test is hidden - if("${Tags}" MATCHES ".*\\[!?(hide|\\.)\\].*") - list(REMOVE_ITEM Labels ${TestTarget}) - endif() - string(REPLACE "]" ";" Tags "${Tags}") - string(REPLACE "[" "" Tags "${Tags}") - else() - # unset tags variable from previous loop - unset(Tags) - endif() - - list(APPEND Labels ${Tags}) - - set(HiddenTagFound OFF) - foreach(label ${Labels}) - string(REGEX MATCH "^!hide|^\\." result ${label}) - if(result) - set(HiddenTagFound ON) - break() - endif() - endforeach(label) - if(PARSE_CATCH_TESTS_NO_HIDDEN_TESTS AND ${HiddenTagFound} AND ${CMAKE_VERSION} VERSION_LESS "3.9") - ParseAndAddCatchTests_PrintDebugMessage("Skipping test \"${CTestName}\" as it has [!hide], [.] or [.foo] label") - else() - ParseAndAddCatchTests_PrintDebugMessage("Adding test \"${CTestName}\"") - if(Labels) - ParseAndAddCatchTests_PrintDebugMessage("Setting labels to ${Labels}") - endif() - - # Escape commas in the test spec - string(REPLACE "," "\\," Name ${Name}) - - # Work around CMake 3.18.0 change in `add_test()`, before the escaped quotes were necessary, - # only with CMake 3.18.0 the escaped double quotes confuse the call. This change is reverted in 3.18.1 - # And properly introduced in 3.19 with the CMP0110 policy - if(_cmp0110_value STREQUAL "NEW" OR ${CMAKE_VERSION} VERSION_EQUAL "3.18") - ParseAndAddCatchTests_PrintDebugMessage("CMP0110 set to NEW, no need for add_test(\"\") workaround") - else() - ParseAndAddCatchTests_PrintDebugMessage("CMP0110 set to OLD adding \"\" for add_test() workaround") - set(CTestName "\"${CTestName}\"") - endif() - - # Handle template test cases - if("${TestTypeAndFixture}" MATCHES ".*TEMPLATE_.*") - set(Name "${Name} - *") - endif() - - # Add the test and set its properties - add_test(NAME "${CTestName}" COMMAND ${OptionalCatchTestLauncher} $ ${Name} ${AdditionalCatchParameters}) - # Old CMake versions do not document VERSION_GREATER_EQUAL, so we use VERSION_GREATER with 3.8 instead - if(PARSE_CATCH_TESTS_NO_HIDDEN_TESTS AND ${HiddenTagFound} AND ${CMAKE_VERSION} VERSION_GREATER "3.8") - ParseAndAddCatchTests_PrintDebugMessage("Setting DISABLED test property") - set_tests_properties("${CTestName}" PROPERTIES DISABLED ON) - else() - set_tests_properties("${CTestName}" PROPERTIES FAIL_REGULAR_EXPRESSION "No tests ran" - LABELS "${Labels}") - endif() - set_property( - TARGET ${TestTarget} - APPEND - PROPERTY ParseAndAddCatchTests_TESTS "${CTestName}") - set_property( - SOURCE ${SourceFile} - APPEND - PROPERTY ParseAndAddCatchTests_TESTS "${CTestName}") - endif() - - - endforeach() + list(APPEND Labels ${Tags}) + + set(HiddenTagFound OFF) + foreach(label ${Labels}) + string(REGEX MATCH "^!hide|^\\." result ${label}) + if(result) + set(HiddenTagFound ON) + break() + endif() + endforeach(label) + if(PARSE_CATCH_TESTS_NO_HIDDEN_TESTS AND ${HiddenTagFound} AND ${CMAKE_VERSION} VERSION_LESS "3.9") + ParseAndAddCatchTests_PrintDebugMessage("Skipping test \"${CTestName}\" as it has [!hide], [.] or [.foo] label") + else() + ParseAndAddCatchTests_PrintDebugMessage("Adding test \"${CTestName}\"") + if(Labels) + ParseAndAddCatchTests_PrintDebugMessage("Setting labels to ${Labels}") + endif() + + # Escape commas in the test spec + string(REPLACE "," "\\," Name ${Name}) + + # Work around CMake 3.18.0 change in `add_test()`, before the escaped quotes were necessary, + # only with CMake 3.18.0 the escaped double quotes confuse the call. This change is reverted in 3.18.1 + # And properly introduced in 3.19 with the CMP0110 policy + if(_cmp0110_value STREQUAL "NEW" OR ${CMAKE_VERSION} VERSION_EQUAL "3.18") + ParseAndAddCatchTests_PrintDebugMessage("CMP0110 set to NEW, no need for add_test(\"\") workaround") + else() + ParseAndAddCatchTests_PrintDebugMessage("CMP0110 set to OLD adding \"\" for add_test() workaround") + set(CTestName "\"${CTestName}\"") + endif() + + # Handle template test cases + if("${TestTypeAndFixture}" MATCHES ".*TEMPLATE_.*") + set(Name "${Name} - *") + endif() + + # Add the test and set its properties + add_test(NAME "${CTestName}" COMMAND ${OptionalCatchTestLauncher} $ ${Name} ${AdditionalCatchParameters}) + # Old CMake versions do not document VERSION_GREATER_EQUAL, so we use VERSION_GREATER with 3.8 instead + if(PARSE_CATCH_TESTS_NO_HIDDEN_TESTS AND ${HiddenTagFound} AND ${CMAKE_VERSION} VERSION_GREATER "3.8") + ParseAndAddCatchTests_PrintDebugMessage("Setting DISABLED test property") + set_tests_properties("${CTestName}" PROPERTIES DISABLED ON) + else() + set_tests_properties("${CTestName}" PROPERTIES FAIL_REGULAR_EXPRESSION "No tests ran" + LABELS "${Labels}") + endif() + set_property( + TARGET ${TestTarget} + APPEND + PROPERTY ParseAndAddCatchTests_TESTS "${CTestName}") + set_property( + SOURCE ${SourceFile} + APPEND + PROPERTY ParseAndAddCatchTests_TESTS "${CTestName}") + endif() + endforeach() endfunction() # entry point function(ParseAndAddCatchTests TestTarget) - message(DEPRECATION "ParseAndAddCatchTest: function deprecated because of possibility of missed test cases. Consider using 'catch_discover_tests' from 'Catch.cmake'") - ParseAndAddCatchTests_PrintDebugMessage("Started parsing ${TestTarget}") - get_target_property(SourceFiles ${TestTarget} SOURCES) - ParseAndAddCatchTests_PrintDebugMessage("Found the following sources: ${SourceFiles}") - foreach(SourceFile ${SourceFiles}) - ParseAndAddCatchTests_ParseFile(${SourceFile} ${TestTarget}) - endforeach() - ParseAndAddCatchTests_PrintDebugMessage("Finished parsing ${TestTarget}") + message(DEPRECATION "ParseAndAddCatchTest: function deprecated because of possibility of missed test cases. Consider using 'catch_discover_tests' from 'Catch.cmake'") + ParseAndAddCatchTests_PrintDebugMessage("Started parsing ${TestTarget}") + get_target_property(SourceFiles ${TestTarget} SOURCES) + ParseAndAddCatchTests_PrintDebugMessage("Found the following sources: ${SourceFiles}") + foreach(SourceFile ${SourceFiles}) + ParseAndAddCatchTests_ParseFile(${SourceFile} ${TestTarget}) + endforeach() + ParseAndAddCatchTests_PrintDebugMessage("Finished parsing ${TestTarget}") endfunction() diff --git a/catch2/extras/catch_amalgamated.cpp b/catch2/extras/catch_amalgamated.cpp index b979eb2..892d637 100644 --- a/catch2/extras/catch_amalgamated.cpp +++ b/catch2/extras/catch_amalgamated.cpp @@ -6,8 +6,8 @@ // SPDX-License-Identifier: BSL-1.0 -// Catch v3.8.1 -// Generated: 2025-04-08 12:33:19.863332 +// Catch v3.11.0 +// Generated: 2025-09-30 10:49:12.549018 // ---------------------------------------------------------- // This file is an amalgamation of multiple different files. // You probably shouldn't edit it directly. @@ -825,6 +825,8 @@ namespace Catch { m_data.reporterSpecifications.push_back( std::move( *parsed ) ); } + // Reading bazel env vars can change some parts of the config data, + // so we have to process the bazel env before acting on the config. if ( enableBazelEnvSupport() ) { readBazelEnvVars(); } @@ -889,6 +891,8 @@ namespace Catch { bool Config::showHelp() const { return m_data.showHelp; } + std::string const& Config::getExitGuardFilePath() const { return m_data.prematureExitGuardFilePath; } + // IConfig interface bool Config::allowThrows() const { return !m_data.noThrow; } StringRef Config::name() const { return m_data.name.empty() ? m_data.processName : m_data.name; } @@ -950,6 +954,26 @@ namespace Catch { m_data.shardCount = bazelShardOptions->shardCount; } } + + const auto bazelExitGuardFile = Detail::getEnv( "TEST_PREMATURE_EXIT_FILE" ); + if (bazelExitGuardFile) { + m_data.prematureExitGuardFilePath = bazelExitGuardFile; + } + + const auto bazelRandomSeed = Detail::getEnv( "TEST_RANDOM_SEED" ); + if ( bazelRandomSeed ) { + auto parsedSeed = parseUInt( bazelRandomSeed, 0 ); + if ( !parsedSeed ) { + // Currently we handle issues with parsing other Bazel Env + // options by warning and ignoring the issue. So we do the + // same for random seed option. + Catch::cerr() + << "Warning: could not parse 'TEST_RANDOM_SEED' ('" + << bazelRandomSeed << "') as proper seed.\n"; + } else { + m_data.rngSeed = *parsedSeed; + } + } } } // end namespace Catch @@ -975,28 +999,26 @@ namespace Catch { ScopedMessage::ScopedMessage( MessageBuilder&& builder ): - m_info( CATCH_MOVE(builder.m_info) ) { - m_info.message = builder.m_stream.str(); - getResultCapture().pushScopedMessage( m_info ); + m_messageId( builder.m_info.sequence ) { + MessageInfo info( CATCH_MOVE( builder.m_info ) ); + info.message = builder.m_stream.str(); + IResultCapture::pushScopedMessage( CATCH_MOVE( info ) ); } ScopedMessage::ScopedMessage( ScopedMessage&& old ) noexcept: - m_info( CATCH_MOVE( old.m_info ) ) { + m_messageId( old.m_messageId ) { old.m_moved = true; } ScopedMessage::~ScopedMessage() { - if ( !uncaught_exceptions() && !m_moved ){ - getResultCapture().popScopedMessage(m_info); - } + if ( !m_moved ) { IResultCapture::popScopedMessage( m_messageId ); } } Capturer::Capturer( StringRef macroName, SourceLineInfo const& lineInfo, ResultWas::OfType resultType, - StringRef names ): - m_resultCapture( getResultCapture() ) { + StringRef names ) { auto trimmed = [&] (size_t start, size_t end) { while (names[start] == ',' || isspace(static_cast(names[start]))) { ++start; @@ -1042,8 +1064,8 @@ namespace Catch { case ',': if (start != pos && openings.empty()) { m_messages.emplace_back(macroName, lineInfo, resultType); - m_messages.back().message = static_cast(trimmed(start, pos)); - m_messages.back().message += " := "; + m_messages.back().message += trimmed(start, pos); + m_messages.back().message += " := "_sr; start = pos; } break; @@ -1052,21 +1074,20 @@ namespace Catch { } assert(openings.empty() && "Mismatched openings"); m_messages.emplace_back(macroName, lineInfo, resultType); - m_messages.back().message = static_cast(trimmed(start, names.size() - 1)); - m_messages.back().message += " := "; + m_messages.back().message += trimmed(start, names.size() - 1); + m_messages.back().message += " := "_sr; } Capturer::~Capturer() { - if ( !uncaught_exceptions() ){ - assert( m_captured == m_messages.size() ); - for( size_t i = 0; i < m_captured; ++i ) - m_resultCapture.popScopedMessage( m_messages[i] ); + assert( m_captured == m_messages.size() ); + for (auto const& message : m_messages) { + IResultCapture::popScopedMessage( message.sequence ); } } void Capturer::captureValue( size_t index, std::string const& value ) { assert( index < m_messages.size() ); m_messages[index].message += value; - m_resultCapture.pushScopedMessage( m_messages[index] ); + IResultCapture::pushScopedMessage( CATCH_MOVE( m_messages[index] ) ); m_captured++; } @@ -1150,7 +1171,6 @@ namespace Catch { } void cleanUp() { cleanupSingletons(); - cleanUpContext(); } std::string translateActiveException() { return getRegistryHub().getExceptionTranslatorRegistry().translateActiveException(); @@ -1161,8 +1181,9 @@ namespace Catch { -#include #include +#include +#include #include #include #include @@ -1170,14 +1191,6 @@ namespace Catch { namespace Catch { namespace { - static constexpr int TestFailureExitCode = 42; - static constexpr int UnspecifiedErrorExitCode = 1; - static constexpr int AllTestsSkippedExitCode = 4; - static constexpr int NoTestsRunExitCode = 2; - static constexpr int UnmatchedTestSpecExitCode = 3; - static constexpr int InvalidTestSpecExitCode = 5; - - IEventListenerPtr createReporter(std::string const& reporterName, ReporterConfig&& config) { auto reporter = Catch::getRegistryHub().getReporterRegistry().create(reporterName, CATCH_MOVE(config)); CATCH_ENFORCE(reporter, "No reporter registered with name: '" << reporterName << '\''); @@ -1285,6 +1298,50 @@ namespace Catch { } } + // Creates empty file at path. The path must be writable, we do not + // try to create directories in path because that's hard in C++14. + void setUpGuardFile( std::string const& guardFilePath ) { + if ( !guardFilePath.empty() ) { +#if defined( _MSC_VER ) + std::FILE* file = nullptr; + if ( fopen_s( &file, guardFilePath.c_str(), "w" ) ) { + char msgBuffer[100]; + const auto err = errno; + std::string errMsg; + if ( !strerror_s( msgBuffer, err ) ) { + errMsg = msgBuffer; + } else { + errMsg = "Could not translate errno to a string"; + } + +#else + std::FILE* file = std::fopen( guardFilePath.c_str(), "w" ); + if ( !file ) { + const auto err = errno; + const char* errMsg = std::strerror( err ); +#endif + + CATCH_RUNTIME_ERROR( "Could not open the exit guard file '" + << guardFilePath << "' because '" + << errMsg << "' (" << err << ')' ); + } + const int ret = std::fclose( file ); + CATCH_ENFORCE( + ret == 0, + "Error when closing the exit guard file: " << ret ); + } + } + + // Removes file at path. Assuming we created it in setUpGuardFile. + void tearDownGuardFile( std::string const& guardFilePath ) { + if ( !guardFilePath.empty() ) { + const int ret = std::remove( guardFilePath.c_str() ); + CATCH_ENFORCE( + ret == 0, + "Error when removing the exit guard file: " << ret ); + } + } + } // anon namespace Session::Session() { @@ -1403,6 +1460,7 @@ namespace Catch { static_cast(std::getchar()); } int exitCode = runInternal(); + if( ( m_configData.waitForKeypress & WaitForKeypress::BeforeExit ) != 0 ) { Catch::cout() << "...waiting for enter/ return before exiting, with code: " << exitCode << '\n' << std::flush; static_cast(std::getchar()); @@ -1443,6 +1501,10 @@ namespace Catch { CATCH_TRY { config(); // Force config to be constructed + // We need to retrieve potential Bazel config with the full Config + // constructor, so we have to create the guard file after it is created. + setUpGuardFile( m_config->getExitGuardFilePath() ); + seedRng( *m_config ); if (m_configData.filenamesAsTags) { @@ -1472,9 +1534,12 @@ namespace Catch { TestGroup tests { CATCH_MOVE(reporter), m_config.get() }; auto const totals = tests.execute(); + // If we got here, running the tests finished normally-enough. + // They might've failed, but that would've been reported elsewhere. + tearDownGuardFile( m_config->getExitGuardFilePath() ); + if ( tests.hadUnmatchedTestSpecs() && m_config->warnAboutUnmatchedTestSpecs() ) { - // UnmatchedTestSpecExitCode return UnmatchedTestSpecExitCode; } @@ -1935,7 +2000,6 @@ namespace Catch { -#include #include namespace Catch { @@ -1985,35 +2049,35 @@ namespace Detail { std::string ret; // This is enough for the "don't escape invisibles" case, and a good // lower bound on the "escape invisibles" case. - ret.reserve(string.size() + 2); + ret.reserve( string.size() + 2 ); - if (!escapeInvisibles) { + if ( !escapeInvisibles ) { ret += '"'; ret += string; ret += '"'; return ret; } + size_t last_start = 0; + auto write_to = [&]( size_t idx ) { + if ( last_start < idx ) { + ret += string.substr( last_start, idx - last_start ); + } + last_start = idx + 1; + }; + ret += '"'; - for (char c : string) { - switch (c) { - case '\r': - ret.append("\\r"); - break; - case '\n': - ret.append("\\n"); - break; - case '\t': - ret.append("\\t"); - break; - case '\f': - ret.append("\\f"); - break; - default: - ret.push_back(c); - break; + for ( size_t i = 0; i < string.size(); ++i ) { + const char c = string[i]; + if ( c == '\r' || c == '\n' || c == '\t' || c == '\f' ) { + write_to( i ); + if ( c == '\r' ) { ret.append( "\\r" ); } + if ( c == '\n' ) { ret.append( "\\n" ); } + if ( c == '\t' ) { ret.append( "\\t" ); } + if ( c == '\f' ) { ret.append( "\\f" ); } } } + write_to( string.size() ); ret += '"'; return ret; @@ -2038,6 +2102,13 @@ namespace Detail { rss << std::setw(2) << static_cast(bytes[i]); return rss.str(); } + + std::string makeExceptionHappenedString() { + return "{ stringification failed with an exception: \"" + + translateActiveException() + "\" }"; + + } + } // end Detail namespace @@ -2283,7 +2354,7 @@ namespace Catch { } Version const& libraryVersion() { - static Version version( 3, 8, 1, "", 0 ); + static Version version( 3, 11, 0, "", 0 ); return version; } @@ -2371,8 +2442,14 @@ namespace Catch { namespace Catch { + namespace Detail { + void missingCaptureInstance() { + CATCH_INTERNAL_ERROR( "No result capture instance" ); + } + } // namespace Detail + IResultCapture::~IResultCapture() = default; -} +} // namespace Catch @@ -3365,6 +3442,9 @@ namespace Catch { | Opt( config.allowZeroTests ) ["--allow-running-no-tests"] ( "Treat 'No tests run' as a success" ) + | Opt( config.prematureExitGuardFilePath, "path" ) + ["--premature-exit-guard-file"] + ( "create a file before running tests and delete it during clean exit" ) | Arg( config.testsOrTags, "test name|pattern|tags" ) ( "which test or tests to use" ); @@ -3519,7 +3599,11 @@ namespace { #endif // Windows/ ANSI/ None -#if defined( CATCH_PLATFORM_LINUX ) || defined( CATCH_PLATFORM_MAC ) || defined( __GLIBC__ ) +#if defined( CATCH_PLATFORM_LINUX ) \ + || defined( CATCH_PLATFORM_MAC ) \ + || defined( __GLIBC__ ) \ + || defined( __FreeBSD__ ) \ + || defined( CATCH_PLATFORM_QNX ) # define CATCH_INTERNAL_HAS_ISATTY # include #endif @@ -3643,20 +3727,10 @@ namespace Catch { namespace Catch { - Context* Context::currentContext = nullptr; - - void cleanUpContext() { - delete Context::currentContext; - Context::currentContext = nullptr; - } - void Context::createContext() { - currentContext = new Context(); - } + Context Context::currentContext; Context& getCurrentMutableContext() { - if ( !Context::currentContext ) { Context::createContext(); } - // NOLINTNEXTLINE(clang-analyzer-core.uninitialized.UndefReturn) - return *Context::currentContext; + return Context::currentContext; } SimplePcg32& sharedRng() { @@ -3761,7 +3835,7 @@ namespace Catch { #endif } // namespace Catch -#elif defined(CATCH_PLATFORM_LINUX) +#elif defined(CATCH_PLATFORM_LINUX) || defined(CATCH_PLATFORM_QNX) #include #include @@ -3993,10 +4067,10 @@ namespace Catch { // To avoid having to handle TFE explicitly everywhere, we just // rethrow it so that it goes back up the caller. catch( TestFailureException& ) { - std::rethrow_exception(std::current_exception()); + return "{ nested assertion failed }"; } catch( TestSkipException& ) { - std::rethrow_exception(std::current_exception()); + return "{ nested SKIP() called }"; } catch( std::exception const& ex ) { return ex.what(); @@ -4088,30 +4162,34 @@ namespace Catch { // There is no 1-1 mapping between signals and windows exceptions. // Windows can easily distinguish between SO and SigSegV, // but SigInt, SigTerm, etc are handled differently. - static SignalDefs signalDefs[] = { + static constexpr SignalDefs signalDefs[] = { { EXCEPTION_ILLEGAL_INSTRUCTION, "SIGILL - Illegal instruction signal" }, { EXCEPTION_STACK_OVERFLOW, "SIGSEGV - Stack overflow" }, { EXCEPTION_ACCESS_VIOLATION, "SIGSEGV - Segmentation violation signal" }, { EXCEPTION_INT_DIVIDE_BY_ZERO, "Divide by zero error" }, }; + // Since we do not support multiple instantiations, we put these + // into global variables and rely on cleaning them up in outlined + // constructors/destructors + static LPTOP_LEVEL_EXCEPTION_FILTER previousTopLevelExceptionFilter = nullptr; + + static LONG CALLBACK topLevelExceptionFilter(PEXCEPTION_POINTERS ExceptionInfo) { for (auto const& def : signalDefs) { if (ExceptionInfo->ExceptionRecord->ExceptionCode == def.id) { reportFatal(def.name); } } - // If its not an exception we care about, pass it along. + // If a filter was previously registered, invoke it + if (previousTopLevelExceptionFilter) { + return previousTopLevelExceptionFilter(ExceptionInfo); + } + // Otherwise, pass along all exceptions. // This stops us from eating debugger breaks etc. return EXCEPTION_CONTINUE_SEARCH; } - // Since we do not support multiple instantiations, we put these - // into global variables and rely on cleaning them up in outlined - // constructors/destructors - static LPTOP_LEVEL_EXCEPTION_FILTER previousTopLevelExceptionFilter = nullptr; - - // For MSVC, we reserve part of the stack memory for handling // memory overflow structured exception. FatalConditionHandler::FatalConditionHandler() { @@ -4159,7 +4237,7 @@ namespace Catch { const char* name; }; - static SignalDefs signalDefs[] = { + static constexpr SignalDefs signalDefs[] = { { SIGINT, "SIGINT - Terminal interrupt signal" }, { SIGILL, "SIGILL - Illegal instruction signal" }, { SIGFPE, "SIGFPE - Floating point error signal" }, @@ -4323,8 +4401,6 @@ namespace Catch { #include #include -#include -#include namespace Catch { @@ -4465,6 +4541,33 @@ namespace Detail { namespace Catch { + + namespace { + static bool needsEscape( char c ) { + return c == '"' || c == '\\' || c == '\b' || c == '\f' || + c == '\n' || c == '\r' || c == '\t'; + } + + static Catch::StringRef makeEscapeStringRef( char c ) { + if ( c == '"' ) { + return "\\\""_sr; + } else if ( c == '\\' ) { + return "\\\\"_sr; + } else if ( c == '\b' ) { + return "\\b"_sr; + } else if ( c == '\f' ) { + return "\\f"_sr; + } else if ( c == '\n' ) { + return "\\n"_sr; + } else if ( c == '\r' ) { + return "\\r"_sr; + } else if ( c == '\t' ) { + return "\\t"_sr; + } + Catch::Detail::Unreachable(); + } + } // namespace + void JsonUtils::indent( std::ostream& os, std::uint64_t level ) { for ( std::uint64_t i = 0; i < level; ++i ) { os << " "; @@ -4574,30 +4677,19 @@ namespace Catch { void JsonValueWriter::writeImpl( Catch::StringRef value, bool quote ) { if ( quote ) { m_os << '"'; } - for (char c : value) { - // Escape list taken from https://www.json.org/json-en.html, - // string definition. - // Note that while forward slash _can_ be escaped, it does - // not have to be, if JSON is not further embedded somewhere - // where forward slash is meaningful. - if ( c == '"' ) { - m_os << "\\\""; - } else if ( c == '\\' ) { - m_os << "\\\\"; - } else if ( c == '\b' ) { - m_os << "\\b"; - } else if ( c == '\f' ) { - m_os << "\\f"; - } else if ( c == '\n' ) { - m_os << "\\n"; - } else if ( c == '\r' ) { - m_os << "\\r"; - } else if ( c == '\t' ) { - m_os << "\\t"; - } else { - m_os << c; + size_t current_start = 0; + for ( size_t i = 0; i < value.size(); ++i ) { + if ( needsEscape( value[i] ) ) { + if ( current_start < i ) { + m_os << value.substr( current_start, i - current_start ); + } + m_os << makeEscapeStringRef( value[i] ); + current_start = i + 1; } } + if ( current_start < value.size() ) { + m_os << value.substr( current_start, value.size() - current_start ); + } if ( quote ) { m_os << '"'; } } @@ -4765,7 +4857,7 @@ namespace Catch { namespace Catch { CATCH_INTERNAL_START_WARNINGS_SUPPRESSION CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS - static LeakDetector leakDetector; + static const LeakDetector leakDetector; CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION } @@ -4794,17 +4886,18 @@ int main (int argc, char * argv[]) { namespace Catch { - MessageInfo::MessageInfo( StringRef _macroName, - SourceLineInfo const& _lineInfo, - ResultWas::OfType _type ) + MessageInfo::MessageInfo( StringRef _macroName, + SourceLineInfo const& _lineInfo, + ResultWas::OfType _type ) : macroName( _macroName ), lineInfo( _lineInfo ), type( _type ), sequence( ++globalCount ) {} - // This may need protecting if threading support is added - unsigned int MessageInfo::globalCount = 0; + // Messages are owned by their individual threads, so the counter should be thread-local as well. + // Alternative consideration: atomic, so threads don't share IDs and things are easier to debug. + thread_local unsigned int MessageInfo::globalCount = 0; } // end namespace Catch @@ -5216,6 +5309,12 @@ namespace Catch { +#if defined( __clang__ ) +# define CATCH2_CLANG_NO_SANITIZE_INTEGER \ + __attribute__( ( no_sanitize( "unsigned-integer-overflow" ) ) ) +#else +# define CATCH2_CLANG_NO_SANITIZE_INTEGER +#endif namespace Catch { namespace { @@ -5225,6 +5324,7 @@ namespace { #pragma warning(disable:4146) // we negate uint32 during the rotate #endif // Safe rotr implementation thanks to John Regehr + CATCH2_CLANG_NO_SANITIZE_INTEGER uint32_t rotate_right(uint32_t val, uint32_t count) { const uint32_t mask = 31; count &= mask; @@ -5258,6 +5358,7 @@ namespace { } } + CATCH2_CLANG_NO_SANITIZE_INTEGER SimplePcg32::result_type SimplePcg32::operator()() { // prepare the output value const uint32_t xorshifted = static_cast(((m_state >> 18u) ^ m_state) >> 27u); @@ -5546,6 +5647,7 @@ ReporterSpec::ReporterSpec( #include #include +#include #include namespace Catch { @@ -5555,34 +5657,40 @@ namespace Catch { std::vector> m_streams; std::vector m_unused; std::ostringstream m_referenceStream; // Used for copy state/ flags from + Detail::Mutex m_mutex; - auto add() -> std::size_t { + auto add() -> std::pair { + Detail::LockGuard _( m_mutex ); if( m_unused.empty() ) { m_streams.push_back( Detail::make_unique() ); - return m_streams.size()-1; + return { m_streams.size()-1, m_streams.back().get() }; } else { auto index = m_unused.back(); m_unused.pop_back(); - return index; + return { index, m_streams[index].get() }; } } - void release( std::size_t index ) { - m_streams[index]->copyfmt( m_referenceStream ); // Restore initial flags and other state - m_unused.push_back(index); + void release( std::size_t index, std::ostream* originalPtr ) { + assert( originalPtr ); + originalPtr->copyfmt( m_referenceStream ); // Restore initial flags and other state + + Detail::LockGuard _( m_mutex ); + assert( originalPtr == m_streams[index].get() && "Mismatch between release index and stream ptr" ); + m_unused.push_back( index ); } }; - ReusableStringStream::ReusableStringStream() - : m_index( Singleton::getMutable().add() ), - m_oss( Singleton::getMutable().m_streams[m_index].get() ) - {} + ReusableStringStream::ReusableStringStream() { + std::tie( m_index, m_oss ) = + Singleton::getMutable().add(); + } ReusableStringStream::~ReusableStringStream() { static_cast( m_oss )->str(""); m_oss->clear(); - Singleton::getMutable().release( m_index ); + Singleton::getMutable().release( m_index, m_oss ); } std::string ReusableStringStream::str() const { @@ -5742,23 +5850,64 @@ namespace Catch { } // namespace } + namespace Detail { + // Assertions are owned by the thread that is executing them. + // This allows for lock-free progress in common cases where we + // do not need to send the assertion events to the reporter. + // This also implies that messages are owned by their respective + // threads, and should not be shared across different threads. + // + // This implies that various pieces of metadata referring to last + // assertion result/source location/message handling, etc + // should also be thread local. For now we just use naked globals + // below, in the future we will want to allocate piece of memory + // from heap, to avoid consuming too much thread-local storage. + + // This is used for the "if" part of CHECKED_IF/CHECKED_ELSE + static thread_local bool g_lastAssertionPassed = false; + + // This is the source location for last encountered macro. It is + // used to provide the users with more precise location of error + // when an unexpected exception/fatal error happens. + static thread_local SourceLineInfo g_lastKnownLineInfo("DummyLocation", static_cast(-1)); + + // Should we clear message scopes before sending off the messages to + // reporter? Set in `assertionPassedFastPath` to avoid doing the full + // clear there for performance reasons. + static thread_local bool g_clearMessageScopes = false; + + CATCH_INTERNAL_START_WARNINGS_SUPPRESSION + CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS + // Actual messages to be provided to the reporter + static thread_local std::vector g_messages; + + // Owners for the UNSCOPED_X information macro + static thread_local std::vector g_messageScopes; + CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION + + } // namespace Detail + RunContext::RunContext(IConfig const* _config, IEventListenerPtr&& reporter) : m_runInfo(_config->name()), m_config(_config), m_reporter(CATCH_MOVE(reporter)), - m_lastAssertionInfo{ StringRef(), SourceLineInfo("",0), StringRef(), ResultDisposition::Normal }, m_outputRedirect( makeOutputRedirect( m_reporter->getPreferences().shouldRedirectStdOut ) ), - m_includeSuccessfulResults( m_config->includeSuccessfulResults() || m_reporter->getPreferences().shouldReportAllAssertions ) + m_abortAfterXFailedAssertions( m_config->abortAfter() ), + m_reportAssertionStarting( m_reporter->getPreferences().shouldReportAllAssertionStarts ), + m_includeSuccessfulResults( m_config->includeSuccessfulResults() || m_reporter->getPreferences().shouldReportAllAssertions ), + m_shouldDebugBreak( m_config->shouldDebugBreak() ) { getCurrentMutableContext().setResultCapture( this ); m_reporter->testRunStarting(m_runInfo); } RunContext::~RunContext() { + updateTotalsFromAtomics(); m_reporter->testRunEnded(TestRunStats(m_runInfo, m_totals, aborting())); } Totals RunContext::runTest(TestCaseHandle const& testCase) { + updateTotalsFromAtomics(); const Totals prevTotals = m_totals; auto const& testInfo = testCase.getTestCaseInfo(); @@ -5813,6 +5962,7 @@ namespace Catch { m_reporter->testCasePartialStarting(testInfo, testRuns); + updateTotalsFromAtomics(); const auto beforeRunTotals = m_totals; runCurrentTest(); std::string oneRunCout = m_outputRedirect->getStdout(); @@ -5821,6 +5971,7 @@ namespace Catch { redirectedCout += oneRunCout; redirectedCerr += oneRunCerr; + updateTotalsFromAtomics(); const auto singleRunTotals = m_totals.delta(beforeRunTotals); auto statsForOneRun = TestCaseStats(testInfo, singleRunTotals, CATCH_MOVE(oneRunCout), CATCH_MOVE(oneRunCerr), aborting()); m_reporter->testCasePartialEnded(statsForOneRun, testRuns); @@ -5850,47 +6001,54 @@ namespace Catch { void RunContext::assertionEnded(AssertionResult&& result) { + Detail::g_lastKnownLineInfo = result.m_info.lineInfo; if (result.getResultType() == ResultWas::Ok) { - m_totals.assertions.passed++; - m_lastAssertionPassed = true; + m_atomicAssertionCount.passed++; + Detail::g_lastAssertionPassed = true; } else if (result.getResultType() == ResultWas::ExplicitSkip) { - m_totals.assertions.skipped++; - m_lastAssertionPassed = true; + m_atomicAssertionCount.skipped++; + Detail::g_lastAssertionPassed = true; } else if (!result.succeeded()) { - m_lastAssertionPassed = false; + Detail::g_lastAssertionPassed = false; if (result.isOk()) { } - else if( m_activeTestCase->getTestCaseInfo().okToFail() ) - m_totals.assertions.failedButOk++; + else if( m_activeTestCase->getTestCaseInfo().okToFail() ) // Read from a shared state established before the threads could start, this is fine + m_atomicAssertionCount.failedButOk++; else - m_totals.assertions.failed++; + m_atomicAssertionCount.failed++; } else { - m_lastAssertionPassed = true; + Detail::g_lastAssertionPassed = true; } + if ( Detail::g_clearMessageScopes ) { + Detail::g_messageScopes.clear(); + Detail::g_clearMessageScopes = false; + } + + // From here, we are touching shared state and need mutex. + Detail::LockGuard lock( m_assertionMutex ); { auto _ = scopedDeactivate( *m_outputRedirect ); - m_reporter->assertionEnded( AssertionStats( result, m_messages, m_totals ) ); + updateTotalsFromAtomics(); + m_reporter->assertionEnded( AssertionStats( result, Detail::g_messages, m_totals ) ); } if ( result.getResultType() != ResultWas::Warning ) { - m_messageScopes.clear(); + Detail::g_messageScopes.clear(); } // Reset working state. assertion info will be reset after // populateReaction is run if it is needed m_lastResult = CATCH_MOVE( result ); } - void RunContext::resetAssertionInfo() { - m_lastAssertionInfo.macroName = StringRef(); - m_lastAssertionInfo.capturedExpression = "{Unknown expression after the reported line}"_sr; - m_lastAssertionInfo.resultDisposition = ResultDisposition::Normal; - } void RunContext::notifyAssertionStarted( AssertionInfo const& info ) { - auto _ = scopedDeactivate( *m_outputRedirect ); - m_reporter->assertionStarting( info ); + if (m_reportAssertionStarting) { + Detail::LockGuard lock( m_assertionMutex ); + auto _ = scopedDeactivate( *m_outputRedirect ); + m_reporter->assertionStarting( info ); + } } bool RunContext::sectionStarted( StringRef sectionName, @@ -5906,13 +6064,14 @@ namespace Catch { m_activeSections.push_back(§ionTracker); SectionInfo sectionInfo( sectionLineInfo, static_cast(sectionName) ); - m_lastAssertionInfo.lineInfo = sectionInfo.lineInfo; + Detail::g_lastKnownLineInfo = sectionLineInfo; { auto _ = scopedDeactivate( *m_outputRedirect ); m_reporter->sectionStarting( sectionInfo ); } + updateTotalsFromAtomics(); assertions = m_totals.assertions; return true; @@ -5920,12 +6079,11 @@ namespace Catch { IGeneratorTracker* RunContext::acquireGeneratorTracker( StringRef generatorName, SourceLineInfo const& lineInfo ) { - using namespace Generators; - GeneratorTracker* tracker = GeneratorTracker::acquire( + auto* tracker = Generators::GeneratorTracker::acquire( m_trackerContext, TestCaseTracking::NameAndLocationRef( generatorName, lineInfo ) ); - m_lastAssertionInfo.lineInfo = lineInfo; + Detail::g_lastKnownLineInfo = lineInfo; return tracker; } @@ -5938,7 +6096,7 @@ namespace Catch { auto& currentTracker = m_trackerContext.currentTracker(); assert( currentTracker.nameAndLocation() != nameAndLoc && - "Trying to create tracker for a genreator that already has one" ); + "Trying to create tracker for a generator that already has one" ); auto newTracker = Catch::Detail::make_unique( CATCH_MOVE(nameAndLoc), m_trackerContext, ¤tTracker ); @@ -5957,12 +6115,13 @@ namespace Catch { return false; if (m_trackerContext.currentTracker().hasChildren()) return false; - m_totals.assertions.failed++; + m_atomicAssertionCount.failed++; assertions.failed++; return true; } void RunContext::sectionEnded(SectionEndInfo&& endInfo) { + updateTotalsFromAtomics(); Counts assertions = m_totals.assertions - endInfo.prevAssertions; bool missingAssertions = testForMissingAssertions(assertions); @@ -5979,9 +6138,6 @@ namespace Catch { endInfo.durationInSeconds, missingAssertions ) ); } - - m_messages.clear(); - m_messageScopes.clear(); } void RunContext::sectionEndedEarly(SectionEndInfo&& endInfo) { @@ -6012,18 +6168,6 @@ namespace Catch { m_reporter->benchmarkFailed( error ); } - void RunContext::pushScopedMessage(MessageInfo const & message) { - m_messages.push_back(message); - } - - void RunContext::popScopedMessage(MessageInfo const & message) { - m_messages.erase(std::remove(m_messages.begin(), m_messages.end(), message), m_messages.end()); - } - - void RunContext::emplaceUnscopedMessage( MessageBuilder&& builder ) { - m_messageScopes.emplace_back( CATCH_MOVE(builder) ); - } - std::string RunContext::getCurrentTestName() const { return m_activeTestCase ? m_activeTestCase->getTestCaseInfo().name @@ -6031,6 +6175,18 @@ namespace Catch { } const AssertionResult * RunContext::getLastResult() const { + // m_lastResult is updated inside the assertion slow-path, under + // a mutex, so the read needs to happen under mutex as well. + + // TBD: The last result only makes sense if it is a thread-local + // thing, because the answer is different per thread, like + // last line info, whether last assertion passed, and so on. + // + // However, the last result was also never updated in the + // assertion fast path, so it was always somewhat broken, + // and since IResultCapture::getLastResult is deprecated, + // we will leave it as is, until it is finally removed. + Detail::LockGuard _( m_assertionMutex ); return &(*m_lastResult); } @@ -6039,28 +6195,44 @@ namespace Catch { } void RunContext::handleFatalErrorCondition( StringRef message ) { - // TODO: scoped deactivate here? Just give up and do best effort? - // the deactivation can break things further, OTOH so can the - // capture - auto _ = scopedDeactivate( *m_outputRedirect ); + // We lock only when touching the reporters directly, to avoid + // deadlocks when we call into other functions that also want + // to lock the mutex before touching reporters. + // + // This does mean that we allow other threads to run while handling + // a fatal error, but this is all a best effort attempt anyway. + { + Detail::LockGuard lock( m_assertionMutex ); + // TODO: scoped deactivate here? Just give up and do best effort? + // the deactivation can break things further, OTOH so can the + // capture + auto _ = scopedDeactivate( *m_outputRedirect ); - // First notify reporter that bad things happened - m_reporter->fatalErrorEncountered( message ); + // First notify reporter that bad things happened + m_reporter->fatalErrorEncountered( message ); + } // Don't rebuild the result -- the stringification itself can cause more fatal errors // Instead, fake a result data. AssertionResultData tempResult( ResultWas::FatalErrorCondition, { false } ); tempResult.message = static_cast(message); - AssertionResult result(m_lastAssertionInfo, CATCH_MOVE(tempResult)); + AssertionResult result( makeDummyAssertionInfo(), + CATCH_MOVE( tempResult ) ); assertionEnded(CATCH_MOVE(result) ); - resetAssertionInfo(); + + + // At this point we touch sections/test cases from this thread + // to try and end them. Technically that is not supported when + // using multiple threads, but the worst thing that can happen + // is that the process aborts harder :-D + Detail::LockGuard lock( m_assertionMutex ); // Best effort cleanup for sections that have not been destructed yet // Since this is a fatal error, we have not had and won't have the opportunity to destruct them properly while (!m_activeSections.empty()) { - auto nl = m_activeSections.back()->nameAndLocation(); - SectionEndInfo endInfo{ SectionInfo(CATCH_MOVE(nl.location), CATCH_MOVE(nl.name)), {}, 0.0 }; + auto const& nl = m_activeSections.back()->nameAndLocation(); + SectionEndInfo endInfo{ SectionInfo(nl.location, nl.name), {}, 0.0 }; sectionEndedEarly(CATCH_MOVE(endInfo)); } handleUnfinishedSections(); @@ -6085,32 +6257,44 @@ namespace Catch { std::string(), false)); m_totals.testCases.failed++; + updateTotalsFromAtomics(); m_reporter->testRunEnded(TestRunStats(m_runInfo, m_totals, false)); } bool RunContext::lastAssertionPassed() { - return m_lastAssertionPassed; + return Detail::g_lastAssertionPassed; + } + + void RunContext::assertionPassedFastPath(SourceLineInfo lineInfo) { + // We want to save the line info for better experience with unexpected assertions + Detail::g_lastKnownLineInfo = lineInfo; + ++m_atomicAssertionCount.passed; + Detail::g_lastAssertionPassed = true; + Detail::g_clearMessageScopes = true; } - void RunContext::assertionPassed() { - m_lastAssertionPassed = true; - ++m_totals.assertions.passed; - resetAssertionInfo(); - m_messageScopes.clear(); + void RunContext::updateTotalsFromAtomics() { + m_totals.assertions = Counts{ + m_atomicAssertionCount.passed, + m_atomicAssertionCount.failed, + m_atomicAssertionCount.failedButOk, + m_atomicAssertionCount.skipped, + }; } bool RunContext::aborting() const { - return m_totals.assertions.failed >= static_cast(m_config->abortAfter()); + return m_atomicAssertionCount.failed >= m_abortAfterXFailedAssertions; } void RunContext::runCurrentTest() { auto const& testCaseInfo = m_activeTestCase->getTestCaseInfo(); SectionInfo testCaseSection(testCaseInfo.lineInfo, testCaseInfo.name); m_reporter->sectionStarting(testCaseSection); + updateTotalsFromAtomics(); Counts prevAssertions = m_totals.assertions; double duration = 0; m_shouldReportUnexpected = true; - m_lastAssertionInfo = { "TEST_CASE"_sr, testCaseInfo.lineInfo, StringRef(), ResultDisposition::Normal }; + Detail::g_lastKnownLineInfo = testCaseInfo.lineInfo; Timer timer; CATCH_TRY { @@ -6127,18 +6311,23 @@ namespace Catch { } CATCH_CATCH_ALL { // Under CATCH_CONFIG_FAST_COMPILE, unexpected exceptions under REQUIRE assertions // are reported without translation at the point of origin. - if( m_shouldReportUnexpected ) { + if ( m_shouldReportUnexpected ) { AssertionReaction dummyReaction; - handleUnexpectedInflightException( m_lastAssertionInfo, translateActiveException(), dummyReaction ); + handleUnexpectedInflightException( makeDummyAssertionInfo(), + translateActiveException(), + dummyReaction ); } } + updateTotalsFromAtomics(); Counts assertions = m_totals.assertions - prevAssertions; bool missingAssertions = testForMissingAssertions(assertions); m_testCaseTracker->close(); handleUnfinishedSections(); - m_messages.clear(); - m_messageScopes.clear(); + Detail::g_messageScopes.clear(); + // TBD: At this point, m_messages should be empty. Do we want to + // assert that this is true, or keep the defensive clear call? + Detail::g_messages.clear(); SectionStats testCaseSectionStats(CATCH_MOVE(testCaseSection), assertions, duration, missingAssertions); m_reporter->sectionEnded(testCaseSectionStats); @@ -6179,7 +6368,7 @@ namespace Catch { if( result ) { if (!m_includeSuccessfulResults) { - assertionPassed(); + assertionPassedFastPath(info.lineInfo); } else { reportExpr(info, ResultWas::Ok, &expr, negated); @@ -6187,9 +6376,9 @@ namespace Catch { } else { reportExpr(info, ResultWas::ExpressionFailed, &expr, negated ); - populateReaction( reaction ); + populateReaction( + reaction, info.resultDisposition & ResultDisposition::Normal ); } - resetAssertionInfo(); } void RunContext::reportExpr( AssertionInfo const &info, @@ -6197,7 +6386,7 @@ namespace Catch { ITransientExpression const *expr, bool negated ) { - m_lastAssertionInfo = info; + Detail::g_lastKnownLineInfo = info.lineInfo; AssertionResultData data( resultType, LazyExpression( negated ) ); AssertionResult assertionResult{ info, CATCH_MOVE( data ) }; @@ -6212,24 +6401,25 @@ namespace Catch { std::string&& message, AssertionReaction& reaction ) { - m_lastAssertionInfo = info; + Detail::g_lastKnownLineInfo = info.lineInfo; AssertionResultData data( resultType, LazyExpression( false ) ); data.message = CATCH_MOVE( message ); - AssertionResult assertionResult{ m_lastAssertionInfo, + AssertionResult assertionResult{ info, CATCH_MOVE( data ) }; const auto isOk = assertionResult.isOk(); assertionEnded( CATCH_MOVE(assertionResult) ); if ( !isOk ) { - populateReaction( reaction ); + populateReaction( + reaction, info.resultDisposition & ResultDisposition::Normal ); } else if ( resultType == ResultWas::ExplicitSkip ) { // TODO: Need to handle this explicitly, as ExplicitSkip is // considered "OK" reaction.shouldSkip = true; } - resetAssertionInfo(); } + void RunContext::handleUnexpectedExceptionNotThrown( AssertionInfo const& info, AssertionReaction& reaction @@ -6242,55 +6432,88 @@ namespace Catch { std::string&& message, AssertionReaction& reaction ) { - m_lastAssertionInfo = info; + Detail::g_lastKnownLineInfo = info.lineInfo; AssertionResultData data( ResultWas::ThrewException, LazyExpression( false ) ); data.message = CATCH_MOVE(message); AssertionResult assertionResult{ info, CATCH_MOVE(data) }; assertionEnded( CATCH_MOVE(assertionResult) ); - populateReaction( reaction ); - resetAssertionInfo(); + populateReaction( reaction, + info.resultDisposition & ResultDisposition::Normal ); } - void RunContext::populateReaction( AssertionReaction& reaction ) { - reaction.shouldDebugBreak = m_config->shouldDebugBreak(); - reaction.shouldThrow = aborting() || (m_lastAssertionInfo.resultDisposition & ResultDisposition::Normal); + void RunContext::populateReaction( AssertionReaction& reaction, + bool has_normal_disposition ) { + reaction.shouldDebugBreak = m_shouldDebugBreak; + reaction.shouldThrow = aborting() || has_normal_disposition; + } + + AssertionInfo RunContext::makeDummyAssertionInfo() { + const bool testCaseJustStarted = + Detail::g_lastKnownLineInfo == + m_activeTestCase->getTestCaseInfo().lineInfo; + + return AssertionInfo{ + testCaseJustStarted ? "TEST_CASE"_sr : StringRef(), + Detail::g_lastKnownLineInfo, + testCaseJustStarted ? StringRef() : "{Unknown expression after the reported line}"_sr, + ResultDisposition::Normal + }; } void RunContext::handleIncomplete( AssertionInfo const& info ) { using namespace std::string_literals; - m_lastAssertionInfo = info; + Detail::g_lastKnownLineInfo = info.lineInfo; AssertionResultData data( ResultWas::ThrewException, LazyExpression( false ) ); data.message = "Exception translation was disabled by CATCH_CONFIG_FAST_COMPILE"s; AssertionResult assertionResult{ info, CATCH_MOVE( data ) }; assertionEnded( CATCH_MOVE(assertionResult) ); - resetAssertionInfo(); } + void RunContext::handleNonExpr( AssertionInfo const &info, ResultWas::OfType resultType, AssertionReaction &reaction ) { - m_lastAssertionInfo = info; - AssertionResultData data( resultType, LazyExpression( false ) ); AssertionResult assertionResult{ info, CATCH_MOVE( data ) }; const auto isOk = assertionResult.isOk(); + if ( isOk && !m_includeSuccessfulResults ) { + assertionPassedFastPath( info.lineInfo ); + return; + } + assertionEnded( CATCH_MOVE(assertionResult) ); - if ( !isOk ) { populateReaction( reaction ); } - resetAssertionInfo(); + if ( !isOk ) { + populateReaction( + reaction, info.resultDisposition & ResultDisposition::Normal ); + } } + void IResultCapture::pushScopedMessage( MessageInfo&& message ) { + Detail::g_messages.push_back( CATCH_MOVE( message ) ); + } - IResultCapture& getResultCapture() { - if (auto* capture = getCurrentContext().getResultCapture()) - return *capture; - else - CATCH_INTERNAL_ERROR("No result capture instance"); + void IResultCapture::popScopedMessage( unsigned int messageId ) { + // Note: On average, it would probably be better to look for the message + // backwards. However, we do not expect to have to deal with more + // messages than low single digits, so the optimization is tiny, + // and we would have to hand-write the loop to avoid terrible + // codegen of reverse iterators in debug mode. + Detail::g_messages.erase( std::find_if( Detail::g_messages.begin(), + Detail::g_messages.end(), + [=]( MessageInfo const& msg ) { + return msg.sequence == + messageId; + } ) ); + } + + void IResultCapture::emplaceUnscopedMessage( MessageBuilder&& builder ) { + Detail::g_messageScopes.emplace_back( CATCH_MOVE( builder ) ); } void seedRng(IConfig const& config) { @@ -6516,7 +6739,7 @@ namespace Catch { std::string origStr = CATCH_MOVE(str); str.clear(); // There is at least one replacement, so reserve with the best guess - // we can make without actually counting the number of occurences. + // we can make without actually counting the number of occurrences. str.reserve(origStr.size() - replaceThis.size() + withThis.size()); do { str.append(origStr, copyBegin, i-copyBegin ); @@ -6562,7 +6785,6 @@ namespace Catch { #include #include #include -#include namespace Catch { StringRef::StringRef( char const* rawChars ) noexcept @@ -7859,7 +8081,7 @@ namespace { void hexEscapeChar(std::ostream& os, unsigned char c) { std::ios_base::fmtflags f(os.flags()); - os << "\\x" + os << "\\x"_sr << std::uppercase << std::hex << std::setfill('0') << std::setw(2) << static_cast(c); os.flags(f); @@ -7878,95 +8100,111 @@ namespace { void XmlEncode::encodeTo( std::ostream& os ) const { // Apostrophe escaping not necessary if we always use " to write attributes // (see: http://www.w3.org/TR/xml/#syntax) + size_t last_start = 0; + auto write_to = [&]( size_t idx ) { + if ( last_start < idx ) { + os << m_str.substr( last_start, idx - last_start ); + } + last_start = idx + 1; + }; - for( std::size_t idx = 0; idx < m_str.size(); ++ idx ) { - unsigned char c = static_cast(m_str[idx]); - switch (c) { - case '<': os << "<"; break; - case '&': os << "&"; break; + for ( std::size_t idx = 0; idx < m_str.size(); ++idx ) { + unsigned char c = static_cast( m_str[idx] ); + switch ( c ) { + case '<': + write_to( idx ); + os << "<"_sr; + break; + case '&': + write_to( idx ); + os << "&"_sr; + break; case '>': // See: http://www.w3.org/TR/xml/#syntax - if (idx > 2 && m_str[idx - 1] == ']' && m_str[idx - 2] == ']') - os << ">"; - else - os << c; + if ( idx > 2 && m_str[idx - 1] == ']' && m_str[idx - 2] == ']' ) { + write_to( idx ); + os << ">"_sr; + } break; case '\"': - if (m_forWhat == ForAttributes) - os << """; - else - os << c; + if ( m_forWhat == ForAttributes ) { + write_to( idx ); + os << """_sr; + } break; default: // Check for control characters and invalid utf-8 // Escape control characters in standard ascii - // see http://stackoverflow.com/questions/404107/why-are-control-characters-illegal-in-xml-1-0 - if (c < 0x09 || (c > 0x0D && c < 0x20) || c == 0x7F) { - hexEscapeChar(os, c); + // see + // http://stackoverflow.com/questions/404107/why-are-control-characters-illegal-in-xml-1-0 + if ( c < 0x09 || ( c > 0x0D && c < 0x20 ) || c == 0x7F ) { + write_to( idx ); + hexEscapeChar( os, c ); break; } // Plain ASCII: Write it to stream - if (c < 0x7F) { - os << c; + if ( c < 0x7F ) { break; } // UTF-8 territory - // Check if the encoding is valid and if it is not, hex escape bytes. - // Important: We do not check the exact decoded values for validity, only the encoding format - // First check that this bytes is a valid lead byte: - // This means that it is not encoded as 1111 1XXX + // Check if the encoding is valid and if it is not, hex escape + // bytes. Important: We do not check the exact decoded values for + // validity, only the encoding format First check that this bytes is + // a valid lead byte: This means that it is not encoded as 1111 1XXX // Or as 10XX XXXX - if (c < 0xC0 || - c >= 0xF8) { - hexEscapeChar(os, c); + if ( c < 0xC0 || c >= 0xF8 ) { + write_to( idx ); + hexEscapeChar( os, c ); break; } - auto encBytes = trailingBytes(c); - // Are there enough bytes left to avoid accessing out-of-bounds memory? - if (idx + encBytes - 1 >= m_str.size()) { - hexEscapeChar(os, c); + auto encBytes = trailingBytes( c ); + // Are there enough bytes left to avoid accessing out-of-bounds + // memory? + if ( idx + encBytes - 1 >= m_str.size() ) { + write_to( idx ); + hexEscapeChar( os, c ); break; } // The header is valid, check data // The next encBytes bytes must together be a valid utf-8 - // This means: bitpattern 10XX XXXX and the extracted value is sane (ish) + // This means: bitpattern 10XX XXXX and the extracted value is sane + // (ish) bool valid = true; - uint32_t value = headerValue(c); - for (std::size_t n = 1; n < encBytes; ++n) { - unsigned char nc = static_cast(m_str[idx + n]); - valid &= ((nc & 0xC0) == 0x80); - value = (value << 6) | (nc & 0x3F); + uint32_t value = headerValue( c ); + for ( std::size_t n = 1; n < encBytes; ++n ) { + unsigned char nc = static_cast( m_str[idx + n] ); + valid &= ( ( nc & 0xC0 ) == 0x80 ); + value = ( value << 6 ) | ( nc & 0x3F ); } if ( // Wrong bit pattern of following bytes - (!valid) || + ( !valid ) || // Overlong encodings - (value < 0x80) || - (0x80 <= value && value < 0x800 && encBytes > 2) || - (0x800 < value && value < 0x10000 && encBytes > 3) || + ( value < 0x80 ) || + ( 0x80 <= value && value < 0x800 && encBytes > 2 ) || + ( 0x800 < value && value < 0x10000 && encBytes > 3 ) || // Encoded value out of range - (value >= 0x110000) - ) { - hexEscapeChar(os, c); + ( value >= 0x110000 ) ) { + write_to( idx ); + hexEscapeChar( os, c ); break; } // If we got here, this is in fact a valid(ish) utf-8 sequence - for (std::size_t n = 0; n < encBytes; ++n) { - os << m_str[idx + n]; - } idx += encBytes - 1; break; } } + + write_to( m_str.size() ); } std::ostream& operator << ( std::ostream& os, XmlEncode const& xmlEncode ) { @@ -8877,7 +9115,8 @@ class AssertionPrinter { << m_config->testSpec() << '\n'; } - m_stream << "RNG seed: " << getSeed() << '\n'; + m_stream << "RNG seed: " << getSeed() << '\n' + << std::flush; } void CompactReporter::assertionEnded( AssertionStats const& _assertionStats ) { @@ -9298,7 +9537,10 @@ ConsoleReporter::ConsoleReporter(ReporterConfig&& config): { "est run time high mean high std dev", 14, Justification::Right } }; } - }())) {} + }())) { + m_preferences.shouldReportAllAssertionStarts = false; +} + ConsoleReporter::~ConsoleReporter() = default; std::string ConsoleReporter::getDescription() { @@ -9313,8 +9555,6 @@ void ConsoleReporter::reportInvalidTestSpec( StringRef arg ) { m_stream << "Invalid Filter: " << arg << '\n'; } -void ConsoleReporter::assertionStarting(AssertionInfo const&) {} - void ConsoleReporter::assertionEnded(AssertionStats const& _assertionStats) { AssertionResult const& result = _assertionStats.assertionResult; @@ -9426,7 +9666,8 @@ void ConsoleReporter::testRunStarting(TestRunInfo const& _testRunInfo) { m_stream << m_colour->guardColour( Colour::BrightYellow ) << "Filters: " << m_config->testSpec() << '\n'; } - m_stream << "Randomness seeded to: " << getSeed() << '\n'; + m_stream << "Randomness seeded to: " << getSeed() << '\n' + << std::flush; } void ConsoleReporter::lazyPrint() { @@ -9754,6 +9995,7 @@ namespace Catch { #include #include +#include #include #include #include @@ -9917,9 +10159,29 @@ namespace Catch { out << "All available tags:\n"; } + // minimum whitespace to pad tag counts, possibly overwritten below + size_t maxTagCountLen = 2; + + // determine necessary padding for tag count column + if ( ! tags.empty() ) { + const auto maxTagCount = + std::max_element( tags.begin(), + tags.end(), + []( auto const& lhs, auto const& rhs ) { + return lhs.count < rhs.count; + } ) + ->count; + + // more padding necessary for 3+ digits + if (maxTagCount >= 100) { + auto numDigits = 1 + std::floor( std::log10( maxTagCount ) ); + maxTagCountLen = static_cast( numDigits ); + } + } + for ( auto const& tagCount : tags ) { ReusableStringStream rss; - rss << " " << std::setw( 2 ) << tagCount.count << " "; + rss << " " << std::setw( maxTagCountLen ) << tagCount.count << " "; auto str = rss.str(); auto wrapper = TextFlow::Column( tagCount.all() ) .initialIndent( 0 ) @@ -10117,6 +10379,8 @@ namespace Catch { // not, but for machine-parseable reporters I think the answer // should be yes. m_preferences.shouldReportAllAssertions = true; + // We only handle assertions when they end + m_preferences.shouldReportAllAssertionStarts = false; m_objectWriters.emplace( m_stream ); m_writers.emplace( Writer::Object ); @@ -10346,7 +10610,6 @@ namespace Catch { endObject(); } - void JsonReporter::assertionStarting( AssertionInfo const& /*assertionInfo*/ ) {} void JsonReporter::assertionEnded( AssertionStats const& assertionStats ) { // TODO: There is lot of different things to handle here, but // we can fill it in later, after we show that the basic @@ -10513,6 +10776,7 @@ namespace Catch { { m_preferences.shouldRedirectStdOut = true; m_preferences.shouldReportAllAssertions = false; + m_preferences.shouldReportAllAssertionStarts = false; m_shouldStoreSuccesfulAssertions = false; } @@ -10743,6 +11007,8 @@ namespace Catch { reporterish.getPreferences().shouldRedirectStdOut; m_preferences.shouldReportAllAssertions |= reporterish.getPreferences().shouldReportAllAssertions; + m_preferences.shouldReportAllAssertionStarts |= + reporterish.getPreferences().shouldReportAllAssertionStarts; } void MultiReporter::addListener( IEventListenerPtr&& listener ) { @@ -11300,7 +11566,8 @@ namespace Catch { if ( m_config->testSpec().hasFilters() ) { m_stream << "# filters: " << m_config->testSpec() << '\n'; } - m_stream << "# rng-seed: " << m_config->rngSeed() << '\n'; + m_stream << "# rng-seed: " << m_config->rngSeed() << '\n' + << std::flush; } void TAPReporter::noMatchingTestCases( StringRef unmatchedSpec ) { @@ -11514,6 +11781,7 @@ namespace Catch { { m_preferences.shouldRedirectStdOut = true; m_preferences.shouldReportAllAssertions = true; + m_preferences.shouldReportAllAssertionStarts = false; } XmlReporter::~XmlReporter() = default; @@ -11570,8 +11838,6 @@ namespace Catch { } } - void XmlReporter::assertionStarting( AssertionInfo const& ) { } - void XmlReporter::assertionEnded( AssertionStats const& assertionStats ) { AssertionResult const& result = assertionStats.assertionResult; diff --git a/catch2/extras/catch_amalgamated.hpp b/catch2/extras/catch_amalgamated.hpp index 7703e95..d5eb1bb 100644 --- a/catch2/extras/catch_amalgamated.hpp +++ b/catch2/extras/catch_amalgamated.hpp @@ -6,8 +6,8 @@ // SPDX-License-Identifier: BSL-1.0 -// Catch v3.8.1 -// Generated: 2025-04-08 12:33:19.851017 +// Catch v3.11.0 +// Generated: 2025-09-30 10:49:11.225746 // ---------------------------------------------------------- // This file is an amalgamation of multiple different files. // You probably shouldn't edit it directly. @@ -101,6 +101,9 @@ #elif defined(linux) || defined(__linux) || defined(__linux__) # define CATCH_PLATFORM_LINUX +#elif defined(__QNX__) +# define CATCH_PLATFORM_QNX + #elif defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) || defined(__MINGW32__) # define CATCH_PLATFORM_WINDOWS @@ -308,13 +311,17 @@ # endif // Universal Windows platform does not support SEH -// Or console colours (or console at all...) -# if defined(CATCH_PLATFORM_WINDOWS_UWP) -# define CATCH_INTERNAL_CONFIG_NO_COLOUR_WIN32 -# else +# if !defined(CATCH_PLATFORM_WINDOWS_UWP) # define CATCH_INTERNAL_CONFIG_WINDOWS_SEH # endif +// Only some Windows platform families support the console +# if defined(WINAPI_FAMILY_PARTITION) +# if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_SYSTEM) +# define CATCH_INTERNAL_CONFIG_NO_COLOUR_WIN32 +# endif +# endif + // MSVC traditional preprocessor needs some workaround for __VA_ARGS__ // _MSVC_TRADITIONAL == 0 means new conformant preprocessor // _MSVC_TRADITIONAL == 1 means old traditional non-conformant preprocessor @@ -564,11 +571,9 @@ namespace Catch { IConfig const* m_config = nullptr; IResultCapture* m_resultCapture = nullptr; - CATCH_EXPORT static Context* currentContext; + CATCH_EXPORT static Context currentContext; friend Context& getCurrentMutableContext(); friend Context const& getCurrentContext(); - static void createContext(); - friend void cleanUpContext(); public: constexpr IResultCapture* getResultCapture() const { @@ -579,21 +584,14 @@ namespace Catch { m_resultCapture = resultCapture; } constexpr void setConfig( IConfig const* config ) { m_config = config; } - }; Context& getCurrentMutableContext(); inline Context const& getCurrentContext() { - // We duplicate the logic from `getCurrentMutableContext` here, - // to avoid paying the call overhead in debug mode. - if ( !Context::currentContext ) { Context::createContext(); } - // NOLINTNEXTLINE(clang-analyzer-core.uninitialized.UndefReturn) - return *Context::currentContext; + return Context::currentContext; } - void cleanUpContext(); - class SimplePcg32; SimplePcg32& sharedRng(); } @@ -958,7 +956,7 @@ namespace Detail { } explicit operator bool() const { - return m_ptr; + return m_ptr != nullptr; } friend void swap(unique_ptr& lhs, unique_ptr& rhs) { @@ -1069,10 +1067,9 @@ namespace Catch { virtual void benchmarkEnded( BenchmarkStats<> const& stats ) = 0; virtual void benchmarkFailed( StringRef error ) = 0; - virtual void pushScopedMessage( MessageInfo const& message ) = 0; - virtual void popScopedMessage( MessageInfo const& message ) = 0; - - virtual void emplaceUnscopedMessage( MessageBuilder&& builder ) = 0; + static void pushScopedMessage( MessageInfo&& message ); + static void popScopedMessage( unsigned int messageId ); + static void emplaceUnscopedMessage( MessageBuilder&& builder ); virtual void handleFatalErrorCondition( StringRef message ) = 0; @@ -1100,9 +1097,7 @@ namespace Catch { AssertionReaction &reaction ) = 0; - virtual bool lastAssertionPassed() = 0; - virtual void assertionPassed() = 0; // Deprecated, do not use: virtual std::string getCurrentTestName() const = 0; @@ -1110,7 +1105,18 @@ namespace Catch { virtual void exceptionEarlyReported() = 0; }; - IResultCapture& getResultCapture(); + namespace Detail { + [[noreturn]] + void missingCaptureInstance(); + } + inline IResultCapture& getResultCapture() { + if (auto* capture = getCurrentContext().getResultCapture()) { + return *capture; + } else { + Detail::missingCaptureInstance(); + } + } + } #endif // CATCH_INTERFACES_CAPTURE_HPP_INCLUDED @@ -1129,6 +1135,7 @@ namespace Catch { //! Deriving classes become noncopyable and nonmovable class NonCopyable { + public: NonCopyable( NonCopyable const& ) = delete; NonCopyable( NonCopyable&& ) = delete; NonCopyable& operator=( NonCopyable const& ) = delete; @@ -1144,7 +1151,6 @@ namespace Catch { #endif // CATCH_NONCOPYABLE_HPP_INCLUDED #include -#include #include #include @@ -1599,8 +1605,7 @@ namespace Catch { namespace Benchmark { namespace Detail { template - struct is_related - : std::is_same, std::decay_t> {}; + static constexpr bool is_related_v = std::is_same, std::decay_t>::value; /// We need to reinvent std::function because every piece of code that might add overhead /// in a measurement context needs to have consistent performance characteristics so that we @@ -1641,7 +1646,7 @@ namespace Catch { BenchmarkFunction(); template ::value, int> = 0> + std::enable_if_t, int> = 0> BenchmarkFunction(Fun&& fun) : f(new model>(CATCH_FORWARD(fun))) {} @@ -1767,8 +1772,6 @@ namespace Catch { #define CATCH_TIMING_HPP_INCLUDED -#include - namespace Catch { namespace Benchmark { template @@ -2156,9 +2159,7 @@ namespace Catch { auto analysis = Detail::analyse(*cfg, samples.data(), samples.data() + samples.size()); BenchmarkStats<> stats{ CATCH_MOVE(info), CATCH_MOVE(analysis.samples), analysis.mean, analysis.standard_deviation, analysis.outliers, analysis.outlier_variance }; getResultCapture().benchmarkEnded(stats); - } CATCH_CATCH_ANON (TestFailureException const&) { - getResultCapture().benchmarkFailed("Benchmark failed due to failed assertion"_sr); - } CATCH_CATCH_ALL{ + } CATCH_CATCH_ALL { getResultCapture().benchmarkFailed(translateActiveException()); // We let the exception go further up so that the // test case is marked as failed. @@ -2167,7 +2168,7 @@ namespace Catch { } // sets lambda to be used in fun *and* executes benchmark! - template ::value, int> = 0> + template , int> = 0> Benchmark & operator=(Fun func) { auto const* cfg = getCurrentContext().getConfig(); if (!cfg->skipBenchmarks()) { @@ -2496,18 +2497,14 @@ namespace Catch { return rawMemoryToString( &object, sizeof(object) ); } - template - class IsStreamInsertable { - template - static auto test(int) - -> decltype(std::declval() << std::declval(), std::true_type()); - - template - static auto test(...)->std::false_type; + template + static constexpr bool IsStreamInsertable_v = false; - public: - static const bool value = decltype(test(0))::value; - }; + template + static constexpr bool IsStreamInsertable_v< + T, + decltype( void( std::declval() << std::declval() ) )> = + true; template std::string convertUnknownEnumToString( E e ); @@ -2552,7 +2549,7 @@ namespace Catch { struct StringMaker { template static - std::enable_if_t<::Catch::Detail::IsStreamInsertable::value, std::string> + std::enable_if_t<::Catch::Detail::IsStreamInsertable_v, std::string> convert(const Fake& value) { ReusableStringStream rss; // NB: call using the function-like syntax to avoid ambiguity with @@ -2563,7 +2560,7 @@ namespace Catch { template static - std::enable_if_t::value, std::string> + std::enable_if_t, std::string> convert( const Fake& value ) { #if !defined(CATCH_CONFIG_FALLBACK_STRINGIFIER) return Detail::convertUnstreamable(value); @@ -2575,11 +2572,17 @@ namespace Catch { namespace Detail { + std::string makeExceptionHappenedString(); + // This function dispatches all stringification requests inside of Catch. // Should be preferably called fully qualified, like ::Catch::Detail::stringify template - std::string stringify(const T& e) { - return ::Catch::StringMaker>>::convert(e); + std::string stringify( const T& e ) { + CATCH_TRY { + return ::Catch::StringMaker< + std::remove_cv_t>>::convert( e ); + } + CATCH_CATCH_ALL { return makeExceptionHappenedString(); } } template @@ -2955,7 +2958,7 @@ namespace Catch { } template - struct StringMaker::value && !::Catch::Detail::IsStreamInsertable::value>> { + struct StringMaker::value && !::Catch::Detail::IsStreamInsertable_v>> { static std::string convert( R const& range ) { return rangeToString( range ); } @@ -3062,17 +3065,19 @@ struct ratio_string { template struct StringMaker> { static std::string convert(std::chrono::time_point const& time_point) { - auto converted = std::chrono::system_clock::to_time_t(time_point); + const auto systemish = std::chrono::time_point_cast< + std::chrono::system_clock::duration>( time_point ); + const auto as_time_t = std::chrono::system_clock::to_time_t( systemish ); #ifdef _MSC_VER std::tm timeInfo = {}; - const auto err = gmtime_s(&timeInfo, &converted); + const auto err = gmtime_s( &timeInfo, &as_time_t ); if ( err ) { return "gmtime from provided timepoint has failed. This " "happens e.g. with pre-1970 dates using Microsoft libc"; } #else - std::tm* timeInfo = std::gmtime(&converted); + std::tm* timeInfo = std::gmtime( &as_time_t ); #endif auto const timeStampSize = sizeof("2017-01-16T17:06:45Z"); @@ -3792,7 +3797,7 @@ namespace Catch { WarnAbout::What warnings = WarnAbout::Nothing; ShowDurations showDurations = ShowDurations::DefaultForReporter; double minDuration = -1; - TestRunOrder runOrder = TestRunOrder::Declared; + TestRunOrder runOrder = TestRunOrder::Randomized; ColourMode defaultColourMode = ColourMode::PlatformDefault; WaitForKeypress::When waitForKeypress = WaitForKeypress::Never; @@ -3803,6 +3808,8 @@ namespace Catch { std::vector testsOrTags; std::vector sectionsToRun; + + std::string prematureExitGuardFilePath; }; @@ -3830,6 +3837,8 @@ namespace Catch { bool showHelp() const; + std::string const& getExitGuardFilePath() const; + // IConfig interface bool allowThrows() const override; StringRef name() const override; @@ -3938,6 +3947,19 @@ namespace Catch { #define CATCH_MESSAGE_INFO_HPP_INCLUDED + +#ifndef CATCH_DEPRECATION_MACRO_HPP_INCLUDED +#define CATCH_DEPRECATION_MACRO_HPP_INCLUDED + + +#if !defined( CATCH_CONFIG_NO_DEPRECATION_ANNOTATIONS ) +# define DEPRECATED( msg ) [[deprecated( msg )]] +#else +# define DEPRECATED( msg ) +#endif + +#endif // CATCH_DEPRECATION_MACRO_HPP_INCLUDED + #include namespace Catch { @@ -3951,16 +3973,19 @@ namespace Catch { std::string message; SourceLineInfo lineInfo; ResultWas::OfType type; + // The "ID" of the message, used to know when to remove it from reporter context. unsigned int sequence; + DEPRECATED( "Explicitly use the 'sequence' member instead" ) bool operator == (MessageInfo const& other) const { return sequence == other.sequence; } + DEPRECATED( "Explicitly use the 'sequence' member instead" ) bool operator < (MessageInfo const& other) const { return sequence < other.sequence; } private: - static unsigned int globalCount; + static thread_local unsigned int globalCount; }; } // end namespace Catch @@ -4008,13 +4033,12 @@ namespace Catch { ScopedMessage( ScopedMessage&& old ) noexcept; ~ScopedMessage(); - MessageInfo m_info; + unsigned int m_messageId; bool m_moved = false; }; class Capturer { std::vector m_messages; - IResultCapture& m_resultCapture; size_t m_captured = 0; public: Capturer( StringRef macroName, SourceLineInfo const& lineInfo, ResultWas::OfType resultType, StringRef names ); @@ -4062,7 +4086,7 @@ namespace Catch { /////////////////////////////////////////////////////////////////////////////// #define INTERNAL_CATCH_UNSCOPED_INFO( macroName, log ) \ - Catch::getResultCapture().emplaceUnscopedMessage( Catch::MessageBuilder( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log ) + Catch::IResultCapture::emplaceUnscopedMessage( Catch::MessageBuilder( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log ) #if defined(CATCH_CONFIG_PREFIX_MESSAGES) && !defined(CATCH_CONFIG_DISABLE) @@ -4237,15 +4261,13 @@ namespace Catch { }; template - struct is_unary_function : std::false_type {}; + static constexpr bool is_unary_function_v = false; template - struct is_unary_function< + static constexpr bool is_unary_function_v< F, - Catch::Detail::void_t()( fake_arg() ) ) - > - > : std::true_type {}; + Catch::Detail::void_t()( + fake_arg() ) )>> = true; // Traits for extracting arg and return type of lambdas (for single // argument lambdas) @@ -4678,14 +4700,14 @@ namespace Catch { template ::value>> + !Detail::is_unary_function_v>> ParserRefImpl( T& ref, StringRef hint ): m_ref( std::make_shared>( ref ) ), m_hint( hint ) {} template ::value>> + Detail::is_unary_function_v>> ParserRefImpl( LambdaT const& ref, StringRef hint ): m_ref( std::make_shared>( ref ) ), m_hint( hint ) {} @@ -4752,7 +4774,7 @@ namespace Catch { template ::value>> + Detail::is_unary_function_v>> Opt( LambdaT const& ref, StringRef hint ): ParserRefImpl( ref, hint ) {} @@ -4762,7 +4784,7 @@ namespace Catch { template ::value>> + !Detail::is_unary_function_v>> Opt( T& ref, StringRef hint ): ParserRefImpl( ref, hint ) {} @@ -4932,6 +4954,14 @@ namespace Catch { namespace Catch { + // TODO: Use C++17 `inline` variables + constexpr int UnspecifiedErrorExitCode = 1; + constexpr int NoTestsRunExitCode = 2; + constexpr int UnmatchedTestSpecExitCode = 3; + constexpr int AllTestsSkippedExitCode = 4; + constexpr int InvalidTestSpecExitCode = 5; + constexpr int TestFailureExitCode = 42; + class Session : Detail::NonCopyable { public: @@ -5016,7 +5046,7 @@ namespace Catch { #define CATCH_REGISTER_TAG_ALIAS( alias, spec ) \ CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ - namespace{ Catch::RegistrarForTagAliases INTERNAL_CATCH_UNIQUE_NAME( AutoRegisterTagAlias )( alias, spec, CATCH_INTERNAL_LINEINFO ); } \ + namespace{ const Catch::RegistrarForTagAliases INTERNAL_CATCH_UNIQUE_NAME( AutoRegisterTagAlias )( alias, spec, CATCH_INTERNAL_LINEINFO ); } \ CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION #endif // CATCH_TAG_ALIAS_AUTOREGISTRAR_HPP_INCLUDED @@ -5193,7 +5223,7 @@ namespace Detail { * when the compiler handles `ExprLhs == b`, it also tries to resolve * the overload set for `b == ExprLhs`. * - * To accomodate these use cases, decomposer ended up rather complex. + * To accommodate these use cases, decomposer ended up rather complex. * * 1) These types are handled by adding SFINAE overloads to our comparison * operators, checking whether `T == U` are comparable with the given @@ -5226,10 +5256,11 @@ namespace Detail { * * 3) If a type has no linkage, we also cannot capture it by reference. * The solution is once again to capture them by value. We handle - * the common cases by using `std::is_arithmetic` as the default - * for `Catch::capture_by_value`, but that is only a some-effort - * heuristic. But as with 2), users can specialize `capture_by_value` - * for their own types as needed. + * the common cases by using `std::is_arithmetic` and `std::is_enum` + * as the default for `Catch::capture_by_value`, but that is only a + * some-effort heuristic. These combine to capture all possible bitfield + * bases, and also some trait-like types. As with 2), users can + * specialize `capture_by_value` for their own types as needed. * * 4) To support C++20 and make the SFINAE on our decomposing operators * work, the SFINAE has to happen in return type, rather than in @@ -5281,13 +5312,22 @@ namespace Catch { using RemoveCVRef_t = std::remove_cv_t>; } - // Note: There is nothing that stops us from extending this, - // e.g. to `std::is_scalar`, but the more encompassing - // traits are usually also more expensive. For now we - // keep this as it used to be and it can be changed later. + // Note: This is about as much as we can currently reasonably support. + // In an ideal world, we could capture by value small trivially + // copyable types, but the actual `std::is_trivially_copyable` + // trait is a huge mess with standard-violating results on + // GCC and Clang, which are unlikely to be fixed soon due to ABI + // concerns. + // `std::is_scalar` also causes issues due to the `is_pointer` + // component, which causes ambiguity issues with (references-to) + // function pointer. If those are resolved, we still need to + // disambiguate the overload set for arrays, through explicit + // overload for references to sized arrays. template struct capture_by_value - : std::integral_constant{}> {}; + : std::integral_constant::value || + std::is_enum::value> {}; #if defined( CATCH_CONFIG_CPP20_COMPARE_OVERLOADS ) template <> @@ -5311,7 +5351,7 @@ namespace Catch { public: constexpr auto isBinaryExpression() const -> bool { return m_isBinaryExpression; } constexpr auto getResult() const -> bool { return m_result; } - //! This function **has** to be overriden by the derived class. + //! This function **has** to be overridden by the derived class. virtual void streamReconstructedExpression( std::ostream& os ) const; constexpr ITransientExpression( bool isBinaryExpression, bool result ) @@ -5912,7 +5952,7 @@ namespace Catch { #else // These section definitions imply that at most one section at one level -// will be intered (because only one section's __LINE__ can be equal to +// will be entered (because only one section's __LINE__ can be equal to // the dummy `catchInternalSectionHint` variable from `TEST_CASE`). namespace Catch { @@ -6195,6 +6235,57 @@ static int catchInternalSectionHint = 0; #endif // CATCH_TEST_REGISTRY_HPP_INCLUDED +#ifndef CATCH_UNREACHABLE_HPP_INCLUDED +#define CATCH_UNREACHABLE_HPP_INCLUDED + +/**\file + * Polyfill `std::unreachable` + * + * We need something like `std::unreachable` to tell the compiler that + * some macros, e.g. `FAIL` or `SKIP`, do not continue execution in normal + * manner, and should handle it as such, e.g. not warn if there is no return + * from non-void function after a `FAIL` or `SKIP`. + */ + +#include + +#if defined( __cpp_lib_unreachable ) && __cpp_lib_unreachable > 202202L +# include +namespace Catch { + namespace Detail { + using Unreachable = std::unreachable; + } +} // namespace Catch + +#else // vv If we do not have std::unreachable, we implement something similar + +namespace Catch { + namespace Detail { + + [[noreturn]] + inline void Unreachable() noexcept { +# if defined( NDEBUG ) +# if defined( _MSC_VER ) && !defined( __clang__ ) + __assume( false ); +# elif defined( __GNUC__ ) + __builtin_unreachable(); +# else // vv platform without known optimization hint + std::terminate(); +# endif +# else // ^^ NDEBUG + // For non-release builds, we prefer termination on bug over UB + std::terminate(); +# endif // + } + + } // namespace Detail +} // end namespace Catch + +#endif + +#endif // CATCH_UNREACHABLE_HPP_INCLUDED + + // All of our user-facing macros support configuration toggle, that // forces them to be defined prefixed with CATCH_. We also like to // support another toggle that can minimize (disable) their implementation. @@ -6226,10 +6317,16 @@ static int catchInternalSectionHint = 0; #define CATCH_REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ ) #define CATCH_SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ ) #define CATCH_DYNAMIC_SECTION( ... ) INTERNAL_CATCH_DYNAMIC_SECTION( __VA_ARGS__ ) - #define CATCH_FAIL( ... ) INTERNAL_CATCH_MSG( "CATCH_FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, __VA_ARGS__ ) + #define CATCH_FAIL( ... ) do { \ + INTERNAL_CATCH_MSG("CATCH_FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, __VA_ARGS__ ); \ + Catch::Detail::Unreachable(); \ + } while ( false ) #define CATCH_FAIL_CHECK( ... ) INTERNAL_CATCH_MSG( "CATCH_FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) #define CATCH_SUCCEED( ... ) INTERNAL_CATCH_MSG( "CATCH_SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) - #define CATCH_SKIP( ... ) INTERNAL_CATCH_MSG( "SKIP", Catch::ResultWas::ExplicitSkip, Catch::ResultDisposition::Normal, __VA_ARGS__ ) + #define CATCH_SKIP( ... ) do { \ + INTERNAL_CATCH_MSG( "CATCH_SKIP", Catch::ResultWas::ExplicitSkip, Catch::ResultDisposition::Normal, __VA_ARGS__ ); \ + Catch::Detail::Unreachable(); \ + } while (false) #if !defined(CATCH_CONFIG_RUNTIME_STATIC_REQUIRE) @@ -6327,10 +6424,16 @@ static int catchInternalSectionHint = 0; #define REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ ) #define SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ ) #define DYNAMIC_SECTION( ... ) INTERNAL_CATCH_DYNAMIC_SECTION( __VA_ARGS__ ) - #define FAIL( ... ) INTERNAL_CATCH_MSG( "FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, __VA_ARGS__ ) + #define FAIL( ... ) do { \ + INTERNAL_CATCH_MSG( "FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, __VA_ARGS__ ); \ + Catch::Detail::Unreachable(); \ + } while (false) #define FAIL_CHECK( ... ) INTERNAL_CATCH_MSG( "FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) #define SUCCEED( ... ) INTERNAL_CATCH_MSG( "SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) - #define SKIP( ... ) INTERNAL_CATCH_MSG( "SKIP", Catch::ResultWas::ExplicitSkip, Catch::ResultDisposition::Normal, __VA_ARGS__ ) + #define SKIP( ... ) do { \ + INTERNAL_CATCH_MSG( "SKIP", Catch::ResultWas::ExplicitSkip, Catch::ResultDisposition::Normal, __VA_ARGS__ ); \ + Catch::Detail::Unreachable(); \ + } while (false) #if !defined(CATCH_CONFIG_RUNTIME_STATIC_REQUIRE) @@ -6424,6 +6527,15 @@ static int catchInternalSectionHint = 0; #endif +namespace Catch { + namespace Detail { + template + struct priority_tag : priority_tag {}; + template <> + struct priority_tag<0> {}; + } +} + #define CATCH_RECURSION_LEVEL0(...) __VA_ARGS__ #define CATCH_RECURSION_LEVEL1(...) CATCH_RECURSION_LEVEL0(CATCH_RECURSION_LEVEL0(CATCH_RECURSION_LEVEL0(__VA_ARGS__))) #define CATCH_RECURSION_LEVEL2(...) CATCH_RECURSION_LEVEL1(CATCH_RECURSION_LEVEL1(CATCH_RECURSION_LEVEL1(__VA_ARGS__))) @@ -6483,10 +6595,10 @@ static int catchInternalSectionHint = 0; #define INTERNAL_CATCH_MAKE_NAMESPACE(name) INTERNAL_CATCH_MAKE_NAMESPACE2(name) #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR -#define INTERNAL_CATCH_MAKE_TYPE_LIST2(...) decltype(get_wrapper()) +#define INTERNAL_CATCH_MAKE_TYPE_LIST2(...) decltype(get_wrapper(Catch::Detail::priority_tag<1>{})) #define INTERNAL_CATCH_MAKE_TYPE_LIST(...) INTERNAL_CATCH_MAKE_TYPE_LIST2(INTERNAL_CATCH_REMOVE_PARENS(__VA_ARGS__)) #else -#define INTERNAL_CATCH_MAKE_TYPE_LIST2(...) INTERNAL_CATCH_EXPAND_VARGS(decltype(get_wrapper())) +#define INTERNAL_CATCH_MAKE_TYPE_LIST2(...) INTERNAL_CATCH_EXPAND_VARGS(decltype(get_wrapper(Catch::Detail::priority_tag<1>{}))) #define INTERNAL_CATCH_MAKE_TYPE_LIST(...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_MAKE_TYPE_LIST2(INTERNAL_CATCH_REMOVE_PARENS(__VA_ARGS__))) #endif @@ -6509,11 +6621,11 @@ static int catchInternalSectionHint = 0; #define INTERNAL_CATCH_TYPE_GEN\ template struct TypeList {};\ - template\ - constexpr auto get_wrapper() noexcept -> TypeList { return {}; }\ + template\ + constexpr auto get_wrapper(Catch::Detail::priority_tag<1>) noexcept -> TypeList { return {}; }\ template class...> struct TemplateTypeList{};\ template class...Cs>\ - constexpr auto get_wrapper() noexcept -> TemplateTypeList { return {}; }\ + constexpr auto get_wrapper(Catch::Detail::priority_tag<1>) noexcept -> TemplateTypeList { return {}; }\ template\ struct append;\ template\ @@ -6543,10 +6655,10 @@ static int catchInternalSectionHint = 0; #define INTERNAL_CATCH_NTTP_1(signature, ...)\ template struct Nttp{};\ template\ - constexpr auto get_wrapper() noexcept -> Nttp<__VA_ARGS__> { return {}; } \ + constexpr auto get_wrapper(Catch::Detail::priority_tag<0>) noexcept -> Nttp<__VA_ARGS__> { return {}; } \ template class...> struct NttpTemplateTypeList{};\ template class...Cs>\ - constexpr auto get_wrapper() noexcept -> NttpTemplateTypeList { return {}; } \ + constexpr auto get_wrapper(Catch::Detail::priority_tag<0>) noexcept -> NttpTemplateTypeList { return {}; } \ \ template< template class Container, template class List, INTERNAL_CATCH_REMOVE_PARENS(signature)>\ struct rewrap, List<__VA_ARGS__>> { using type = TypeList>; };\ @@ -6571,13 +6683,14 @@ static int catchInternalSectionHint = 0; template\ static void TestName() -#define INTERNAL_CATCH_NTTP_REGISTER0(TestFunc, signature)\ - template\ - void reg_test(TypeList, Catch::NameAndTags nameAndTags)\ +#define INTERNAL_CATCH_TYPES_REGISTER(TestFunc)\ + template\ + void reg_test(TypeList, Catch::NameAndTags nameAndTags)\ {\ - Catch::AutoReg( Catch::makeTestInvoker(&TestFunc), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), nameAndTags);\ + Catch::AutoReg( Catch::makeTestInvoker(&TestFunc), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), nameAndTags);\ } +#define INTERNAL_CATCH_NTTP_REGISTER0(TestFunc, signature, ...) #define INTERNAL_CATCH_NTTP_REGISTER(TestFunc, signature, ...)\ template\ void reg_test(Nttp<__VA_ARGS__>, Catch::NameAndTags nameAndTags)\ @@ -6626,7 +6739,7 @@ static int catchInternalSectionHint = 0; #define INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD(TestName, ...) INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD1, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD0)(TestName, __VA_ARGS__) #define INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD(TestName, ClassName, ...) INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD1, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD0)(TestName, ClassName, __VA_ARGS__) #define INTERNAL_CATCH_NTTP_REG_METHOD_GEN(TestName, ...) INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD0, INTERNAL_CATCH_NTTP_REGISTER_METHOD0)(TestName, __VA_ARGS__) -#define INTERNAL_CATCH_NTTP_REG_GEN(TestFunc, ...) INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER0, INTERNAL_CATCH_NTTP_REGISTER0)(TestFunc, __VA_ARGS__) +#define INTERNAL_CATCH_NTTP_REG_GEN(TestFunc, ...) INTERNAL_CATCH_TYPES_REGISTER(TestFunc) INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER0, INTERNAL_CATCH_NTTP_REGISTER0)(TestFunc, __VA_ARGS__) #define INTERNAL_CATCH_DEFINE_SIG_TEST(TestName, ...) INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X,INTERNAL_CATCH_DEFINE_SIG_TEST_X,INTERNAL_CATCH_DEFINE_SIG_TEST1, INTERNAL_CATCH_DEFINE_SIG_TEST0)(TestName, __VA_ARGS__) #define INTERNAL_CATCH_DECLARE_SIG_TEST(TestName, ...) INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DECLARE_SIG_TEST_X,INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X,INTERNAL_CATCH_DECLARE_SIG_TEST_X,INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST1, INTERNAL_CATCH_DECLARE_SIG_TEST0)(TestName, __VA_ARGS__) #define INTERNAL_CATCH_REMOVE_PARENS_GEN(...) INTERNAL_CATCH_VA_NARGS_IMPL(__VA_ARGS__, INTERNAL_CATCH_REMOVE_PARENS_11_ARG,INTERNAL_CATCH_REMOVE_PARENS_10_ARG,INTERNAL_CATCH_REMOVE_PARENS_9_ARG,INTERNAL_CATCH_REMOVE_PARENS_8_ARG,INTERNAL_CATCH_REMOVE_PARENS_7_ARG,INTERNAL_CATCH_REMOVE_PARENS_6_ARG,INTERNAL_CATCH_REMOVE_PARENS_5_ARG,INTERNAL_CATCH_REMOVE_PARENS_4_ARG,INTERNAL_CATCH_REMOVE_PARENS_3_ARG,INTERNAL_CATCH_REMOVE_PARENS_2_ARG,INTERNAL_CATCH_REMOVE_PARENS_1_ARG)(__VA_ARGS__) @@ -6636,7 +6749,7 @@ static int catchInternalSectionHint = 0; #define INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD(TestName, ...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD1, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD0)(TestName, __VA_ARGS__)) #define INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD(TestName, ClassName, ...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD1, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD0)(TestName, ClassName, __VA_ARGS__)) #define INTERNAL_CATCH_NTTP_REG_METHOD_GEN(TestName, ...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD0, INTERNAL_CATCH_NTTP_REGISTER_METHOD0)(TestName, __VA_ARGS__)) -#define INTERNAL_CATCH_NTTP_REG_GEN(TestFunc, ...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER0, INTERNAL_CATCH_NTTP_REGISTER0)(TestFunc, __VA_ARGS__)) +#define INTERNAL_CATCH_NTTP_REG_GEN(TestFunc, ...) INTERNAL_CATCH_TYPES_REGISTER(TestFunc) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER0, INTERNAL_CATCH_NTTP_REGISTER0)(TestFunc, __VA_ARGS__)) #define INTERNAL_CATCH_DEFINE_SIG_TEST(TestName, ...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X,INTERNAL_CATCH_DEFINE_SIG_TEST_X,INTERNAL_CATCH_DEFINE_SIG_TEST1, INTERNAL_CATCH_DEFINE_SIG_TEST0)(TestName, __VA_ARGS__)) #define INTERNAL_CATCH_DECLARE_SIG_TEST(TestName, ...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DECLARE_SIG_TEST_X,INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X,INTERNAL_CATCH_DECLARE_SIG_TEST_X,INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST1, INTERNAL_CATCH_DECLARE_SIG_TEST0)(TestName, __VA_ARGS__)) #define INTERNAL_CATCH_REMOVE_PARENS_GEN(...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL(__VA_ARGS__, INTERNAL_CATCH_REMOVE_PARENS_11_ARG,INTERNAL_CATCH_REMOVE_PARENS_10_ARG,INTERNAL_CATCH_REMOVE_PARENS_9_ARG,INTERNAL_CATCH_REMOVE_PARENS_8_ARG,INTERNAL_CATCH_REMOVE_PARENS_7_ARG,INTERNAL_CATCH_REMOVE_PARENS_6_ARG,INTERNAL_CATCH_REMOVE_PARENS_5_ARG,INTERNAL_CATCH_REMOVE_PARENS_4_ARG,INTERNAL_CATCH_REMOVE_PARENS_3_ARG,INTERNAL_CATCH_REMOVE_PARENS_2_ARG,INTERNAL_CATCH_REMOVE_PARENS_1_ARG)(__VA_ARGS__)) @@ -6765,11 +6878,11 @@ static int catchInternalSectionHint = 0; constexpr char const* tmpl_types[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TmplTypes))};\ constexpr char const* types_list[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TypesList))};\ constexpr auto num_types = sizeof(types_list) / sizeof(types_list[0]);\ - (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestFuncName ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index / num_types]) + '<' + std::string(types_list[index % num_types]) + '>', Tags } ), index++)... };/* NOLINT */\ + (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestFuncName ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index / num_types]) + '<' + types_list[index % num_types] + '>', Tags } ), index++)... };/* NOLINT */\ } \ }; \ - static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){ \ - using TestInit = typename create()), TypeList>::type; \ + static const int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){ \ + using TestInit = typename create(Catch::Detail::priority_tag<1>{})), TypeList>::type; \ TestInit t; \ t.reg_tests(); \ return 0; \ @@ -6814,7 +6927,7 @@ static int catchInternalSectionHint = 0; (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestFunc ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ Name " - " INTERNAL_CATCH_STRINGIZE(TmplList) " - " + std::to_string(index), Tags } ), index++)... };/* NOLINT */\ } \ };\ - static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){ \ + static const int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){ \ using TestInit = typename convert::type; \ TestInit t; \ t.reg_tests(); \ @@ -6850,7 +6963,7 @@ static int catchInternalSectionHint = 0; (void)expander{(reg_test(Types{}, #ClassName, Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index]), Tags } ), index++)... };/* NOLINT */ \ }\ };\ - static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\ + static const int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\ TestNameClass();\ return 0;\ }();\ @@ -6897,11 +7010,11 @@ static int catchInternalSectionHint = 0; constexpr char const* tmpl_types[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TmplTypes))};\ constexpr char const* types_list[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TypesList))};\ constexpr auto num_types = sizeof(types_list) / sizeof(types_list[0]);\ - (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestName::test ), CATCH_INTERNAL_LINEINFO, #ClassName, Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index / num_types]) + '<' + std::string(types_list[index % num_types]) + '>', Tags } ), index++)... };/* NOLINT */ \ + (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestName::test ), CATCH_INTERNAL_LINEINFO, #ClassName, Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index / num_types]) + '<' + types_list[index % num_types] + '>', Tags } ), index++)... };/* NOLINT */ \ }\ };\ - static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\ - using TestInit = typename create()), TypeList>::type;\ + static const int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\ + using TestInit = typename create(Catch::Detail::priority_tag<1>{})), TypeList>::type;\ TestInit t;\ t.reg_tests();\ return 0;\ @@ -6949,7 +7062,7 @@ static int catchInternalSectionHint = 0; (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestName::test ), CATCH_INTERNAL_LINEINFO, #ClassName##_catch_sr, Catch::NameAndTags{ Name " - " INTERNAL_CATCH_STRINGIZE(TmplList) " - " + std::to_string(index), Tags } ), index++)... };/* NOLINT */ \ }\ };\ - static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\ + static const int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\ using TestInit = typename convert::type;\ TestInit t;\ t.reg_tests();\ @@ -7201,6 +7314,22 @@ namespace Catch { #endif // CATCH_TEST_CASE_INFO_HPP_INCLUDED +#ifndef CATCH_TEST_RUN_INFO_HPP_INCLUDED +#define CATCH_TEST_RUN_INFO_HPP_INCLUDED + + +namespace Catch { + + struct TestRunInfo { + constexpr TestRunInfo(StringRef _name) : name(_name) {} + StringRef name; + }; + +} // end namespace Catch + +#endif // CATCH_TEST_RUN_INFO_HPP_INCLUDED + + #ifndef CATCH_TRANSLATE_EXCEPTION_HPP_INCLUDED #define CATCH_TRANSLATE_EXCEPTION_HPP_INCLUDED @@ -7288,7 +7417,7 @@ namespace Catch { static std::string translatorName( signature ); \ CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ - namespace{ Catch::ExceptionTranslatorRegistrar INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionRegistrar )( &translatorName ); } \ + namespace{ const Catch::ExceptionTranslatorRegistrar INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionRegistrar )( &translatorName ); } \ CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \ static std::string translatorName( signature ) @@ -7349,8 +7478,8 @@ namespace Catch { #define CATCH_VERSION_MACROS_HPP_INCLUDED #define CATCH_VERSION_MAJOR 3 -#define CATCH_VERSION_MINOR 8 -#define CATCH_VERSION_PATCH 1 +#define CATCH_VERSION_MINOR 11 +#define CATCH_VERSION_PATCH 0 #endif // CATCH_VERSION_MACROS_HPP_INCLUDED @@ -7391,7 +7520,7 @@ namespace Catch { m_msg(msg) {} - const char* what() const noexcept override final; + const char* what() const noexcept final; }; } // end namespace Catch @@ -7765,8 +7894,9 @@ namespace Generators { class FilterGenerator final : public IGenerator { GeneratorWrapper m_generator; Predicate m_predicate; + static_assert(!std::is_reference::value, "This would most likely result in a dangling reference"); public: - template + template FilterGenerator(P&& pred, GeneratorWrapper&& generator): m_generator(CATCH_MOVE(generator)), m_predicate(CATCH_FORWARD(pred)) @@ -7798,7 +7928,7 @@ namespace Generators { template GeneratorWrapper filter(Predicate&& pred, GeneratorWrapper&& generator) { - return GeneratorWrapper(Catch::Detail::make_unique>(CATCH_FORWARD(pred), CATCH_MOVE(generator))); + return GeneratorWrapper(Catch::Detail::make_unique::type>>(CATCH_FORWARD(pred), CATCH_MOVE(generator))); } template @@ -8778,26 +8908,9 @@ auto from_range(Container const& cnt) { #define CATCH_INTERFACES_REPORTER_HPP_INCLUDED - -#ifndef CATCH_TEST_RUN_INFO_HPP_INCLUDED -#define CATCH_TEST_RUN_INFO_HPP_INCLUDED - - -namespace Catch { - - struct TestRunInfo { - constexpr TestRunInfo(StringRef _name) : name(_name) {} - StringRef name; - }; - -} // end namespace Catch - -#endif // CATCH_TEST_RUN_INFO_HPP_INCLUDED - #include #include #include -#include namespace Catch { @@ -8893,6 +9006,11 @@ namespace Catch { //! Catch2 should call `Reporter::assertionEnded` even for passing //! assertions bool shouldReportAllAssertions = false; + //! Catch2 should call `Reporter::assertionStarting` for all assertions + // Defaults to true for backwards compatibility, but none of our current + // reporters actually want this, and it enables a fast path in assertion + // handling. + bool shouldReportAllAssertionStarts = true; }; /** @@ -9415,6 +9533,17 @@ namespace Catch { bool isDebuggerActive(); } +#if !defined( CATCH_TRAP ) && defined( __clang__ ) && defined( __has_builtin ) +# if __has_builtin( __builtin_debugtrap ) +# define CATCH_TRAP() __builtin_debugtrap() +# endif +#endif + +#if !defined( CATCH_TRAP ) && defined( _MSC_VER ) +# define CATCH_TRAP() __debugbreak() +#endif + +#if !defined(CATCH_TRAP) // If we couldn't use compiler-specific impl from above, we get into platform-specific options #ifdef CATCH_PLATFORM_MAC #if defined(__i386__) || defined(__x86_64__) @@ -9439,7 +9568,7 @@ namespace Catch { #define CATCH_TRAP() __asm__(".inst 0xde01") #endif -#elif defined(CATCH_PLATFORM_LINUX) +#elif defined(CATCH_PLATFORM_LINUX) || defined(CATCH_PLATFORM_QNX) // If we can use inline assembler, do it because this allows us to break // directly at the location of the failing check instead of breaking inside // raise() called from it, i.e. one stack frame below. @@ -9450,15 +9579,15 @@ namespace Catch { #define CATCH_TRAP() raise(SIGTRAP) #endif -#elif defined(_MSC_VER) - #define CATCH_TRAP() __debugbreak() #elif defined(__MINGW32__) extern "C" __declspec(dllimport) void __stdcall DebugBreak(); #define CATCH_TRAP() DebugBreak() #endif +#endif // ^^ CATCH_TRAP is not defined yet, so we define it -#ifndef CATCH_BREAK_INTO_DEBUGGER - #ifdef CATCH_TRAP + +#if !defined(CATCH_BREAK_INTO_DEBUGGER) + #if defined(CATCH_TRAP) #define CATCH_BREAK_INTO_DEBUGGER() []{ if( Catch::isDebuggerActive() ) { CATCH_TRAP(); } }() #else #define CATCH_BREAK_INTO_DEBUGGER() []{}() @@ -9472,7 +9601,7 @@ namespace Catch { #define CATCH_ENFORCE_HPP_INCLUDED -#include +#include // for `std::exception` in no-exception configuration namespace Catch { #if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) @@ -9568,7 +9697,6 @@ namespace Catch { #define CATCH_EXCEPTION_TRANSLATOR_REGISTRY_HPP_INCLUDED -#include #include namespace Catch { @@ -9768,8 +9896,8 @@ namespace Detail { #ifndef CATCH_IS_PERMUTATION_HPP_INCLUDED #define CATCH_IS_PERMUTATION_HPP_INCLUDED -#include #include +#include namespace Catch { namespace Detail { @@ -9906,8 +10034,6 @@ namespace Catch { #include -#include -#include #include namespace Catch { @@ -10491,6 +10617,48 @@ using TestCaseTracking::SectionTracker; #endif // CATCH_TEST_CASE_TRACKER_HPP_INCLUDED + +#ifndef CATCH_THREAD_SUPPORT_HPP_INCLUDED +#define CATCH_THREAD_SUPPORT_HPP_INCLUDED + + +#if defined( CATCH_CONFIG_EXPERIMENTAL_THREAD_SAFE_ASSERTIONS ) +# include +# include +#endif + + +namespace Catch { + namespace Detail { +#if defined( CATCH_CONFIG_EXPERIMENTAL_THREAD_SAFE_ASSERTIONS ) + using Mutex = std::mutex; + using LockGuard = std::lock_guard; + struct AtomicCounts { + std::atomic passed = 0; + std::atomic failed = 0; + std::atomic failedButOk = 0; + std::atomic skipped = 0; + }; +#else // ^^ Use actual mutex, lock and atomics + // vv Dummy implementations for single-thread performance + + struct Mutex { + void lock() {} + void unlock() {} + }; + + struct LockGuard { + LockGuard( Mutex ) {} + }; + + using AtomicCounts = Counts; +#endif + + } // namespace Detail +} // namespace Catch + +#endif // CATCH_THREAD_SUPPORT_HPP_INCLUDED + #include namespace Catch { @@ -10563,11 +10731,6 @@ namespace Catch { void benchmarkEnded( BenchmarkStats<> const& stats ) override; void benchmarkFailed( StringRef error ) override; - void pushScopedMessage( MessageInfo const& message ) override; - void popScopedMessage( MessageInfo const& message ) override; - - void emplaceUnscopedMessage( MessageBuilder&& builder ) override; - std::string getCurrentTestName() const override; const AssertionResult* getLastResult() const override; @@ -10578,18 +10741,18 @@ namespace Catch { bool lastAssertionPassed() override; - void assertionPassed() override; - public: // !TBD We need to do this another way! bool aborting() const; private: + void assertionPassedFastPath( SourceLineInfo lineInfo ); + // Update the non-thread-safe m_totals from the atomic assertion counts. + void updateTotalsFromAtomics(); void runCurrentTest(); void invokeActiveTestCase(); - void resetAssertionInfo(); bool testForMissingAssertions( Counts& assertions ); void assertionEnded( AssertionResult&& result ); @@ -10599,31 +10762,39 @@ namespace Catch { ITransientExpression const *expr, bool negated ); - void populateReaction( AssertionReaction& reaction ); + void populateReaction( AssertionReaction& reaction, bool has_normal_disposition ); + + // Creates dummy info for unexpected exceptions/fatal errors, + // where we do not have the access to one, but we still need + // to send one to the reporters. + AssertionInfo makeDummyAssertionInfo(); private: void handleUnfinishedSections(); - + mutable Detail::Mutex m_assertionMutex; TestRunInfo m_runInfo; TestCaseHandle const* m_activeTestCase = nullptr; ITracker* m_testCaseTracker = nullptr; Optional m_lastResult; - IConfig const* m_config; Totals m_totals; + Detail::AtomicCounts m_atomicAssertionCount; IEventListenerPtr m_reporter; - std::vector m_messages; - std::vector m_messageScopes; /* Keeps owners of so-called unscoped messages. */ - AssertionInfo m_lastAssertionInfo; std::vector m_unfinishedSections; std::vector m_activeSections; TrackerContext m_trackerContext; Detail::unique_ptr m_outputRedirect; FatalConditionHandler m_fatalConditionhandler; - bool m_lastAssertionPassed = false; + // Caches m_config->abortAfter() to avoid vptr calls/allow inlining + size_t m_abortAfterXFailedAssertions; bool m_shouldReportUnexpected = true; + // Caches whether `assertionStarting` events should be sent to the reporter. + bool m_reportAssertionStarting; + // Caches whether `assertionEnded` events for successful assertions should be sent to the reporter bool m_includeSuccessfulResults; + // Caches m_config->shouldDebugBreak() to avoid vptr calls/allow inlining + bool m_shouldDebugBreak; }; void seedRng(IConfig const& config); @@ -10637,7 +10808,6 @@ namespace Catch { #define CATCH_SHARDING_HPP_INCLUDED #include -#include #include namespace Catch { @@ -11860,19 +12030,19 @@ namespace Matchers { } template - using is_generic_matcher = std::is_base_of< + static constexpr bool is_generic_matcher_v = std::is_base_of< Catch::Matchers::MatcherGenericBase, std::remove_cv_t> - >; + >::value; template - using are_generic_matchers = Catch::Detail::conjunction...>; + static constexpr bool are_generic_matchers_v = Catch::Detail::conjunction>...>::value; template - using is_matcher = std::is_base_of< + static constexpr bool is_matcher_v = std::is_base_of< Catch::Matchers::MatcherUntypedBase, std::remove_cv_t> - >; + >::value; template @@ -11945,7 +12115,7 @@ namespace Matchers { //! Avoids type nesting for `GenericAllOf && some matcher` case template - friend std::enable_if_t::value, + friend std::enable_if_t, MatchAllOfGeneric> operator && ( MatchAllOfGeneric&& lhs, MatcherRHS const& rhs) { @@ -11954,7 +12124,7 @@ namespace Matchers { //! Avoids type nesting for `some matcher && GenericAllOf` case template - friend std::enable_if_t::value, + friend std::enable_if_t, MatchAllOfGeneric> operator && ( MatcherLHS const& lhs, MatchAllOfGeneric&& rhs) { @@ -11999,7 +12169,7 @@ namespace Matchers { //! Avoids type nesting for `GenericAnyOf || some matcher` case template - friend std::enable_if_t::value, + friend std::enable_if_t, MatchAnyOfGeneric> operator || ( MatchAnyOfGeneric&& lhs, MatcherRHS const& rhs) { @@ -12008,7 +12178,7 @@ namespace Matchers { //! Avoids type nesting for `some matcher || GenericAnyOf` case template - friend std::enable_if_t::value, + friend std::enable_if_t, MatchAnyOfGeneric> operator || ( MatcherLHS const& lhs, MatchAnyOfGeneric&& rhs) { @@ -12048,20 +12218,20 @@ namespace Matchers { // compose only generic matchers template - std::enable_if_t::value, Detail::MatchAllOfGeneric> + std::enable_if_t, Detail::MatchAllOfGeneric> operator && (MatcherLHS const& lhs, MatcherRHS const& rhs) { return { lhs, rhs }; } template - std::enable_if_t::value, Detail::MatchAnyOfGeneric> + std::enable_if_t, Detail::MatchAnyOfGeneric> operator || (MatcherLHS const& lhs, MatcherRHS const& rhs) { return { lhs, rhs }; } //! Wrap provided generic matcher in generic negator template - std::enable_if_t::value, Detail::MatchNotOfGeneric> + std::enable_if_t, Detail::MatchNotOfGeneric> operator ! (MatcherT const& matcher) { return Detail::MatchNotOfGeneric{matcher}; } @@ -12069,25 +12239,25 @@ namespace Matchers { // compose mixed generic and non-generic matchers template - std::enable_if_t::value, Detail::MatchAllOfGeneric>> + std::enable_if_t, Detail::MatchAllOfGeneric>> operator && (MatcherLHS const& lhs, MatcherBase const& rhs) { return { lhs, rhs }; } template - std::enable_if_t::value, Detail::MatchAllOfGeneric, MatcherRHS>> + std::enable_if_t, Detail::MatchAllOfGeneric, MatcherRHS>> operator && (MatcherBase const& lhs, MatcherRHS const& rhs) { return { lhs, rhs }; } template - std::enable_if_t::value, Detail::MatchAnyOfGeneric>> + std::enable_if_t, Detail::MatchAnyOfGeneric>> operator || (MatcherLHS const& lhs, MatcherBase const& rhs) { return { lhs, rhs }; } template - std::enable_if_t::value, Detail::MatchAnyOfGeneric, MatcherRHS>> + std::enable_if_t, Detail::MatchAnyOfGeneric, MatcherRHS>> operator || (MatcherBase const& lhs, MatcherRHS const& rhs) { return { lhs, rhs }; } @@ -12164,7 +12334,7 @@ namespace Catch { //! Creates a matcher that accepts ranges/containers with specific size HasSizeMatcher SizeIs(std::size_t sz); template - std::enable_if_t::value, + std::enable_if_t, SizeMatchesMatcher> SizeIs(Matcher&& m) { return SizeMatchesMatcher{CATCH_FORWARD(m)}; } @@ -12179,8 +12349,8 @@ namespace Catch { #define CATCH_MATCHERS_CONTAINS_HPP_INCLUDED -#include #include +#include namespace Catch { namespace Matchers { @@ -12242,14 +12412,14 @@ namespace Catch { * Uses `std::equal_to` to do the comparison */ template - std::enable_if_t::value, + std::enable_if_t, ContainsElementMatcher>> Contains(T&& elem) { return { CATCH_FORWARD(elem), std::equal_to<>{} }; } //! Creates a matcher that checks whether a range contains element matching a matcher template - std::enable_if_t::value, + std::enable_if_t, ContainsMatcherMatcher> Contains(Matcher&& matcher) { return { CATCH_FORWARD(matcher) }; } @@ -12626,8 +12796,7 @@ namespace Catch { #define CATCH_MATCHERS_RANGE_EQUALS_HPP_INCLUDED -#include -#include +#include namespace Catch { namespace Matchers { @@ -13211,9 +13380,11 @@ namespace Catch { public: // GCC5 compat: we cannot use inherited constructor, because it // doesn't implement backport of P0136 - AutomakeReporter(ReporterConfig&& _config): - StreamingReporterBase(CATCH_MOVE(_config)) - {} + AutomakeReporter( ReporterConfig&& _config ): + StreamingReporterBase( CATCH_MOVE( _config ) ) { + m_preferences.shouldReportAllAssertionStarts = false; + } + ~AutomakeReporter() override; static std::string getDescription() { @@ -13240,7 +13411,10 @@ namespace Catch { class CompactReporter final : public StreamingReporterBase { public: - using StreamingReporterBase::StreamingReporterBase; + CompactReporter( ReporterConfig&& _config ): + StreamingReporterBase( CATCH_MOVE( _config ) ) { + m_preferences.shouldReportAllAssertionStarts = false; + } ~CompactReporter() override; @@ -13282,8 +13456,6 @@ namespace Catch { void noMatchingTestCases( StringRef unmatchedSpec ) override; void reportInvalidTestSpec( StringRef arg ) override; - void assertionStarting(AssertionInfo const&) override; - void assertionEnded(AssertionStats const& _assertionStats) override; void sectionStarting(SectionInfo const& _sectionInfo) override; @@ -13637,7 +13809,6 @@ namespace Catch { void sectionStarting( SectionInfo const& sectionInfo ) override; void sectionEnded( SectionStats const& sectionStats ) override; - void assertionStarting( AssertionInfo const& assertionInfo ) override; void assertionEnded( AssertionStats const& assertionStats ) override; //void testRunEndedCumulative() override; @@ -13764,6 +13935,11 @@ namespace Catch { void updatePreferences(IEventListener const& reporterish); public: + MultiReporter( IConfig const* config ): + IEventListener( config ) { + m_preferences.shouldReportAllAssertionStarts = false; + } + using IEventListener::IEventListener; void addListener( IEventListenerPtr&& listener ); @@ -13899,22 +14075,24 @@ namespace Catch { #if !defined(CATCH_CONFIG_DISABLE) -# define CATCH_REGISTER_REPORTER( name, reporterType ) \ - CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ - CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ - namespace { \ - Catch::ReporterRegistrar INTERNAL_CATCH_UNIQUE_NAME( \ - catch_internal_RegistrarFor )( name ); \ - } \ +# define CATCH_REGISTER_REPORTER( name, reporterType ) \ + CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ + CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ + namespace { \ + const Catch::ReporterRegistrar \ + INTERNAL_CATCH_UNIQUE_NAME( catch_internal_RegistrarFor )( \ + name ); \ + } \ CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION -# define CATCH_REGISTER_LISTENER( listenerType ) \ - CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ - CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ - namespace { \ - Catch::ListenerRegistrar INTERNAL_CATCH_UNIQUE_NAME( \ - catch_internal_RegistrarFor )( #listenerType##_catch_sr ); \ - } \ +# define CATCH_REGISTER_LISTENER( listenerType ) \ + CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ + CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ + namespace { \ + const Catch::ListenerRegistrar \ + INTERNAL_CATCH_UNIQUE_NAME( catch_internal_RegistrarFor )( \ + #listenerType##_catch_sr ); \ + } \ CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION #else // CATCH_CONFIG_DISABLE @@ -13941,6 +14119,7 @@ namespace Catch { , xml(m_stream) { m_preferences.shouldRedirectStdOut = true; m_preferences.shouldReportAllAssertions = false; + m_preferences.shouldReportAllAssertionStarts = false; m_shouldStoreSuccesfulAssertions = false; } @@ -13989,6 +14168,7 @@ namespace Catch { TAPReporter( ReporterConfig&& config ): StreamingReporterBase( CATCH_MOVE(config) ) { m_preferences.shouldReportAllAssertions = true; + m_preferences.shouldReportAllAssertionStarts = false; } static std::string getDescription() { @@ -14032,6 +14212,7 @@ namespace Catch { : StreamingReporterBase( CATCH_MOVE(_config) ) { m_preferences.shouldRedirectStdOut = true; + m_preferences.shouldReportAllAssertionStarts = false; } ~TeamCityReporter() override; @@ -14099,8 +14280,6 @@ namespace Catch { void sectionStarting(SectionInfo const& sectionInfo) override; - void assertionStarting(AssertionInfo const&) override; - void assertionEnded(AssertionStats const& assertionStats) override; void sectionEnded(SectionStats const& sectionStats) override; diff --git a/catch2/fuzzing/CMakeLists.txt b/catch2/fuzzing/CMakeLists.txt index daba61d..8370fe3 100644 --- a/catch2/fuzzing/CMakeLists.txt +++ b/catch2/fuzzing/CMakeLists.txt @@ -15,6 +15,6 @@ target_compile_features(fuzzhelper PUBLIC cxx_std_17) target_link_options(fuzzhelper PUBLIC "-fsanitize=fuzzer") foreach(fuzzer TestSpecParser XmlWriter textflow) -add_executable(fuzz_${fuzzer} fuzz_${fuzzer}.cpp) -target_link_libraries(fuzz_${fuzzer} PRIVATE fuzzhelper) + add_executable(fuzz_${fuzzer} fuzz_${fuzzer}.cpp) + target_link_libraries(fuzz_${fuzzer} PRIVATE fuzzhelper) endforeach() diff --git a/catch2/fuzzing/NullOStream.h b/catch2/fuzzing/NullOStream.h index abbec09..390ac86 100644 --- a/catch2/fuzzing/NullOStream.h +++ b/catch2/fuzzing/NullOStream.h @@ -16,7 +16,7 @@ class NullStreambuf : public std::streambuf { char dummyBuffer[64]; protected: - virtual int overflow(int c) override final; + virtual int overflow(int c) final; }; class NullOStream final : private NullStreambuf, public std::ostream { diff --git a/catch2/meson.build b/catch2/meson.build index 6346d44..16b3879 100644 --- a/catch2/meson.build +++ b/catch2/meson.build @@ -8,7 +8,7 @@ project( 'catch2', 'cpp', - version: '3.8.1', # CML version placeholder, don't delete + version: '3.11.0', # CML version placeholder, don't delete license: 'BSL-1.0', meson_version: '>=0.54.1', ) diff --git a/catch2/src/CMakeLists.txt b/catch2/src/CMakeLists.txt index c40de04..1e3af14 100644 --- a/catch2/src/CMakeLists.txt +++ b/catch2/src/CMakeLists.txt @@ -40,7 +40,6 @@ set(BENCHMARK_SOURCES ) set(BENCHMARK_FILES ${BENCHMARK_HEADERS} ${BENCHMARK_SOURCES}) - set(IMPL_HEADERS "${PROJECT_BINARY_DIR}/generated-includes/catch2/catch_user_config.hpp" ${SOURCES_DIR}/catch_user_config.hpp.in @@ -59,6 +58,7 @@ set(IMPL_HEADERS ${SOURCES_DIR}/catch_template_test_macros.hpp ${SOURCES_DIR}/catch_test_case_info.hpp ${SOURCES_DIR}/catch_test_macros.hpp + ${SOURCES_DIR}/catch_test_run_info.hpp ${SOURCES_DIR}/catch_test_spec.hpp ${SOURCES_DIR}/catch_timer.hpp ${SOURCES_DIR}/catch_tostring.hpp @@ -85,6 +85,7 @@ set(IMPL_HEADERS ${SOURCES_DIR}/internal/catch_debug_console.hpp ${SOURCES_DIR}/internal/catch_debugger.hpp ${SOURCES_DIR}/internal/catch_decomposer.hpp + ${SOURCES_DIR}/internal/catch_deprecation_macro.hpp ${SOURCES_DIR}/internal/catch_enforce.hpp ${SOURCES_DIR}/internal/catch_enum_values_registry.hpp ${SOURCES_DIR}/internal/catch_errno_guard.hpp @@ -136,15 +137,16 @@ set(IMPL_HEADERS ${SOURCES_DIR}/internal/catch_test_failure_exception.hpp ${SOURCES_DIR}/internal/catch_test_macro_impl.hpp ${SOURCES_DIR}/internal/catch_test_registry.hpp - ${SOURCES_DIR}/internal/catch_test_run_info.hpp ${SOURCES_DIR}/internal/catch_test_spec_parser.hpp ${SOURCES_DIR}/internal/catch_textflow.hpp + ${SOURCES_DIR}/internal/catch_thread_support.hpp ${SOURCES_DIR}/internal/catch_to_string.hpp ${SOURCES_DIR}/internal/catch_uncaught_exceptions.hpp ${SOURCES_DIR}/internal/catch_uniform_floating_point_distribution.hpp ${SOURCES_DIR}/internal/catch_uniform_integer_distribution.hpp ${SOURCES_DIR}/internal/catch_unique_name.hpp ${SOURCES_DIR}/internal/catch_unique_ptr.hpp + ${SOURCES_DIR}/internal/catch_unreachable.hpp ${SOURCES_DIR}/internal/catch_void_type.hpp ${SOURCES_DIR}/internal/catch_wildcard_pattern.hpp ${SOURCES_DIR}/internal/catch_windows_h_proxy.hpp @@ -348,25 +350,23 @@ source_group("generated headers" ) add_library(Catch2 ${ALL_FILES}) -if (CATCH_ENABLE_REPRODUCIBLE_BUILD) - add_build_reproducibility_settings(Catch2) +if(CATCH_ENABLE_REPRODUCIBLE_BUILD) + add_build_reproducibility_settings(Catch2) endif() add_library(Catch2::Catch2 ALIAS Catch2) -if (ANDROID) - target_link_libraries(Catch2 PRIVATE log) +if(ANDROID) + target_link_libraries(Catch2 PRIVATE log) endif() set_target_properties(Catch2 PROPERTIES - DEBUG_POSTFIX "d" - VERSION ${PROJECT_VERSION} - SOVERSION ${PROJECT_VERSION}) + DEBUG_POSTFIX "d" + VERSION ${PROJECT_VERSION} + SOVERSION ${PROJECT_VERSION} +) # require C++14 -target_compile_features(Catch2 - PUBLIC - cxx_std_14 -) +target_compile_features(Catch2 PUBLIC cxx_std_14) configure_file( "${SOURCES_DIR}/catch_user_config.hpp.in" @@ -382,105 +382,97 @@ target_include_directories(Catch2 add_library(Catch2WithMain - ${SOURCES_DIR}/internal/catch_main.cpp + ${SOURCES_DIR}/internal/catch_main.cpp ) -if (CATCH_ENABLE_REPRODUCIBLE_BUILD) - add_build_reproducibility_settings(Catch2WithMain) +if(CATCH_ENABLE_REPRODUCIBLE_BUILD) + add_build_reproducibility_settings(Catch2WithMain) endif() add_library(Catch2::Catch2WithMain ALIAS Catch2WithMain) target_link_libraries(Catch2WithMain PUBLIC Catch2) set_target_properties(Catch2WithMain PROPERTIES OUTPUT_NAME "Catch2Main" - VERSION ${PROJECT_VERSION} - SOVERSION ${PROJECT_VERSION} + VERSION ${PROJECT_VERSION} + SOVERSION ${PROJECT_VERSION} ) set_target_properties(Catch2WithMain PROPERTIES DEBUG_POSTFIX "d") -if (NOT_SUBPROJECT) - # create and install an export set for catch target as Catch2::Catch - install( - TARGETS - Catch2 - Catch2WithMain - EXPORT - Catch2Targets - LIBRARY DESTINATION - ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION - ${CMAKE_INSTALL_LIBDIR} - RUNTIME DESTINATION - ${CMAKE_INSTALL_BINDIR} - ) - +if(NOT_SUBPROJECT) + # create and install an export set for catch target as Catch2::Catch + install( + TARGETS + Catch2 + Catch2WithMain + EXPORT + Catch2Targets + LIBRARY DESTINATION + ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION + ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION + ${CMAKE_INSTALL_BINDIR} + ) - install( - EXPORT - Catch2Targets - NAMESPACE - Catch2:: - DESTINATION - ${CATCH_CMAKE_CONFIG_DESTINATION} - ) - # Install the headers - install( - DIRECTORY - "${SOURCES_DIR}" - "${PROJECT_BINARY_DIR}/generated-includes/catch2" # Also install the generated header - DESTINATION - "${CMAKE_INSTALL_INCLUDEDIR}" - FILES_MATCHING - PATTERN "*.hpp" - ) + install( + EXPORT + Catch2Targets + NAMESPACE + Catch2:: + DESTINATION + ${CATCH_CMAKE_CONFIG_DESTINATION} + ) + # Install the headers + install( + DIRECTORY + "${SOURCES_DIR}" + "${PROJECT_BINARY_DIR}/generated-includes/catch2" # Also install the generated header + DESTINATION + "${CMAKE_INSTALL_INCLUDEDIR}" + FILES_MATCHING + PATTERN "*.hpp" + ) endif() # Some tests require a full recompilation of Catch2 lib with different # compilation flags. They can link against this target to recompile all # the sources into the binary. -if (CATCH_BUILD_EXAMPLES OR CATCH_BUILD_EXTRA_TESTS) - add_library(Catch2_buildall_interface INTERFACE) - target_sources(Catch2_buildall_interface INTERFACE - ${ALL_FILES} - # Also include main entry point - ${SOURCES_DIR}/internal/catch_main.cpp - ) - target_include_directories(Catch2_buildall_interface - INTERFACE - $ - $ - $ - ) - target_compile_definitions(Catch2_buildall_interface - INTERFACE - CATCH_CONFIG_STATIC - ) - target_compile_features(Catch2_buildall_interface - INTERFACE - cxx_std_14 - ) +if(CATCH_BUILD_EXAMPLES OR CATCH_BUILD_EXTRA_TESTS) + add_library(Catch2_buildall_interface INTERFACE) + target_sources(Catch2_buildall_interface INTERFACE + ${ALL_FILES} + # Also include main entry point + ${SOURCES_DIR}/internal/catch_main.cpp + ) + target_include_directories(Catch2_buildall_interface + INTERFACE + $ + $ + $ + ) + target_compile_definitions(Catch2_buildall_interface INTERFACE CATCH_CONFIG_STATIC) + target_compile_features(Catch2_buildall_interface INTERFACE cxx_std_14) endif() -list(APPEND CATCH_WARNING_TARGETS Catch2 Catch2WithMain) -set(CATCH_WARNING_TARGETS ${CATCH_WARNING_TARGETS} PARENT_SCOPE) - +list(APPEND CATCH_IMPL_TARGETS Catch2 Catch2WithMain) +set(CATCH_IMPL_TARGETS ${CATCH_IMPL_TARGETS} PARENT_SCOPE) # We still do not support building dynamic library with hidden visibility # so we want to check & warn users if they do this. However, we won't abort # the configuration step so that we don't have to also provide an override. -if (BUILD_SHARED_LIBS) +if(BUILD_SHARED_LIBS) + set_target_properties(Catch2 Catch2WithMain + PROPERTIES + WINDOWS_EXPORT_ALL_SYMBOLS ON + ) + + get_target_property(_VisPreset Catch2 CXX_VISIBILITY_PRESET) + if(NOT MSVC AND _VisPreset STREQUAL "hidden") set_target_properties(Catch2 Catch2WithMain PROPERTIES - WINDOWS_EXPORT_ALL_SYMBOLS ON + CXX_VISIBILITY_PRESET "default" + VISIBILITY_INLINES_HIDDEN OFF ) - - get_target_property(_VisPreset Catch2 CXX_VISIBILITY_PRESET) - if (NOT MSVC AND _VisPreset STREQUAL "hidden") - set_target_properties(Catch2 Catch2WithMain - PROPERTIES - CXX_VISIBILITY_PRESET "default" - VISIBILITY_INLINES_HIDDEN OFF - ) - message(WARNING "Setting Catch2's visibility to default." - " Hidden visibility is not supported.") - endif() + message(WARNING "Setting Catch2's visibility to default." + " Hidden visibility is not supported.") + endif() endif() diff --git a/catch2/src/catch2/benchmark/catch_benchmark.hpp b/catch2/src/catch2/benchmark/catch_benchmark.hpp index d0f88cf..ce68aee 100644 --- a/catch2/src/catch2/benchmark/catch_benchmark.hpp +++ b/catch2/src/catch2/benchmark/catch_benchmark.hpp @@ -86,9 +86,7 @@ namespace Catch { auto analysis = Detail::analyse(*cfg, samples.data(), samples.data() + samples.size()); BenchmarkStats<> stats{ CATCH_MOVE(info), CATCH_MOVE(analysis.samples), analysis.mean, analysis.standard_deviation, analysis.outliers, analysis.outlier_variance }; getResultCapture().benchmarkEnded(stats); - } CATCH_CATCH_ANON (TestFailureException const&) { - getResultCapture().benchmarkFailed("Benchmark failed due to failed assertion"_sr); - } CATCH_CATCH_ALL{ + } CATCH_CATCH_ALL { getResultCapture().benchmarkFailed(translateActiveException()); // We let the exception go further up so that the // test case is marked as failed. @@ -97,7 +95,7 @@ namespace Catch { } // sets lambda to be used in fun *and* executes benchmark! - template ::value, int> = 0> + template , int> = 0> Benchmark & operator=(Fun func) { auto const* cfg = getCurrentContext().getConfig(); if (!cfg->skipBenchmarks()) { diff --git a/catch2/src/catch2/benchmark/detail/catch_benchmark_function.hpp b/catch2/src/catch2/benchmark/detail/catch_benchmark_function.hpp index a03cb11..90b07b7 100644 --- a/catch2/src/catch2/benchmark/detail/catch_benchmark_function.hpp +++ b/catch2/src/catch2/benchmark/detail/catch_benchmark_function.hpp @@ -21,8 +21,7 @@ namespace Catch { namespace Benchmark { namespace Detail { template - struct is_related - : std::is_same, std::decay_t> {}; + static constexpr bool is_related_v = std::is_same, std::decay_t>::value; /// We need to reinvent std::function because every piece of code that might add overhead /// in a measurement context needs to have consistent performance characteristics so that we @@ -63,7 +62,7 @@ namespace Catch { BenchmarkFunction(); template ::value, int> = 0> + std::enable_if_t, int> = 0> BenchmarkFunction(Fun&& fun) : f(new model>(CATCH_FORWARD(fun))) {} diff --git a/catch2/src/catch2/benchmark/detail/catch_estimate_clock.hpp b/catch2/src/catch2/benchmark/detail/catch_estimate_clock.hpp index 6da24ce..576fdb6 100644 --- a/catch2/src/catch2/benchmark/detail/catch_estimate_clock.hpp +++ b/catch2/src/catch2/benchmark/detail/catch_estimate_clock.hpp @@ -15,7 +15,6 @@ #include #include #include -#include #include #include diff --git a/catch2/src/catch2/benchmark/detail/catch_timing.hpp b/catch2/src/catch2/benchmark/detail/catch_timing.hpp index da56719..7dfe822 100644 --- a/catch2/src/catch2/benchmark/detail/catch_timing.hpp +++ b/catch2/src/catch2/benchmark/detail/catch_timing.hpp @@ -13,8 +13,6 @@ #include #include -#include - namespace Catch { namespace Benchmark { template diff --git a/catch2/src/catch2/catch_all.hpp b/catch2/src/catch2/catch_all.hpp index 5715995..2417d85 100644 --- a/catch2/src/catch2/catch_all.hpp +++ b/catch2/src/catch2/catch_all.hpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -65,6 +66,7 @@ #include #include #include +#include #include #include #include @@ -117,15 +119,16 @@ #include #include #include -#include #include #include +#include #include #include #include #include #include #include +#include #include #include #include diff --git a/catch2/src/catch2/catch_config.cpp b/catch2/src/catch2/catch_config.cpp index 352c1f4..fef03d7 100644 --- a/catch2/src/catch2/catch_config.cpp +++ b/catch2/src/catch2/catch_config.cpp @@ -119,6 +119,8 @@ namespace Catch { m_data.reporterSpecifications.push_back( std::move( *parsed ) ); } + // Reading bazel env vars can change some parts of the config data, + // so we have to process the bazel env before acting on the config. if ( enableBazelEnvSupport() ) { readBazelEnvVars(); } @@ -183,6 +185,8 @@ namespace Catch { bool Config::showHelp() const { return m_data.showHelp; } + std::string const& Config::getExitGuardFilePath() const { return m_data.prematureExitGuardFilePath; } + // IConfig interface bool Config::allowThrows() const { return !m_data.noThrow; } StringRef Config::name() const { return m_data.name.empty() ? m_data.processName : m_data.name; } @@ -244,6 +248,26 @@ namespace Catch { m_data.shardCount = bazelShardOptions->shardCount; } } + + const auto bazelExitGuardFile = Detail::getEnv( "TEST_PREMATURE_EXIT_FILE" ); + if (bazelExitGuardFile) { + m_data.prematureExitGuardFilePath = bazelExitGuardFile; + } + + const auto bazelRandomSeed = Detail::getEnv( "TEST_RANDOM_SEED" ); + if ( bazelRandomSeed ) { + auto parsedSeed = parseUInt( bazelRandomSeed, 0 ); + if ( !parsedSeed ) { + // Currently we handle issues with parsing other Bazel Env + // options by warning and ignoring the issue. So we do the + // same for random seed option. + Catch::cerr() + << "Warning: could not parse 'TEST_RANDOM_SEED' ('" + << bazelRandomSeed << "') as proper seed.\n"; + } else { + m_data.rngSeed = *parsedSeed; + } + } } } // end namespace Catch diff --git a/catch2/src/catch2/catch_config.hpp b/catch2/src/catch2/catch_config.hpp index 17e983e..cdf286a 100644 --- a/catch2/src/catch2/catch_config.hpp +++ b/catch2/src/catch2/catch_config.hpp @@ -76,7 +76,7 @@ namespace Catch { WarnAbout::What warnings = WarnAbout::Nothing; ShowDurations showDurations = ShowDurations::DefaultForReporter; double minDuration = -1; - TestRunOrder runOrder = TestRunOrder::Declared; + TestRunOrder runOrder = TestRunOrder::Randomized; ColourMode defaultColourMode = ColourMode::PlatformDefault; WaitForKeypress::When waitForKeypress = WaitForKeypress::Never; @@ -87,6 +87,8 @@ namespace Catch { std::vector testsOrTags; std::vector sectionsToRun; + + std::string prematureExitGuardFilePath; }; @@ -114,6 +116,8 @@ namespace Catch { bool showHelp() const; + std::string const& getExitGuardFilePath() const; + // IConfig interface bool allowThrows() const override; StringRef name() const override; diff --git a/catch2/src/catch2/catch_message.cpp b/catch2/src/catch2/catch_message.cpp index 7b09ab8..dc7d567 100644 --- a/catch2/src/catch2/catch_message.cpp +++ b/catch2/src/catch2/catch_message.cpp @@ -7,7 +7,6 @@ // SPDX-License-Identifier: BSL-1.0 #include #include -#include #include #include @@ -20,28 +19,26 @@ namespace Catch { ScopedMessage::ScopedMessage( MessageBuilder&& builder ): - m_info( CATCH_MOVE(builder.m_info) ) { - m_info.message = builder.m_stream.str(); - getResultCapture().pushScopedMessage( m_info ); + m_messageId( builder.m_info.sequence ) { + MessageInfo info( CATCH_MOVE( builder.m_info ) ); + info.message = builder.m_stream.str(); + IResultCapture::pushScopedMessage( CATCH_MOVE( info ) ); } ScopedMessage::ScopedMessage( ScopedMessage&& old ) noexcept: - m_info( CATCH_MOVE( old.m_info ) ) { + m_messageId( old.m_messageId ) { old.m_moved = true; } ScopedMessage::~ScopedMessage() { - if ( !uncaught_exceptions() && !m_moved ){ - getResultCapture().popScopedMessage(m_info); - } + if ( !m_moved ) { IResultCapture::popScopedMessage( m_messageId ); } } Capturer::Capturer( StringRef macroName, SourceLineInfo const& lineInfo, ResultWas::OfType resultType, - StringRef names ): - m_resultCapture( getResultCapture() ) { + StringRef names ) { auto trimmed = [&] (size_t start, size_t end) { while (names[start] == ',' || isspace(static_cast(names[start]))) { ++start; @@ -87,8 +84,8 @@ namespace Catch { case ',': if (start != pos && openings.empty()) { m_messages.emplace_back(macroName, lineInfo, resultType); - m_messages.back().message = static_cast(trimmed(start, pos)); - m_messages.back().message += " := "; + m_messages.back().message += trimmed(start, pos); + m_messages.back().message += " := "_sr; start = pos; } break; @@ -97,21 +94,20 @@ namespace Catch { } assert(openings.empty() && "Mismatched openings"); m_messages.emplace_back(macroName, lineInfo, resultType); - m_messages.back().message = static_cast(trimmed(start, names.size() - 1)); - m_messages.back().message += " := "; + m_messages.back().message += trimmed(start, names.size() - 1); + m_messages.back().message += " := "_sr; } Capturer::~Capturer() { - if ( !uncaught_exceptions() ){ - assert( m_captured == m_messages.size() ); - for( size_t i = 0; i < m_captured; ++i ) - m_resultCapture.popScopedMessage( m_messages[i] ); + assert( m_captured == m_messages.size() ); + for (auto const& message : m_messages) { + IResultCapture::popScopedMessage( message.sequence ); } } void Capturer::captureValue( size_t index, std::string const& value ) { assert( index < m_messages.size() ); m_messages[index].message += value; - m_resultCapture.pushScopedMessage( m_messages[index] ); + IResultCapture::pushScopedMessage( CATCH_MOVE( m_messages[index] ) ); m_captured++; } diff --git a/catch2/src/catch2/catch_message.hpp b/catch2/src/catch2/catch_message.hpp index 0a73834..44b0747 100644 --- a/catch2/src/catch2/catch_message.hpp +++ b/catch2/src/catch2/catch_message.hpp @@ -57,13 +57,12 @@ namespace Catch { ScopedMessage( ScopedMessage&& old ) noexcept; ~ScopedMessage(); - MessageInfo m_info; + unsigned int m_messageId; bool m_moved = false; }; class Capturer { std::vector m_messages; - IResultCapture& m_resultCapture; size_t m_captured = 0; public: Capturer( StringRef macroName, SourceLineInfo const& lineInfo, ResultWas::OfType resultType, StringRef names ); @@ -111,7 +110,7 @@ namespace Catch { /////////////////////////////////////////////////////////////////////////////// #define INTERNAL_CATCH_UNSCOPED_INFO( macroName, log ) \ - Catch::getResultCapture().emplaceUnscopedMessage( Catch::MessageBuilder( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log ) + Catch::IResultCapture::emplaceUnscopedMessage( Catch::MessageBuilder( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log ) #if defined(CATCH_CONFIG_PREFIX_MESSAGES) && !defined(CATCH_CONFIG_DISABLE) diff --git a/catch2/src/catch2/catch_registry_hub.cpp b/catch2/src/catch2/catch_registry_hub.cpp index 3a59467..925468f 100644 --- a/catch2/src/catch2/catch_registry_hub.cpp +++ b/catch2/src/catch2/catch_registry_hub.cpp @@ -96,7 +96,6 @@ namespace Catch { } void cleanUp() { cleanupSingletons(); - cleanUpContext(); } std::string translateActiveException() { return getRegistryHub().getExceptionTranslatorRegistry().translateActiveException(); diff --git a/catch2/src/catch2/catch_session.cpp b/catch2/src/catch2/catch_session.cpp index a4a410c..042b7f4 100644 --- a/catch2/src/catch2/catch_session.cpp +++ b/catch2/src/catch2/catch_session.cpp @@ -25,8 +25,9 @@ #include #include -#include #include +#include +#include #include #include #include @@ -34,14 +35,6 @@ namespace Catch { namespace { - static constexpr int TestFailureExitCode = 42; - static constexpr int UnspecifiedErrorExitCode = 1; - static constexpr int AllTestsSkippedExitCode = 4; - static constexpr int NoTestsRunExitCode = 2; - static constexpr int UnmatchedTestSpecExitCode = 3; - static constexpr int InvalidTestSpecExitCode = 5; - - IEventListenerPtr createReporter(std::string const& reporterName, ReporterConfig&& config) { auto reporter = Catch::getRegistryHub().getReporterRegistry().create(reporterName, CATCH_MOVE(config)); CATCH_ENFORCE(reporter, "No reporter registered with name: '" << reporterName << '\''); @@ -149,6 +142,50 @@ namespace Catch { } } + // Creates empty file at path. The path must be writable, we do not + // try to create directories in path because that's hard in C++14. + void setUpGuardFile( std::string const& guardFilePath ) { + if ( !guardFilePath.empty() ) { +#if defined( _MSC_VER ) + std::FILE* file = nullptr; + if ( fopen_s( &file, guardFilePath.c_str(), "w" ) ) { + char msgBuffer[100]; + const auto err = errno; + std::string errMsg; + if ( !strerror_s( msgBuffer, err ) ) { + errMsg = msgBuffer; + } else { + errMsg = "Could not translate errno to a string"; + } + +#else + std::FILE* file = std::fopen( guardFilePath.c_str(), "w" ); + if ( !file ) { + const auto err = errno; + const char* errMsg = std::strerror( err ); +#endif + + CATCH_RUNTIME_ERROR( "Could not open the exit guard file '" + << guardFilePath << "' because '" + << errMsg << "' (" << err << ')' ); + } + const int ret = std::fclose( file ); + CATCH_ENFORCE( + ret == 0, + "Error when closing the exit guard file: " << ret ); + } + } + + // Removes file at path. Assuming we created it in setUpGuardFile. + void tearDownGuardFile( std::string const& guardFilePath ) { + if ( !guardFilePath.empty() ) { + const int ret = std::remove( guardFilePath.c_str() ); + CATCH_ENFORCE( + ret == 0, + "Error when removing the exit guard file: " << ret ); + } + } + } // anon namespace Session::Session() { @@ -267,6 +304,7 @@ namespace Catch { static_cast(std::getchar()); } int exitCode = runInternal(); + if( ( m_configData.waitForKeypress & WaitForKeypress::BeforeExit ) != 0 ) { Catch::cout() << "...waiting for enter/ return before exiting, with code: " << exitCode << '\n' << std::flush; static_cast(std::getchar()); @@ -307,6 +345,10 @@ namespace Catch { CATCH_TRY { config(); // Force config to be constructed + // We need to retrieve potential Bazel config with the full Config + // constructor, so we have to create the guard file after it is created. + setUpGuardFile( m_config->getExitGuardFilePath() ); + seedRng( *m_config ); if (m_configData.filenamesAsTags) { @@ -336,9 +378,12 @@ namespace Catch { TestGroup tests { CATCH_MOVE(reporter), m_config.get() }; auto const totals = tests.execute(); + // If we got here, running the tests finished normally-enough. + // They might've failed, but that would've been reported elsewhere. + tearDownGuardFile( m_config->getExitGuardFilePath() ); + if ( tests.hadUnmatchedTestSpecs() && m_config->warnAboutUnmatchedTestSpecs() ) { - // UnmatchedTestSpecExitCode return UnmatchedTestSpecExitCode; } diff --git a/catch2/src/catch2/catch_session.hpp b/catch2/src/catch2/catch_session.hpp index c1de6d5..23fc6f8 100644 --- a/catch2/src/catch2/catch_session.hpp +++ b/catch2/src/catch2/catch_session.hpp @@ -16,6 +16,14 @@ namespace Catch { + // TODO: Use C++17 `inline` variables + constexpr int UnspecifiedErrorExitCode = 1; + constexpr int NoTestsRunExitCode = 2; + constexpr int UnmatchedTestSpecExitCode = 3; + constexpr int AllTestsSkippedExitCode = 4; + constexpr int InvalidTestSpecExitCode = 5; + constexpr int TestFailureExitCode = 42; + class Session : Detail::NonCopyable { public: diff --git a/catch2/src/catch2/catch_tag_alias_autoregistrar.hpp b/catch2/src/catch2/catch_tag_alias_autoregistrar.hpp index 9f80f72..4fc183a 100644 --- a/catch2/src/catch2/catch_tag_alias_autoregistrar.hpp +++ b/catch2/src/catch2/catch_tag_alias_autoregistrar.hpp @@ -23,7 +23,7 @@ namespace Catch { #define CATCH_REGISTER_TAG_ALIAS( alias, spec ) \ CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ - namespace{ Catch::RegistrarForTagAliases INTERNAL_CATCH_UNIQUE_NAME( AutoRegisterTagAlias )( alias, spec, CATCH_INTERNAL_LINEINFO ); } \ + namespace{ const Catch::RegistrarForTagAliases INTERNAL_CATCH_UNIQUE_NAME( AutoRegisterTagAlias )( alias, spec, CATCH_INTERNAL_LINEINFO ); } \ CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION #endif // CATCH_TAG_ALIAS_AUTOREGISTRAR_HPP_INCLUDED diff --git a/catch2/src/catch2/catch_test_macros.hpp b/catch2/src/catch2/catch_test_macros.hpp index 6ee2129..9770855 100644 --- a/catch2/src/catch2/catch_test_macros.hpp +++ b/catch2/src/catch2/catch_test_macros.hpp @@ -14,6 +14,7 @@ #include #include #include +#include // All of our user-facing macros support configuration toggle, that @@ -47,10 +48,16 @@ #define CATCH_REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ ) #define CATCH_SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ ) #define CATCH_DYNAMIC_SECTION( ... ) INTERNAL_CATCH_DYNAMIC_SECTION( __VA_ARGS__ ) - #define CATCH_FAIL( ... ) INTERNAL_CATCH_MSG( "CATCH_FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, __VA_ARGS__ ) + #define CATCH_FAIL( ... ) do { \ + INTERNAL_CATCH_MSG("CATCH_FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, __VA_ARGS__ ); \ + Catch::Detail::Unreachable(); \ + } while ( false ) #define CATCH_FAIL_CHECK( ... ) INTERNAL_CATCH_MSG( "CATCH_FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) #define CATCH_SUCCEED( ... ) INTERNAL_CATCH_MSG( "CATCH_SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) - #define CATCH_SKIP( ... ) INTERNAL_CATCH_MSG( "SKIP", Catch::ResultWas::ExplicitSkip, Catch::ResultDisposition::Normal, __VA_ARGS__ ) + #define CATCH_SKIP( ... ) do { \ + INTERNAL_CATCH_MSG( "CATCH_SKIP", Catch::ResultWas::ExplicitSkip, Catch::ResultDisposition::Normal, __VA_ARGS__ ); \ + Catch::Detail::Unreachable(); \ + } while (false) #if !defined(CATCH_CONFIG_RUNTIME_STATIC_REQUIRE) @@ -148,10 +155,16 @@ #define REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ ) #define SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ ) #define DYNAMIC_SECTION( ... ) INTERNAL_CATCH_DYNAMIC_SECTION( __VA_ARGS__ ) - #define FAIL( ... ) INTERNAL_CATCH_MSG( "FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, __VA_ARGS__ ) + #define FAIL( ... ) do { \ + INTERNAL_CATCH_MSG( "FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, __VA_ARGS__ ); \ + Catch::Detail::Unreachable(); \ + } while (false) #define FAIL_CHECK( ... ) INTERNAL_CATCH_MSG( "FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) #define SUCCEED( ... ) INTERNAL_CATCH_MSG( "SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) - #define SKIP( ... ) INTERNAL_CATCH_MSG( "SKIP", Catch::ResultWas::ExplicitSkip, Catch::ResultDisposition::Normal, __VA_ARGS__ ) + #define SKIP( ... ) do { \ + INTERNAL_CATCH_MSG( "SKIP", Catch::ResultWas::ExplicitSkip, Catch::ResultDisposition::Normal, __VA_ARGS__ ); \ + Catch::Detail::Unreachable(); \ + } while (false) #if !defined(CATCH_CONFIG_RUNTIME_STATIC_REQUIRE) diff --git a/catch2/src/catch2/internal/catch_test_run_info.hpp b/catch2/src/catch2/catch_test_run_info.hpp similarity index 100% rename from catch2/src/catch2/internal/catch_test_run_info.hpp rename to catch2/src/catch2/catch_test_run_info.hpp diff --git a/catch2/src/catch2/catch_tostring.cpp b/catch2/src/catch2/catch_tostring.cpp index 83327cf..cc68656 100644 --- a/catch2/src/catch2/catch_tostring.cpp +++ b/catch2/src/catch2/catch_tostring.cpp @@ -8,10 +8,10 @@ #include #include +#include #include #include -#include #include namespace Catch { @@ -61,35 +61,35 @@ namespace Detail { std::string ret; // This is enough for the "don't escape invisibles" case, and a good // lower bound on the "escape invisibles" case. - ret.reserve(string.size() + 2); + ret.reserve( string.size() + 2 ); - if (!escapeInvisibles) { + if ( !escapeInvisibles ) { ret += '"'; ret += string; ret += '"'; return ret; } + size_t last_start = 0; + auto write_to = [&]( size_t idx ) { + if ( last_start < idx ) { + ret += string.substr( last_start, idx - last_start ); + } + last_start = idx + 1; + }; + ret += '"'; - for (char c : string) { - switch (c) { - case '\r': - ret.append("\\r"); - break; - case '\n': - ret.append("\\n"); - break; - case '\t': - ret.append("\\t"); - break; - case '\f': - ret.append("\\f"); - break; - default: - ret.push_back(c); - break; + for ( size_t i = 0; i < string.size(); ++i ) { + const char c = string[i]; + if ( c == '\r' || c == '\n' || c == '\t' || c == '\f' ) { + write_to( i ); + if ( c == '\r' ) { ret.append( "\\r" ); } + if ( c == '\n' ) { ret.append( "\\n" ); } + if ( c == '\t' ) { ret.append( "\\t" ); } + if ( c == '\f' ) { ret.append( "\\f" ); } } } + write_to( string.size() ); ret += '"'; return ret; @@ -114,6 +114,13 @@ namespace Detail { rss << std::setw(2) << static_cast(bytes[i]); return rss.str(); } + + std::string makeExceptionHappenedString() { + return "{ stringification failed with an exception: \"" + + translateActiveException() + "\" }"; + + } + } // end Detail namespace diff --git a/catch2/src/catch2/catch_tostring.hpp b/catch2/src/catch2/catch_tostring.hpp index 5f84196..41f8941 100644 --- a/catch2/src/catch2/catch_tostring.hpp +++ b/catch2/src/catch2/catch_tostring.hpp @@ -64,18 +64,14 @@ namespace Catch { return rawMemoryToString( &object, sizeof(object) ); } - template - class IsStreamInsertable { - template - static auto test(int) - -> decltype(std::declval() << std::declval(), std::true_type()); - - template - static auto test(...)->std::false_type; + template + static constexpr bool IsStreamInsertable_v = false; - public: - static const bool value = decltype(test(0))::value; - }; + template + static constexpr bool IsStreamInsertable_v< + T, + decltype( void( std::declval() << std::declval() ) )> = + true; template std::string convertUnknownEnumToString( E e ); @@ -120,7 +116,7 @@ namespace Catch { struct StringMaker { template static - std::enable_if_t<::Catch::Detail::IsStreamInsertable::value, std::string> + std::enable_if_t<::Catch::Detail::IsStreamInsertable_v, std::string> convert(const Fake& value) { ReusableStringStream rss; // NB: call using the function-like syntax to avoid ambiguity with @@ -131,7 +127,7 @@ namespace Catch { template static - std::enable_if_t::value, std::string> + std::enable_if_t, std::string> convert( const Fake& value ) { #if !defined(CATCH_CONFIG_FALLBACK_STRINGIFIER) return Detail::convertUnstreamable(value); @@ -143,11 +139,17 @@ namespace Catch { namespace Detail { + std::string makeExceptionHappenedString(); + // This function dispatches all stringification requests inside of Catch. // Should be preferably called fully qualified, like ::Catch::Detail::stringify template - std::string stringify(const T& e) { - return ::Catch::StringMaker>>::convert(e); + std::string stringify( const T& e ) { + CATCH_TRY { + return ::Catch::StringMaker< + std::remove_cv_t>>::convert( e ); + } + CATCH_CATCH_ALL { return makeExceptionHappenedString(); } } template @@ -523,7 +525,7 @@ namespace Catch { } template - struct StringMaker::value && !::Catch::Detail::IsStreamInsertable::value>> { + struct StringMaker::value && !::Catch::Detail::IsStreamInsertable_v>> { static std::string convert( R const& range ) { return rangeToString( range ); } @@ -630,17 +632,19 @@ struct ratio_string { template struct StringMaker> { static std::string convert(std::chrono::time_point const& time_point) { - auto converted = std::chrono::system_clock::to_time_t(time_point); + const auto systemish = std::chrono::time_point_cast< + std::chrono::system_clock::duration>( time_point ); + const auto as_time_t = std::chrono::system_clock::to_time_t( systemish ); #ifdef _MSC_VER std::tm timeInfo = {}; - const auto err = gmtime_s(&timeInfo, &converted); + const auto err = gmtime_s( &timeInfo, &as_time_t ); if ( err ) { return "gmtime from provided timepoint has failed. This " "happens e.g. with pre-1970 dates using Microsoft libc"; } #else - std::tm* timeInfo = std::gmtime(&converted); + std::tm* timeInfo = std::gmtime( &as_time_t ); #endif auto const timeStampSize = sizeof("2017-01-16T17:06:45Z"); diff --git a/catch2/src/catch2/catch_translate_exception.hpp b/catch2/src/catch2/catch_translate_exception.hpp index 2bf8d36..4d3bac6 100644 --- a/catch2/src/catch2/catch_translate_exception.hpp +++ b/catch2/src/catch2/catch_translate_exception.hpp @@ -65,7 +65,7 @@ namespace Catch { static std::string translatorName( signature ); \ CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ - namespace{ Catch::ExceptionTranslatorRegistrar INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionRegistrar )( &translatorName ); } \ + namespace{ const Catch::ExceptionTranslatorRegistrar INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionRegistrar )( &translatorName ); } \ CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \ static std::string translatorName( signature ) diff --git a/catch2/src/catch2/catch_user_config.hpp.in b/catch2/src/catch2/catch_user_config.hpp.in index 3acda68..18e2ef1 100644 --- a/catch2/src/catch2/catch_user_config.hpp.in +++ b/catch2/src/catch2/catch_user_config.hpp.in @@ -187,6 +187,24 @@ #endif +#cmakedefine CATCH_CONFIG_DEPRECATION_ANNOTATIONS +#cmakedefine CATCH_CONFIG_NO_DEPRECATION_ANNOTATIONS + +#if defined( CATCH_CONFIG_DEPRECATION_ANNOTATIONS ) && \ + defined( CATCH_CONFIG_NO_DEPRECATION_ANNOTATIONS ) +# error Cannot force DEPRECATION_ANNOTATIONS to both ON and OFF +#endif + + +#cmakedefine CATCH_CONFIG_EXPERIMENTAL_THREAD_SAFE_ASSERTIONS +#cmakedefine CATCH_CONFIG_NO_EXPERIMENTAL_THREAD_SAFE_ASSERTIONS + +#if defined( CATCH_CONFIG_EXPERIMENTAL_THREAD_SAFE_ASSERTIONS ) && \ + defined( CATCH_CONFIG_NO_EXPERIMENTAL_THREAD_SAFE_ASSERTIONS ) +# error Cannot force EXPERIMENTAL_THREAD_SAFE_ASSERTIONS to both ON and OFF +#endif + + // ------ // Simple toggle defines // their value is never used and they cannot be overridden diff --git a/catch2/src/catch2/catch_version.cpp b/catch2/src/catch2/catch_version.cpp index 2c40ccc..39b0c0b 100644 --- a/catch2/src/catch2/catch_version.cpp +++ b/catch2/src/catch2/catch_version.cpp @@ -36,7 +36,7 @@ namespace Catch { } Version const& libraryVersion() { - static Version version( 3, 8, 1, "", 0 ); + static Version version( 3, 11, 0, "", 0 ); return version; } diff --git a/catch2/src/catch2/catch_version_macros.hpp b/catch2/src/catch2/catch_version_macros.hpp index 42655fa..630f5b0 100644 --- a/catch2/src/catch2/catch_version_macros.hpp +++ b/catch2/src/catch2/catch_version_macros.hpp @@ -9,7 +9,7 @@ #define CATCH_VERSION_MACROS_HPP_INCLUDED #define CATCH_VERSION_MAJOR 3 -#define CATCH_VERSION_MINOR 8 -#define CATCH_VERSION_PATCH 1 +#define CATCH_VERSION_MINOR 11 +#define CATCH_VERSION_PATCH 0 #endif // CATCH_VERSION_MACROS_HPP_INCLUDED diff --git a/catch2/src/catch2/generators/catch_generator_exception.hpp b/catch2/src/catch2/generators/catch_generator_exception.hpp index f353042..8dffcd2 100644 --- a/catch2/src/catch2/generators/catch_generator_exception.hpp +++ b/catch2/src/catch2/generators/catch_generator_exception.hpp @@ -23,7 +23,7 @@ namespace Catch { m_msg(msg) {} - const char* what() const noexcept override final; + const char* what() const noexcept final; }; } // end namespace Catch diff --git a/catch2/src/catch2/generators/catch_generators_adapters.hpp b/catch2/src/catch2/generators/catch_generators_adapters.hpp index d5fc1e1..f623bd2 100644 --- a/catch2/src/catch2/generators/catch_generators_adapters.hpp +++ b/catch2/src/catch2/generators/catch_generators_adapters.hpp @@ -58,8 +58,9 @@ namespace Generators { class FilterGenerator final : public IGenerator { GeneratorWrapper m_generator; Predicate m_predicate; + static_assert(!std::is_reference::value, "This would most likely result in a dangling reference"); public: - template + template FilterGenerator(P&& pred, GeneratorWrapper&& generator): m_generator(CATCH_MOVE(generator)), m_predicate(CATCH_FORWARD(pred)) @@ -91,7 +92,7 @@ namespace Generators { template GeneratorWrapper filter(Predicate&& pred, GeneratorWrapper&& generator) { - return GeneratorWrapper(Catch::Detail::make_unique>(CATCH_FORWARD(pred), CATCH_MOVE(generator))); + return GeneratorWrapper(Catch::Detail::make_unique::type>>(CATCH_FORWARD(pred), CATCH_MOVE(generator))); } template diff --git a/catch2/src/catch2/interfaces/catch_interfaces_capture.cpp b/catch2/src/catch2/interfaces/catch_interfaces_capture.cpp index 9b40ee5..492c5bd 100644 --- a/catch2/src/catch2/interfaces/catch_interfaces_capture.cpp +++ b/catch2/src/catch2/interfaces/catch_interfaces_capture.cpp @@ -7,7 +7,14 @@ // SPDX-License-Identifier: BSL-1.0 #include +#include namespace Catch { + namespace Detail { + void missingCaptureInstance() { + CATCH_INTERNAL_ERROR( "No result capture instance" ); + } + } // namespace Detail + IResultCapture::~IResultCapture() = default; -} +} // namespace Catch diff --git a/catch2/src/catch2/interfaces/catch_interfaces_capture.hpp b/catch2/src/catch2/interfaces/catch_interfaces_capture.hpp index 9e5431d..4e27a98 100644 --- a/catch2/src/catch2/interfaces/catch_interfaces_capture.hpp +++ b/catch2/src/catch2/interfaces/catch_interfaces_capture.hpp @@ -10,6 +10,7 @@ #include +#include #include #include #include @@ -62,10 +63,9 @@ namespace Catch { virtual void benchmarkEnded( BenchmarkStats<> const& stats ) = 0; virtual void benchmarkFailed( StringRef error ) = 0; - virtual void pushScopedMessage( MessageInfo const& message ) = 0; - virtual void popScopedMessage( MessageInfo const& message ) = 0; - - virtual void emplaceUnscopedMessage( MessageBuilder&& builder ) = 0; + static void pushScopedMessage( MessageInfo&& message ); + static void popScopedMessage( unsigned int messageId ); + static void emplaceUnscopedMessage( MessageBuilder&& builder ); virtual void handleFatalErrorCondition( StringRef message ) = 0; @@ -93,9 +93,7 @@ namespace Catch { AssertionReaction &reaction ) = 0; - virtual bool lastAssertionPassed() = 0; - virtual void assertionPassed() = 0; // Deprecated, do not use: virtual std::string getCurrentTestName() const = 0; @@ -103,7 +101,18 @@ namespace Catch { virtual void exceptionEarlyReported() = 0; }; - IResultCapture& getResultCapture(); + namespace Detail { + [[noreturn]] + void missingCaptureInstance(); + } + inline IResultCapture& getResultCapture() { + if (auto* capture = getCurrentContext().getResultCapture()) { + return *capture; + } else { + Detail::missingCaptureInstance(); + } + } + } #endif // CATCH_INTERFACES_CAPTURE_HPP_INCLUDED diff --git a/catch2/src/catch2/interfaces/catch_interfaces_config.hpp b/catch2/src/catch2/interfaces/catch_interfaces_config.hpp index eb05480..82a298d 100644 --- a/catch2/src/catch2/interfaces/catch_interfaces_config.hpp +++ b/catch2/src/catch2/interfaces/catch_interfaces_config.hpp @@ -12,7 +12,6 @@ #include #include -#include #include #include diff --git a/catch2/src/catch2/interfaces/catch_interfaces_reporter.hpp b/catch2/src/catch2/interfaces/catch_interfaces_reporter.hpp index a052c5d..c721788 100644 --- a/catch2/src/catch2/interfaces/catch_interfaces_reporter.hpp +++ b/catch2/src/catch2/interfaces/catch_interfaces_reporter.hpp @@ -9,18 +9,17 @@ #define CATCH_INTERFACES_REPORTER_HPP_INCLUDED #include +#include #include #include #include #include -#include #include #include #include #include #include -#include namespace Catch { @@ -116,6 +115,11 @@ namespace Catch { //! Catch2 should call `Reporter::assertionEnded` even for passing //! assertions bool shouldReportAllAssertions = false; + //! Catch2 should call `Reporter::assertionStarting` for all assertions + // Defaults to true for backwards compatibility, but none of our current + // reporters actually want this, and it enables a fast path in assertion + // handling. + bool shouldReportAllAssertionStarts = true; }; /** diff --git a/catch2/src/catch2/internal/catch_clara.hpp b/catch2/src/catch2/internal/catch_clara.hpp index d869593..85874a1 100644 --- a/catch2/src/catch2/internal/catch_clara.hpp +++ b/catch2/src/catch2/internal/catch_clara.hpp @@ -66,15 +66,13 @@ namespace Catch { }; template - struct is_unary_function : std::false_type {}; + static constexpr bool is_unary_function_v = false; template - struct is_unary_function< + static constexpr bool is_unary_function_v< F, - Catch::Detail::void_t()( fake_arg() ) ) - > - > : std::true_type {}; + Catch::Detail::void_t()( + fake_arg() ) )>> = true; // Traits for extracting arg and return type of lambdas (for single // argument lambdas) @@ -507,14 +505,14 @@ namespace Catch { template ::value>> + !Detail::is_unary_function_v>> ParserRefImpl( T& ref, StringRef hint ): m_ref( std::make_shared>( ref ) ), m_hint( hint ) {} template ::value>> + Detail::is_unary_function_v>> ParserRefImpl( LambdaT const& ref, StringRef hint ): m_ref( std::make_shared>( ref ) ), m_hint( hint ) {} @@ -581,7 +579,7 @@ namespace Catch { template ::value>> + Detail::is_unary_function_v>> Opt( LambdaT const& ref, StringRef hint ): ParserRefImpl( ref, hint ) {} @@ -591,7 +589,7 @@ namespace Catch { template ::value>> + !Detail::is_unary_function_v>> Opt( T& ref, StringRef hint ): ParserRefImpl( ref, hint ) {} diff --git a/catch2/src/catch2/internal/catch_commandline.cpp b/catch2/src/catch2/internal/catch_commandline.cpp index 212f177..db90350 100644 --- a/catch2/src/catch2/internal/catch_commandline.cpp +++ b/catch2/src/catch2/internal/catch_commandline.cpp @@ -305,6 +305,9 @@ namespace Catch { | Opt( config.allowZeroTests ) ["--allow-running-no-tests"] ( "Treat 'No tests run' as a success" ) + | Opt( config.prematureExitGuardFilePath, "path" ) + ["--premature-exit-guard-file"] + ( "create a file before running tests and delete it during clean exit" ) | Arg( config.testsOrTags, "test name|pattern|tags" ) ( "which test or tests to use" ); diff --git a/catch2/src/catch2/internal/catch_compiler_capabilities.hpp b/catch2/src/catch2/internal/catch_compiler_capabilities.hpp index 4cf1d65..983fb63 100644 --- a/catch2/src/catch2/internal/catch_compiler_capabilities.hpp +++ b/catch2/src/catch2/internal/catch_compiler_capabilities.hpp @@ -220,13 +220,17 @@ # endif // Universal Windows platform does not support SEH -// Or console colours (or console at all...) -# if defined(CATCH_PLATFORM_WINDOWS_UWP) -# define CATCH_INTERNAL_CONFIG_NO_COLOUR_WIN32 -# else +# if !defined(CATCH_PLATFORM_WINDOWS_UWP) # define CATCH_INTERNAL_CONFIG_WINDOWS_SEH # endif +// Only some Windows platform families support the console +# if defined(WINAPI_FAMILY_PARTITION) +# if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_SYSTEM) +# define CATCH_INTERNAL_CONFIG_NO_COLOUR_WIN32 +# endif +# endif + // MSVC traditional preprocessor needs some workaround for __VA_ARGS__ // _MSVC_TRADITIONAL == 0 means new conformant preprocessor // _MSVC_TRADITIONAL == 1 means old traditional non-conformant preprocessor diff --git a/catch2/src/catch2/internal/catch_console_colour.cpp b/catch2/src/catch2/internal/catch_console_colour.cpp index 142de9e..948c4cb 100644 --- a/catch2/src/catch2/internal/catch_console_colour.cpp +++ b/catch2/src/catch2/internal/catch_console_colour.cpp @@ -161,7 +161,11 @@ namespace { #endif // Windows/ ANSI/ None -#if defined( CATCH_PLATFORM_LINUX ) || defined( CATCH_PLATFORM_MAC ) || defined( __GLIBC__ ) +#if defined( CATCH_PLATFORM_LINUX ) \ + || defined( CATCH_PLATFORM_MAC ) \ + || defined( __GLIBC__ ) \ + || defined( __FreeBSD__ ) \ + || defined( CATCH_PLATFORM_QNX ) # define CATCH_INTERNAL_HAS_ISATTY # include #endif diff --git a/catch2/src/catch2/internal/catch_context.cpp b/catch2/src/catch2/internal/catch_context.cpp index 8acf1ed..5389de3 100644 --- a/catch2/src/catch2/internal/catch_context.cpp +++ b/catch2/src/catch2/internal/catch_context.cpp @@ -6,25 +6,14 @@ // SPDX-License-Identifier: BSL-1.0 #include -#include #include namespace Catch { - Context* Context::currentContext = nullptr; - - void cleanUpContext() { - delete Context::currentContext; - Context::currentContext = nullptr; - } - void Context::createContext() { - currentContext = new Context(); - } + Context Context::currentContext; Context& getCurrentMutableContext() { - if ( !Context::currentContext ) { Context::createContext(); } - // NOLINTNEXTLINE(clang-analyzer-core.uninitialized.UndefReturn) - return *Context::currentContext; + return Context::currentContext; } SimplePcg32& sharedRng() { diff --git a/catch2/src/catch2/internal/catch_context.hpp b/catch2/src/catch2/internal/catch_context.hpp index 4d8a5da..0b89632 100644 --- a/catch2/src/catch2/internal/catch_context.hpp +++ b/catch2/src/catch2/internal/catch_context.hpp @@ -19,11 +19,9 @@ namespace Catch { IConfig const* m_config = nullptr; IResultCapture* m_resultCapture = nullptr; - CATCH_EXPORT static Context* currentContext; + CATCH_EXPORT static Context currentContext; friend Context& getCurrentMutableContext(); friend Context const& getCurrentContext(); - static void createContext(); - friend void cleanUpContext(); public: constexpr IResultCapture* getResultCapture() const { @@ -34,21 +32,14 @@ namespace Catch { m_resultCapture = resultCapture; } constexpr void setConfig( IConfig const* config ) { m_config = config; } - }; Context& getCurrentMutableContext(); inline Context const& getCurrentContext() { - // We duplicate the logic from `getCurrentMutableContext` here, - // to avoid paying the call overhead in debug mode. - if ( !Context::currentContext ) { Context::createContext(); } - // NOLINTNEXTLINE(clang-analyzer-core.uninitialized.UndefReturn) - return *Context::currentContext; + return Context::currentContext; } - void cleanUpContext(); - class SimplePcg32; SimplePcg32& sharedRng(); } diff --git a/catch2/src/catch2/internal/catch_debugger.cpp b/catch2/src/catch2/internal/catch_debugger.cpp index bd3be17..da22c7f 100644 --- a/catch2/src/catch2/internal/catch_debugger.cpp +++ b/catch2/src/catch2/internal/catch_debugger.cpp @@ -69,7 +69,7 @@ #endif } // namespace Catch -#elif defined(CATCH_PLATFORM_LINUX) +#elif defined(CATCH_PLATFORM_LINUX) || defined(CATCH_PLATFORM_QNX) #include #include diff --git a/catch2/src/catch2/internal/catch_debugger.hpp b/catch2/src/catch2/internal/catch_debugger.hpp index 25c5a26..997f440 100644 --- a/catch2/src/catch2/internal/catch_debugger.hpp +++ b/catch2/src/catch2/internal/catch_debugger.hpp @@ -14,6 +14,17 @@ namespace Catch { bool isDebuggerActive(); } +#if !defined( CATCH_TRAP ) && defined( __clang__ ) && defined( __has_builtin ) +# if __has_builtin( __builtin_debugtrap ) +# define CATCH_TRAP() __builtin_debugtrap() +# endif +#endif + +#if !defined( CATCH_TRAP ) && defined( _MSC_VER ) +# define CATCH_TRAP() __debugbreak() +#endif + +#if !defined(CATCH_TRAP) // If we couldn't use compiler-specific impl from above, we get into platform-specific options #ifdef CATCH_PLATFORM_MAC #if defined(__i386__) || defined(__x86_64__) @@ -38,7 +49,7 @@ namespace Catch { #define CATCH_TRAP() __asm__(".inst 0xde01") #endif -#elif defined(CATCH_PLATFORM_LINUX) +#elif defined(CATCH_PLATFORM_LINUX) || defined(CATCH_PLATFORM_QNX) // If we can use inline assembler, do it because this allows us to break // directly at the location of the failing check instead of breaking inside // raise() called from it, i.e. one stack frame below. @@ -49,15 +60,15 @@ namespace Catch { #define CATCH_TRAP() raise(SIGTRAP) #endif -#elif defined(_MSC_VER) - #define CATCH_TRAP() __debugbreak() #elif defined(__MINGW32__) extern "C" __declspec(dllimport) void __stdcall DebugBreak(); #define CATCH_TRAP() DebugBreak() #endif +#endif // ^^ CATCH_TRAP is not defined yet, so we define it + -#ifndef CATCH_BREAK_INTO_DEBUGGER - #ifdef CATCH_TRAP +#if !defined(CATCH_BREAK_INTO_DEBUGGER) + #if defined(CATCH_TRAP) #define CATCH_BREAK_INTO_DEBUGGER() []{ if( Catch::isDebuggerActive() ) { CATCH_TRAP(); } }() #else #define CATCH_BREAK_INTO_DEBUGGER() []{}() diff --git a/catch2/src/catch2/internal/catch_decomposer.hpp b/catch2/src/catch2/internal/catch_decomposer.hpp index adce89f..fcc017d 100644 --- a/catch2/src/catch2/internal/catch_decomposer.hpp +++ b/catch2/src/catch2/internal/catch_decomposer.hpp @@ -45,7 +45,7 @@ * when the compiler handles `ExprLhs == b`, it also tries to resolve * the overload set for `b == ExprLhs`. * - * To accomodate these use cases, decomposer ended up rather complex. + * To accommodate these use cases, decomposer ended up rather complex. * * 1) These types are handled by adding SFINAE overloads to our comparison * operators, checking whether `T == U` are comparable with the given @@ -78,10 +78,11 @@ * * 3) If a type has no linkage, we also cannot capture it by reference. * The solution is once again to capture them by value. We handle - * the common cases by using `std::is_arithmetic` as the default - * for `Catch::capture_by_value`, but that is only a some-effort - * heuristic. But as with 2), users can specialize `capture_by_value` - * for their own types as needed. + * the common cases by using `std::is_arithmetic` and `std::is_enum` + * as the default for `Catch::capture_by_value`, but that is only a + * some-effort heuristic. These combine to capture all possible bitfield + * bases, and also some trait-like types. As with 2), users can + * specialize `capture_by_value` for their own types as needed. * * 4) To support C++20 and make the SFINAE on our decomposing operators * work, the SFINAE has to happen in return type, rather than in @@ -133,13 +134,22 @@ namespace Catch { using RemoveCVRef_t = std::remove_cv_t>; } - // Note: There is nothing that stops us from extending this, - // e.g. to `std::is_scalar`, but the more encompassing - // traits are usually also more expensive. For now we - // keep this as it used to be and it can be changed later. + // Note: This is about as much as we can currently reasonably support. + // In an ideal world, we could capture by value small trivially + // copyable types, but the actual `std::is_trivially_copyable` + // trait is a huge mess with standard-violating results on + // GCC and Clang, which are unlikely to be fixed soon due to ABI + // concerns. + // `std::is_scalar` also causes issues due to the `is_pointer` + // component, which causes ambiguity issues with (references-to) + // function pointer. If those are resolved, we still need to + // disambiguate the overload set for arrays, through explicit + // overload for references to sized arrays. template struct capture_by_value - : std::integral_constant{}> {}; + : std::integral_constant::value || + std::is_enum::value> {}; #if defined( CATCH_CONFIG_CPP20_COMPARE_OVERLOADS ) template <> @@ -163,7 +173,7 @@ namespace Catch { public: constexpr auto isBinaryExpression() const -> bool { return m_isBinaryExpression; } constexpr auto getResult() const -> bool { return m_result; } - //! This function **has** to be overriden by the derived class. + //! This function **has** to be overridden by the derived class. virtual void streamReconstructedExpression( std::ostream& os ) const; constexpr ITransientExpression( bool isBinaryExpression, bool result ) diff --git a/catch2/src/catch2/internal/catch_deprecation_macro.hpp b/catch2/src/catch2/internal/catch_deprecation_macro.hpp new file mode 100644 index 0000000..7834882 --- /dev/null +++ b/catch2/src/catch2/internal/catch_deprecation_macro.hpp @@ -0,0 +1,19 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 +#ifndef CATCH_DEPRECATION_MACRO_HPP_INCLUDED +#define CATCH_DEPRECATION_MACRO_HPP_INCLUDED + +#include + +#if !defined( CATCH_CONFIG_NO_DEPRECATION_ANNOTATIONS ) +# define DEPRECATED( msg ) [[deprecated( msg )]] +#else +# define DEPRECATED( msg ) +#endif + +#endif // CATCH_DEPRECATION_MACRO_HPP_INCLUDED diff --git a/catch2/src/catch2/internal/catch_enforce.hpp b/catch2/src/catch2/internal/catch_enforce.hpp index 076cea3..171ea12 100644 --- a/catch2/src/catch2/internal/catch_enforce.hpp +++ b/catch2/src/catch2/internal/catch_enforce.hpp @@ -12,7 +12,7 @@ #include #include -#include +#include // for `std::exception` in no-exception configuration namespace Catch { #if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) diff --git a/catch2/src/catch2/internal/catch_exception_translator_registry.cpp b/catch2/src/catch2/internal/catch_exception_translator_registry.cpp index 1eb6114..8867d78 100644 --- a/catch2/src/catch2/internal/catch_exception_translator_registry.cpp +++ b/catch2/src/catch2/internal/catch_exception_translator_registry.cpp @@ -59,10 +59,10 @@ namespace Catch { // To avoid having to handle TFE explicitly everywhere, we just // rethrow it so that it goes back up the caller. catch( TestFailureException& ) { - std::rethrow_exception(std::current_exception()); + return "{ nested assertion failed }"; } catch( TestSkipException& ) { - std::rethrow_exception(std::current_exception()); + return "{ nested SKIP() called }"; } catch( std::exception const& ex ) { return ex.what(); diff --git a/catch2/src/catch2/internal/catch_exception_translator_registry.hpp b/catch2/src/catch2/internal/catch_exception_translator_registry.hpp index 3123e93..32917d4 100644 --- a/catch2/src/catch2/internal/catch_exception_translator_registry.hpp +++ b/catch2/src/catch2/internal/catch_exception_translator_registry.hpp @@ -11,7 +11,6 @@ #include #include -#include #include namespace Catch { diff --git a/catch2/src/catch2/internal/catch_fatal_condition_handler.cpp b/catch2/src/catch2/internal/catch_fatal_condition_handler.cpp index 9ef5b21..3dfa138 100644 --- a/catch2/src/catch2/internal/catch_fatal_condition_handler.cpp +++ b/catch2/src/catch2/internal/catch_fatal_condition_handler.cpp @@ -79,30 +79,34 @@ namespace Catch { // There is no 1-1 mapping between signals and windows exceptions. // Windows can easily distinguish between SO and SigSegV, // but SigInt, SigTerm, etc are handled differently. - static SignalDefs signalDefs[] = { + static constexpr SignalDefs signalDefs[] = { { EXCEPTION_ILLEGAL_INSTRUCTION, "SIGILL - Illegal instruction signal" }, { EXCEPTION_STACK_OVERFLOW, "SIGSEGV - Stack overflow" }, { EXCEPTION_ACCESS_VIOLATION, "SIGSEGV - Segmentation violation signal" }, { EXCEPTION_INT_DIVIDE_BY_ZERO, "Divide by zero error" }, }; + // Since we do not support multiple instantiations, we put these + // into global variables and rely on cleaning them up in outlined + // constructors/destructors + static LPTOP_LEVEL_EXCEPTION_FILTER previousTopLevelExceptionFilter = nullptr; + + static LONG CALLBACK topLevelExceptionFilter(PEXCEPTION_POINTERS ExceptionInfo) { for (auto const& def : signalDefs) { if (ExceptionInfo->ExceptionRecord->ExceptionCode == def.id) { reportFatal(def.name); } } - // If its not an exception we care about, pass it along. + // If a filter was previously registered, invoke it + if (previousTopLevelExceptionFilter) { + return previousTopLevelExceptionFilter(ExceptionInfo); + } + // Otherwise, pass along all exceptions. // This stops us from eating debugger breaks etc. return EXCEPTION_CONTINUE_SEARCH; } - // Since we do not support multiple instantiations, we put these - // into global variables and rely on cleaning them up in outlined - // constructors/destructors - static LPTOP_LEVEL_EXCEPTION_FILTER previousTopLevelExceptionFilter = nullptr; - - // For MSVC, we reserve part of the stack memory for handling // memory overflow structured exception. FatalConditionHandler::FatalConditionHandler() { @@ -150,7 +154,7 @@ namespace Catch { const char* name; }; - static SignalDefs signalDefs[] = { + static constexpr SignalDefs signalDefs[] = { { SIGINT, "SIGINT - Terminal interrupt signal" }, { SIGILL, "SIGILL - Illegal instruction signal" }, { SIGFPE, "SIGFPE - Floating point error signal" }, diff --git a/catch2/src/catch2/internal/catch_is_permutation.hpp b/catch2/src/catch2/internal/catch_is_permutation.hpp index c77a6d3..ba7082d 100644 --- a/catch2/src/catch2/internal/catch_is_permutation.hpp +++ b/catch2/src/catch2/internal/catch_is_permutation.hpp @@ -8,8 +8,8 @@ #ifndef CATCH_IS_PERMUTATION_HPP_INCLUDED #define CATCH_IS_PERMUTATION_HPP_INCLUDED -#include #include +#include namespace Catch { namespace Detail { diff --git a/catch2/src/catch2/internal/catch_istream.cpp b/catch2/src/catch2/internal/catch_istream.cpp index 2867ce7..717da0e 100644 --- a/catch2/src/catch2/internal/catch_istream.cpp +++ b/catch2/src/catch2/internal/catch_istream.cpp @@ -14,8 +14,6 @@ #include #include -#include -#include namespace Catch { diff --git a/catch2/src/catch2/internal/catch_istream.hpp b/catch2/src/catch2/internal/catch_istream.hpp index e6b9a2d..1247be3 100644 --- a/catch2/src/catch2/internal/catch_istream.hpp +++ b/catch2/src/catch2/internal/catch_istream.hpp @@ -12,8 +12,6 @@ #include #include -#include -#include #include namespace Catch { diff --git a/catch2/src/catch2/internal/catch_jsonwriter.cpp b/catch2/src/catch2/internal/catch_jsonwriter.cpp index 1a96e34..6915c9c 100644 --- a/catch2/src/catch2/internal/catch_jsonwriter.cpp +++ b/catch2/src/catch2/internal/catch_jsonwriter.cpp @@ -7,8 +7,36 @@ // SPDX-License-Identifier: BSL-1.0 #include #include +#include namespace Catch { + + namespace { + static bool needsEscape( char c ) { + return c == '"' || c == '\\' || c == '\b' || c == '\f' || + c == '\n' || c == '\r' || c == '\t'; + } + + static Catch::StringRef makeEscapeStringRef( char c ) { + if ( c == '"' ) { + return "\\\""_sr; + } else if ( c == '\\' ) { + return "\\\\"_sr; + } else if ( c == '\b' ) { + return "\\b"_sr; + } else if ( c == '\f' ) { + return "\\f"_sr; + } else if ( c == '\n' ) { + return "\\n"_sr; + } else if ( c == '\r' ) { + return "\\r"_sr; + } else if ( c == '\t' ) { + return "\\t"_sr; + } + Catch::Detail::Unreachable(); + } + } // namespace + void JsonUtils::indent( std::ostream& os, std::uint64_t level ) { for ( std::uint64_t i = 0; i < level; ++i ) { os << " "; @@ -118,30 +146,19 @@ namespace Catch { void JsonValueWriter::writeImpl( Catch::StringRef value, bool quote ) { if ( quote ) { m_os << '"'; } - for (char c : value) { - // Escape list taken from https://www.json.org/json-en.html, - // string definition. - // Note that while forward slash _can_ be escaped, it does - // not have to be, if JSON is not further embedded somewhere - // where forward slash is meaningful. - if ( c == '"' ) { - m_os << "\\\""; - } else if ( c == '\\' ) { - m_os << "\\\\"; - } else if ( c == '\b' ) { - m_os << "\\b"; - } else if ( c == '\f' ) { - m_os << "\\f"; - } else if ( c == '\n' ) { - m_os << "\\n"; - } else if ( c == '\r' ) { - m_os << "\\r"; - } else if ( c == '\t' ) { - m_os << "\\t"; - } else { - m_os << c; + size_t current_start = 0; + for ( size_t i = 0; i < value.size(); ++i ) { + if ( needsEscape( value[i] ) ) { + if ( current_start < i ) { + m_os << value.substr( current_start, i - current_start ); + } + m_os << makeEscapeStringRef( value[i] ); + current_start = i + 1; } } + if ( current_start < value.size() ) { + m_os << value.substr( current_start, value.size() - current_start ); + } if ( quote ) { m_os << '"'; } } diff --git a/catch2/src/catch2/internal/catch_main.cpp b/catch2/src/catch2/internal/catch_main.cpp index 503b540..adabdb5 100644 --- a/catch2/src/catch2/internal/catch_main.cpp +++ b/catch2/src/catch2/internal/catch_main.cpp @@ -14,7 +14,7 @@ namespace Catch { CATCH_INTERNAL_START_WARNINGS_SUPPRESSION CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS - static LeakDetector leakDetector; + static const LeakDetector leakDetector; CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION } diff --git a/catch2/src/catch2/internal/catch_message_info.cpp b/catch2/src/catch2/internal/catch_message_info.cpp index e0e9dc7..bc887ab 100644 --- a/catch2/src/catch2/internal/catch_message_info.cpp +++ b/catch2/src/catch2/internal/catch_message_info.cpp @@ -10,16 +10,17 @@ namespace Catch { - MessageInfo::MessageInfo( StringRef _macroName, - SourceLineInfo const& _lineInfo, - ResultWas::OfType _type ) + MessageInfo::MessageInfo( StringRef _macroName, + SourceLineInfo const& _lineInfo, + ResultWas::OfType _type ) : macroName( _macroName ), lineInfo( _lineInfo ), type( _type ), sequence( ++globalCount ) {} - // This may need protecting if threading support is added - unsigned int MessageInfo::globalCount = 0; + // Messages are owned by their individual threads, so the counter should be thread-local as well. + // Alternative consideration: atomic, so threads don't share IDs and things are easier to debug. + thread_local unsigned int MessageInfo::globalCount = 0; } // end namespace Catch diff --git a/catch2/src/catch2/internal/catch_message_info.hpp b/catch2/src/catch2/internal/catch_message_info.hpp index 1ef43fd..8c18186 100644 --- a/catch2/src/catch2/internal/catch_message_info.hpp +++ b/catch2/src/catch2/internal/catch_message_info.hpp @@ -8,6 +8,7 @@ #ifndef CATCH_MESSAGE_INFO_HPP_INCLUDED #define CATCH_MESSAGE_INFO_HPP_INCLUDED +#include #include #include #include @@ -25,16 +26,19 @@ namespace Catch { std::string message; SourceLineInfo lineInfo; ResultWas::OfType type; + // The "ID" of the message, used to know when to remove it from reporter context. unsigned int sequence; + DEPRECATED( "Explicitly use the 'sequence' member instead" ) bool operator == (MessageInfo const& other) const { return sequence == other.sequence; } + DEPRECATED( "Explicitly use the 'sequence' member instead" ) bool operator < (MessageInfo const& other) const { return sequence < other.sequence; } private: - static unsigned int globalCount; + static thread_local unsigned int globalCount; }; } // end namespace Catch diff --git a/catch2/src/catch2/internal/catch_noncopyable.hpp b/catch2/src/catch2/internal/catch_noncopyable.hpp index eb0823e..f574658 100644 --- a/catch2/src/catch2/internal/catch_noncopyable.hpp +++ b/catch2/src/catch2/internal/catch_noncopyable.hpp @@ -13,6 +13,7 @@ namespace Catch { //! Deriving classes become noncopyable and nonmovable class NonCopyable { + public: NonCopyable( NonCopyable const& ) = delete; NonCopyable( NonCopyable&& ) = delete; NonCopyable& operator=( NonCopyable const& ) = delete; diff --git a/catch2/src/catch2/internal/catch_platform.hpp b/catch2/src/catch2/internal/catch_platform.hpp index b653a58..ba4717f 100644 --- a/catch2/src/catch2/internal/catch_platform.hpp +++ b/catch2/src/catch2/internal/catch_platform.hpp @@ -25,6 +25,9 @@ #elif defined(linux) || defined(__linux) || defined(__linux__) # define CATCH_PLATFORM_LINUX +#elif defined(__QNX__) +# define CATCH_PLATFORM_QNX + #elif defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) || defined(__MINGW32__) # define CATCH_PLATFORM_WINDOWS diff --git a/catch2/src/catch2/internal/catch_preprocessor.hpp b/catch2/src/catch2/internal/catch_preprocessor.hpp index 08e844d..1fc8fb8 100644 --- a/catch2/src/catch2/internal/catch_preprocessor.hpp +++ b/catch2/src/catch2/internal/catch_preprocessor.hpp @@ -16,6 +16,15 @@ #endif +namespace Catch { + namespace Detail { + template + struct priority_tag : priority_tag {}; + template <> + struct priority_tag<0> {}; + } +} + #define CATCH_RECURSION_LEVEL0(...) __VA_ARGS__ #define CATCH_RECURSION_LEVEL1(...) CATCH_RECURSION_LEVEL0(CATCH_RECURSION_LEVEL0(CATCH_RECURSION_LEVEL0(__VA_ARGS__))) #define CATCH_RECURSION_LEVEL2(...) CATCH_RECURSION_LEVEL1(CATCH_RECURSION_LEVEL1(CATCH_RECURSION_LEVEL1(__VA_ARGS__))) @@ -75,10 +84,10 @@ #define INTERNAL_CATCH_MAKE_NAMESPACE(name) INTERNAL_CATCH_MAKE_NAMESPACE2(name) #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR -#define INTERNAL_CATCH_MAKE_TYPE_LIST2(...) decltype(get_wrapper()) +#define INTERNAL_CATCH_MAKE_TYPE_LIST2(...) decltype(get_wrapper(Catch::Detail::priority_tag<1>{})) #define INTERNAL_CATCH_MAKE_TYPE_LIST(...) INTERNAL_CATCH_MAKE_TYPE_LIST2(INTERNAL_CATCH_REMOVE_PARENS(__VA_ARGS__)) #else -#define INTERNAL_CATCH_MAKE_TYPE_LIST2(...) INTERNAL_CATCH_EXPAND_VARGS(decltype(get_wrapper())) +#define INTERNAL_CATCH_MAKE_TYPE_LIST2(...) INTERNAL_CATCH_EXPAND_VARGS(decltype(get_wrapper(Catch::Detail::priority_tag<1>{}))) #define INTERNAL_CATCH_MAKE_TYPE_LIST(...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_MAKE_TYPE_LIST2(INTERNAL_CATCH_REMOVE_PARENS(__VA_ARGS__))) #endif @@ -101,11 +110,11 @@ #define INTERNAL_CATCH_TYPE_GEN\ template struct TypeList {};\ - template\ - constexpr auto get_wrapper() noexcept -> TypeList { return {}; }\ + template\ + constexpr auto get_wrapper(Catch::Detail::priority_tag<1>) noexcept -> TypeList { return {}; }\ template class...> struct TemplateTypeList{};\ template class...Cs>\ - constexpr auto get_wrapper() noexcept -> TemplateTypeList { return {}; }\ + constexpr auto get_wrapper(Catch::Detail::priority_tag<1>) noexcept -> TemplateTypeList { return {}; }\ template\ struct append;\ template\ @@ -135,10 +144,10 @@ #define INTERNAL_CATCH_NTTP_1(signature, ...)\ template struct Nttp{};\ template\ - constexpr auto get_wrapper() noexcept -> Nttp<__VA_ARGS__> { return {}; } \ + constexpr auto get_wrapper(Catch::Detail::priority_tag<0>) noexcept -> Nttp<__VA_ARGS__> { return {}; } \ template class...> struct NttpTemplateTypeList{};\ template class...Cs>\ - constexpr auto get_wrapper() noexcept -> NttpTemplateTypeList { return {}; } \ + constexpr auto get_wrapper(Catch::Detail::priority_tag<0>) noexcept -> NttpTemplateTypeList { return {}; } \ \ template< template class Container, template class List, INTERNAL_CATCH_REMOVE_PARENS(signature)>\ struct rewrap, List<__VA_ARGS__>> { using type = TypeList>; };\ @@ -163,13 +172,14 @@ template\ static void TestName() -#define INTERNAL_CATCH_NTTP_REGISTER0(TestFunc, signature)\ - template\ - void reg_test(TypeList, Catch::NameAndTags nameAndTags)\ +#define INTERNAL_CATCH_TYPES_REGISTER(TestFunc)\ + template\ + void reg_test(TypeList, Catch::NameAndTags nameAndTags)\ {\ - Catch::AutoReg( Catch::makeTestInvoker(&TestFunc), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), nameAndTags);\ + Catch::AutoReg( Catch::makeTestInvoker(&TestFunc), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), nameAndTags);\ } +#define INTERNAL_CATCH_NTTP_REGISTER0(TestFunc, signature, ...) #define INTERNAL_CATCH_NTTP_REGISTER(TestFunc, signature, ...)\ template\ void reg_test(Nttp<__VA_ARGS__>, Catch::NameAndTags nameAndTags)\ @@ -218,7 +228,7 @@ #define INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD(TestName, ...) INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD1, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD0)(TestName, __VA_ARGS__) #define INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD(TestName, ClassName, ...) INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD1, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD0)(TestName, ClassName, __VA_ARGS__) #define INTERNAL_CATCH_NTTP_REG_METHOD_GEN(TestName, ...) INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD0, INTERNAL_CATCH_NTTP_REGISTER_METHOD0)(TestName, __VA_ARGS__) -#define INTERNAL_CATCH_NTTP_REG_GEN(TestFunc, ...) INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER0, INTERNAL_CATCH_NTTP_REGISTER0)(TestFunc, __VA_ARGS__) +#define INTERNAL_CATCH_NTTP_REG_GEN(TestFunc, ...) INTERNAL_CATCH_TYPES_REGISTER(TestFunc) INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER0, INTERNAL_CATCH_NTTP_REGISTER0)(TestFunc, __VA_ARGS__) #define INTERNAL_CATCH_DEFINE_SIG_TEST(TestName, ...) INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X,INTERNAL_CATCH_DEFINE_SIG_TEST_X,INTERNAL_CATCH_DEFINE_SIG_TEST1, INTERNAL_CATCH_DEFINE_SIG_TEST0)(TestName, __VA_ARGS__) #define INTERNAL_CATCH_DECLARE_SIG_TEST(TestName, ...) INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DECLARE_SIG_TEST_X,INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X,INTERNAL_CATCH_DECLARE_SIG_TEST_X,INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST1, INTERNAL_CATCH_DECLARE_SIG_TEST0)(TestName, __VA_ARGS__) #define INTERNAL_CATCH_REMOVE_PARENS_GEN(...) INTERNAL_CATCH_VA_NARGS_IMPL(__VA_ARGS__, INTERNAL_CATCH_REMOVE_PARENS_11_ARG,INTERNAL_CATCH_REMOVE_PARENS_10_ARG,INTERNAL_CATCH_REMOVE_PARENS_9_ARG,INTERNAL_CATCH_REMOVE_PARENS_8_ARG,INTERNAL_CATCH_REMOVE_PARENS_7_ARG,INTERNAL_CATCH_REMOVE_PARENS_6_ARG,INTERNAL_CATCH_REMOVE_PARENS_5_ARG,INTERNAL_CATCH_REMOVE_PARENS_4_ARG,INTERNAL_CATCH_REMOVE_PARENS_3_ARG,INTERNAL_CATCH_REMOVE_PARENS_2_ARG,INTERNAL_CATCH_REMOVE_PARENS_1_ARG)(__VA_ARGS__) @@ -228,7 +238,7 @@ #define INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD(TestName, ...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD1, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD0)(TestName, __VA_ARGS__)) #define INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD(TestName, ClassName, ...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD1, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD0)(TestName, ClassName, __VA_ARGS__)) #define INTERNAL_CATCH_NTTP_REG_METHOD_GEN(TestName, ...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD0, INTERNAL_CATCH_NTTP_REGISTER_METHOD0)(TestName, __VA_ARGS__)) -#define INTERNAL_CATCH_NTTP_REG_GEN(TestFunc, ...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER0, INTERNAL_CATCH_NTTP_REGISTER0)(TestFunc, __VA_ARGS__)) +#define INTERNAL_CATCH_NTTP_REG_GEN(TestFunc, ...) INTERNAL_CATCH_TYPES_REGISTER(TestFunc) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER0, INTERNAL_CATCH_NTTP_REGISTER0)(TestFunc, __VA_ARGS__)) #define INTERNAL_CATCH_DEFINE_SIG_TEST(TestName, ...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X,INTERNAL_CATCH_DEFINE_SIG_TEST_X,INTERNAL_CATCH_DEFINE_SIG_TEST1, INTERNAL_CATCH_DEFINE_SIG_TEST0)(TestName, __VA_ARGS__)) #define INTERNAL_CATCH_DECLARE_SIG_TEST(TestName, ...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DECLARE_SIG_TEST_X,INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X,INTERNAL_CATCH_DECLARE_SIG_TEST_X,INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST1, INTERNAL_CATCH_DECLARE_SIG_TEST0)(TestName, __VA_ARGS__)) #define INTERNAL_CATCH_REMOVE_PARENS_GEN(...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL(__VA_ARGS__, INTERNAL_CATCH_REMOVE_PARENS_11_ARG,INTERNAL_CATCH_REMOVE_PARENS_10_ARG,INTERNAL_CATCH_REMOVE_PARENS_9_ARG,INTERNAL_CATCH_REMOVE_PARENS_8_ARG,INTERNAL_CATCH_REMOVE_PARENS_7_ARG,INTERNAL_CATCH_REMOVE_PARENS_6_ARG,INTERNAL_CATCH_REMOVE_PARENS_5_ARG,INTERNAL_CATCH_REMOVE_PARENS_4_ARG,INTERNAL_CATCH_REMOVE_PARENS_3_ARG,INTERNAL_CATCH_REMOVE_PARENS_2_ARG,INTERNAL_CATCH_REMOVE_PARENS_1_ARG)(__VA_ARGS__)) diff --git a/catch2/src/catch2/internal/catch_random_number_generator.cpp b/catch2/src/catch2/internal/catch_random_number_generator.cpp index c88cd8f..e46b5fd 100644 --- a/catch2/src/catch2/internal/catch_random_number_generator.cpp +++ b/catch2/src/catch2/internal/catch_random_number_generator.cpp @@ -7,6 +7,12 @@ // SPDX-License-Identifier: BSL-1.0 #include +#if defined( __clang__ ) +# define CATCH2_CLANG_NO_SANITIZE_INTEGER \ + __attribute__( ( no_sanitize( "unsigned-integer-overflow" ) ) ) +#else +# define CATCH2_CLANG_NO_SANITIZE_INTEGER +#endif namespace Catch { namespace { @@ -16,6 +22,7 @@ namespace { #pragma warning(disable:4146) // we negate uint32 during the rotate #endif // Safe rotr implementation thanks to John Regehr + CATCH2_CLANG_NO_SANITIZE_INTEGER uint32_t rotate_right(uint32_t val, uint32_t count) { const uint32_t mask = 31; count &= mask; @@ -49,6 +56,7 @@ namespace { } } + CATCH2_CLANG_NO_SANITIZE_INTEGER SimplePcg32::result_type SimplePcg32::operator()() { // prepare the output value const uint32_t xorshifted = static_cast(((m_state >> 18u) ^ m_state) >> 27u); diff --git a/catch2/src/catch2/internal/catch_reusable_string_stream.cpp b/catch2/src/catch2/internal/catch_reusable_string_stream.cpp index 33eafde..875da4d 100644 --- a/catch2/src/catch2/internal/catch_reusable_string_stream.cpp +++ b/catch2/src/catch2/internal/catch_reusable_string_stream.cpp @@ -7,10 +7,12 @@ // SPDX-License-Identifier: BSL-1.0 #include #include +#include #include #include #include +#include #include namespace Catch { @@ -20,34 +22,40 @@ namespace Catch { std::vector> m_streams; std::vector m_unused; std::ostringstream m_referenceStream; // Used for copy state/ flags from + Detail::Mutex m_mutex; - auto add() -> std::size_t { + auto add() -> std::pair { + Detail::LockGuard _( m_mutex ); if( m_unused.empty() ) { m_streams.push_back( Detail::make_unique() ); - return m_streams.size()-1; + return { m_streams.size()-1, m_streams.back().get() }; } else { auto index = m_unused.back(); m_unused.pop_back(); - return index; + return { index, m_streams[index].get() }; } } - void release( std::size_t index ) { - m_streams[index]->copyfmt( m_referenceStream ); // Restore initial flags and other state - m_unused.push_back(index); + void release( std::size_t index, std::ostream* originalPtr ) { + assert( originalPtr ); + originalPtr->copyfmt( m_referenceStream ); // Restore initial flags and other state + + Detail::LockGuard _( m_mutex ); + assert( originalPtr == m_streams[index].get() && "Mismatch between release index and stream ptr" ); + m_unused.push_back( index ); } }; - ReusableStringStream::ReusableStringStream() - : m_index( Singleton::getMutable().add() ), - m_oss( Singleton::getMutable().m_streams[m_index].get() ) - {} + ReusableStringStream::ReusableStringStream() { + std::tie( m_index, m_oss ) = + Singleton::getMutable().add(); + } ReusableStringStream::~ReusableStringStream() { static_cast( m_oss )->str(""); m_oss->clear(); - Singleton::getMutable().release( m_index ); + Singleton::getMutable().release( m_index, m_oss ); } std::string ReusableStringStream::str() const { diff --git a/catch2/src/catch2/internal/catch_run_context.cpp b/catch2/src/catch2/internal/catch_run_context.cpp index 2a102fb..0029bf5 100644 --- a/catch2/src/catch2/internal/catch_run_context.cpp +++ b/catch2/src/catch2/internal/catch_run_context.cpp @@ -165,23 +165,64 @@ namespace Catch { } // namespace } + namespace Detail { + // Assertions are owned by the thread that is executing them. + // This allows for lock-free progress in common cases where we + // do not need to send the assertion events to the reporter. + // This also implies that messages are owned by their respective + // threads, and should not be shared across different threads. + // + // This implies that various pieces of metadata referring to last + // assertion result/source location/message handling, etc + // should also be thread local. For now we just use naked globals + // below, in the future we will want to allocate piece of memory + // from heap, to avoid consuming too much thread-local storage. + + // This is used for the "if" part of CHECKED_IF/CHECKED_ELSE + static thread_local bool g_lastAssertionPassed = false; + + // This is the source location for last encountered macro. It is + // used to provide the users with more precise location of error + // when an unexpected exception/fatal error happens. + static thread_local SourceLineInfo g_lastKnownLineInfo("DummyLocation", static_cast(-1)); + + // Should we clear message scopes before sending off the messages to + // reporter? Set in `assertionPassedFastPath` to avoid doing the full + // clear there for performance reasons. + static thread_local bool g_clearMessageScopes = false; + + CATCH_INTERNAL_START_WARNINGS_SUPPRESSION + CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS + // Actual messages to be provided to the reporter + static thread_local std::vector g_messages; + + // Owners for the UNSCOPED_X information macro + static thread_local std::vector g_messageScopes; + CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION + + } // namespace Detail + RunContext::RunContext(IConfig const* _config, IEventListenerPtr&& reporter) : m_runInfo(_config->name()), m_config(_config), m_reporter(CATCH_MOVE(reporter)), - m_lastAssertionInfo{ StringRef(), SourceLineInfo("",0), StringRef(), ResultDisposition::Normal }, m_outputRedirect( makeOutputRedirect( m_reporter->getPreferences().shouldRedirectStdOut ) ), - m_includeSuccessfulResults( m_config->includeSuccessfulResults() || m_reporter->getPreferences().shouldReportAllAssertions ) + m_abortAfterXFailedAssertions( m_config->abortAfter() ), + m_reportAssertionStarting( m_reporter->getPreferences().shouldReportAllAssertionStarts ), + m_includeSuccessfulResults( m_config->includeSuccessfulResults() || m_reporter->getPreferences().shouldReportAllAssertions ), + m_shouldDebugBreak( m_config->shouldDebugBreak() ) { getCurrentMutableContext().setResultCapture( this ); m_reporter->testRunStarting(m_runInfo); } RunContext::~RunContext() { + updateTotalsFromAtomics(); m_reporter->testRunEnded(TestRunStats(m_runInfo, m_totals, aborting())); } Totals RunContext::runTest(TestCaseHandle const& testCase) { + updateTotalsFromAtomics(); const Totals prevTotals = m_totals; auto const& testInfo = testCase.getTestCaseInfo(); @@ -236,6 +277,7 @@ namespace Catch { m_reporter->testCasePartialStarting(testInfo, testRuns); + updateTotalsFromAtomics(); const auto beforeRunTotals = m_totals; runCurrentTest(); std::string oneRunCout = m_outputRedirect->getStdout(); @@ -244,6 +286,7 @@ namespace Catch { redirectedCout += oneRunCout; redirectedCerr += oneRunCerr; + updateTotalsFromAtomics(); const auto singleRunTotals = m_totals.delta(beforeRunTotals); auto statsForOneRun = TestCaseStats(testInfo, singleRunTotals, CATCH_MOVE(oneRunCout), CATCH_MOVE(oneRunCerr), aborting()); m_reporter->testCasePartialEnded(statsForOneRun, testRuns); @@ -273,47 +316,54 @@ namespace Catch { void RunContext::assertionEnded(AssertionResult&& result) { + Detail::g_lastKnownLineInfo = result.m_info.lineInfo; if (result.getResultType() == ResultWas::Ok) { - m_totals.assertions.passed++; - m_lastAssertionPassed = true; + m_atomicAssertionCount.passed++; + Detail::g_lastAssertionPassed = true; } else if (result.getResultType() == ResultWas::ExplicitSkip) { - m_totals.assertions.skipped++; - m_lastAssertionPassed = true; + m_atomicAssertionCount.skipped++; + Detail::g_lastAssertionPassed = true; } else if (!result.succeeded()) { - m_lastAssertionPassed = false; + Detail::g_lastAssertionPassed = false; if (result.isOk()) { } - else if( m_activeTestCase->getTestCaseInfo().okToFail() ) - m_totals.assertions.failedButOk++; + else if( m_activeTestCase->getTestCaseInfo().okToFail() ) // Read from a shared state established before the threads could start, this is fine + m_atomicAssertionCount.failedButOk++; else - m_totals.assertions.failed++; + m_atomicAssertionCount.failed++; } else { - m_lastAssertionPassed = true; + Detail::g_lastAssertionPassed = true; + } + + if ( Detail::g_clearMessageScopes ) { + Detail::g_messageScopes.clear(); + Detail::g_clearMessageScopes = false; } + // From here, we are touching shared state and need mutex. + Detail::LockGuard lock( m_assertionMutex ); { auto _ = scopedDeactivate( *m_outputRedirect ); - m_reporter->assertionEnded( AssertionStats( result, m_messages, m_totals ) ); + updateTotalsFromAtomics(); + m_reporter->assertionEnded( AssertionStats( result, Detail::g_messages, m_totals ) ); } if ( result.getResultType() != ResultWas::Warning ) { - m_messageScopes.clear(); + Detail::g_messageScopes.clear(); } // Reset working state. assertion info will be reset after // populateReaction is run if it is needed m_lastResult = CATCH_MOVE( result ); } - void RunContext::resetAssertionInfo() { - m_lastAssertionInfo.macroName = StringRef(); - m_lastAssertionInfo.capturedExpression = "{Unknown expression after the reported line}"_sr; - m_lastAssertionInfo.resultDisposition = ResultDisposition::Normal; - } void RunContext::notifyAssertionStarted( AssertionInfo const& info ) { - auto _ = scopedDeactivate( *m_outputRedirect ); - m_reporter->assertionStarting( info ); + if (m_reportAssertionStarting) { + Detail::LockGuard lock( m_assertionMutex ); + auto _ = scopedDeactivate( *m_outputRedirect ); + m_reporter->assertionStarting( info ); + } } bool RunContext::sectionStarted( StringRef sectionName, @@ -329,13 +379,14 @@ namespace Catch { m_activeSections.push_back(§ionTracker); SectionInfo sectionInfo( sectionLineInfo, static_cast(sectionName) ); - m_lastAssertionInfo.lineInfo = sectionInfo.lineInfo; + Detail::g_lastKnownLineInfo = sectionLineInfo; { auto _ = scopedDeactivate( *m_outputRedirect ); m_reporter->sectionStarting( sectionInfo ); } + updateTotalsFromAtomics(); assertions = m_totals.assertions; return true; @@ -343,12 +394,11 @@ namespace Catch { IGeneratorTracker* RunContext::acquireGeneratorTracker( StringRef generatorName, SourceLineInfo const& lineInfo ) { - using namespace Generators; - GeneratorTracker* tracker = GeneratorTracker::acquire( + auto* tracker = Generators::GeneratorTracker::acquire( m_trackerContext, TestCaseTracking::NameAndLocationRef( generatorName, lineInfo ) ); - m_lastAssertionInfo.lineInfo = lineInfo; + Detail::g_lastKnownLineInfo = lineInfo; return tracker; } @@ -361,7 +411,7 @@ namespace Catch { auto& currentTracker = m_trackerContext.currentTracker(); assert( currentTracker.nameAndLocation() != nameAndLoc && - "Trying to create tracker for a genreator that already has one" ); + "Trying to create tracker for a generator that already has one" ); auto newTracker = Catch::Detail::make_unique( CATCH_MOVE(nameAndLoc), m_trackerContext, ¤tTracker ); @@ -380,12 +430,13 @@ namespace Catch { return false; if (m_trackerContext.currentTracker().hasChildren()) return false; - m_totals.assertions.failed++; + m_atomicAssertionCount.failed++; assertions.failed++; return true; } void RunContext::sectionEnded(SectionEndInfo&& endInfo) { + updateTotalsFromAtomics(); Counts assertions = m_totals.assertions - endInfo.prevAssertions; bool missingAssertions = testForMissingAssertions(assertions); @@ -402,9 +453,6 @@ namespace Catch { endInfo.durationInSeconds, missingAssertions ) ); } - - m_messages.clear(); - m_messageScopes.clear(); } void RunContext::sectionEndedEarly(SectionEndInfo&& endInfo) { @@ -435,18 +483,6 @@ namespace Catch { m_reporter->benchmarkFailed( error ); } - void RunContext::pushScopedMessage(MessageInfo const & message) { - m_messages.push_back(message); - } - - void RunContext::popScopedMessage(MessageInfo const & message) { - m_messages.erase(std::remove(m_messages.begin(), m_messages.end(), message), m_messages.end()); - } - - void RunContext::emplaceUnscopedMessage( MessageBuilder&& builder ) { - m_messageScopes.emplace_back( CATCH_MOVE(builder) ); - } - std::string RunContext::getCurrentTestName() const { return m_activeTestCase ? m_activeTestCase->getTestCaseInfo().name @@ -454,6 +490,18 @@ namespace Catch { } const AssertionResult * RunContext::getLastResult() const { + // m_lastResult is updated inside the assertion slow-path, under + // a mutex, so the read needs to happen under mutex as well. + + // TBD: The last result only makes sense if it is a thread-local + // thing, because the answer is different per thread, like + // last line info, whether last assertion passed, and so on. + // + // However, the last result was also never updated in the + // assertion fast path, so it was always somewhat broken, + // and since IResultCapture::getLastResult is deprecated, + // we will leave it as is, until it is finally removed. + Detail::LockGuard _( m_assertionMutex ); return &(*m_lastResult); } @@ -462,28 +510,44 @@ namespace Catch { } void RunContext::handleFatalErrorCondition( StringRef message ) { - // TODO: scoped deactivate here? Just give up and do best effort? - // the deactivation can break things further, OTOH so can the - // capture - auto _ = scopedDeactivate( *m_outputRedirect ); + // We lock only when touching the reporters directly, to avoid + // deadlocks when we call into other functions that also want + // to lock the mutex before touching reporters. + // + // This does mean that we allow other threads to run while handling + // a fatal error, but this is all a best effort attempt anyway. + { + Detail::LockGuard lock( m_assertionMutex ); + // TODO: scoped deactivate here? Just give up and do best effort? + // the deactivation can break things further, OTOH so can the + // capture + auto _ = scopedDeactivate( *m_outputRedirect ); - // First notify reporter that bad things happened - m_reporter->fatalErrorEncountered( message ); + // First notify reporter that bad things happened + m_reporter->fatalErrorEncountered( message ); + } // Don't rebuild the result -- the stringification itself can cause more fatal errors // Instead, fake a result data. AssertionResultData tempResult( ResultWas::FatalErrorCondition, { false } ); tempResult.message = static_cast(message); - AssertionResult result(m_lastAssertionInfo, CATCH_MOVE(tempResult)); + AssertionResult result( makeDummyAssertionInfo(), + CATCH_MOVE( tempResult ) ); assertionEnded(CATCH_MOVE(result) ); - resetAssertionInfo(); + + + // At this point we touch sections/test cases from this thread + // to try and end them. Technically that is not supported when + // using multiple threads, but the worst thing that can happen + // is that the process aborts harder :-D + Detail::LockGuard lock( m_assertionMutex ); // Best effort cleanup for sections that have not been destructed yet // Since this is a fatal error, we have not had and won't have the opportunity to destruct them properly while (!m_activeSections.empty()) { - auto nl = m_activeSections.back()->nameAndLocation(); - SectionEndInfo endInfo{ SectionInfo(CATCH_MOVE(nl.location), CATCH_MOVE(nl.name)), {}, 0.0 }; + auto const& nl = m_activeSections.back()->nameAndLocation(); + SectionEndInfo endInfo{ SectionInfo(nl.location, nl.name), {}, 0.0 }; sectionEndedEarly(CATCH_MOVE(endInfo)); } handleUnfinishedSections(); @@ -508,32 +572,44 @@ namespace Catch { std::string(), false)); m_totals.testCases.failed++; + updateTotalsFromAtomics(); m_reporter->testRunEnded(TestRunStats(m_runInfo, m_totals, false)); } bool RunContext::lastAssertionPassed() { - return m_lastAssertionPassed; + return Detail::g_lastAssertionPassed; + } + + void RunContext::assertionPassedFastPath(SourceLineInfo lineInfo) { + // We want to save the line info for better experience with unexpected assertions + Detail::g_lastKnownLineInfo = lineInfo; + ++m_atomicAssertionCount.passed; + Detail::g_lastAssertionPassed = true; + Detail::g_clearMessageScopes = true; } - void RunContext::assertionPassed() { - m_lastAssertionPassed = true; - ++m_totals.assertions.passed; - resetAssertionInfo(); - m_messageScopes.clear(); + void RunContext::updateTotalsFromAtomics() { + m_totals.assertions = Counts{ + m_atomicAssertionCount.passed, + m_atomicAssertionCount.failed, + m_atomicAssertionCount.failedButOk, + m_atomicAssertionCount.skipped, + }; } bool RunContext::aborting() const { - return m_totals.assertions.failed >= static_cast(m_config->abortAfter()); + return m_atomicAssertionCount.failed >= m_abortAfterXFailedAssertions; } void RunContext::runCurrentTest() { auto const& testCaseInfo = m_activeTestCase->getTestCaseInfo(); SectionInfo testCaseSection(testCaseInfo.lineInfo, testCaseInfo.name); m_reporter->sectionStarting(testCaseSection); + updateTotalsFromAtomics(); Counts prevAssertions = m_totals.assertions; double duration = 0; m_shouldReportUnexpected = true; - m_lastAssertionInfo = { "TEST_CASE"_sr, testCaseInfo.lineInfo, StringRef(), ResultDisposition::Normal }; + Detail::g_lastKnownLineInfo = testCaseInfo.lineInfo; Timer timer; CATCH_TRY { @@ -550,18 +626,23 @@ namespace Catch { } CATCH_CATCH_ALL { // Under CATCH_CONFIG_FAST_COMPILE, unexpected exceptions under REQUIRE assertions // are reported without translation at the point of origin. - if( m_shouldReportUnexpected ) { + if ( m_shouldReportUnexpected ) { AssertionReaction dummyReaction; - handleUnexpectedInflightException( m_lastAssertionInfo, translateActiveException(), dummyReaction ); + handleUnexpectedInflightException( makeDummyAssertionInfo(), + translateActiveException(), + dummyReaction ); } } + updateTotalsFromAtomics(); Counts assertions = m_totals.assertions - prevAssertions; bool missingAssertions = testForMissingAssertions(assertions); m_testCaseTracker->close(); handleUnfinishedSections(); - m_messages.clear(); - m_messageScopes.clear(); + Detail::g_messageScopes.clear(); + // TBD: At this point, m_messages should be empty. Do we want to + // assert that this is true, or keep the defensive clear call? + Detail::g_messages.clear(); SectionStats testCaseSectionStats(CATCH_MOVE(testCaseSection), assertions, duration, missingAssertions); m_reporter->sectionEnded(testCaseSectionStats); @@ -602,7 +683,7 @@ namespace Catch { if( result ) { if (!m_includeSuccessfulResults) { - assertionPassed(); + assertionPassedFastPath(info.lineInfo); } else { reportExpr(info, ResultWas::Ok, &expr, negated); @@ -610,9 +691,9 @@ namespace Catch { } else { reportExpr(info, ResultWas::ExpressionFailed, &expr, negated ); - populateReaction( reaction ); + populateReaction( + reaction, info.resultDisposition & ResultDisposition::Normal ); } - resetAssertionInfo(); } void RunContext::reportExpr( AssertionInfo const &info, @@ -620,7 +701,7 @@ namespace Catch { ITransientExpression const *expr, bool negated ) { - m_lastAssertionInfo = info; + Detail::g_lastKnownLineInfo = info.lineInfo; AssertionResultData data( resultType, LazyExpression( negated ) ); AssertionResult assertionResult{ info, CATCH_MOVE( data ) }; @@ -635,24 +716,25 @@ namespace Catch { std::string&& message, AssertionReaction& reaction ) { - m_lastAssertionInfo = info; + Detail::g_lastKnownLineInfo = info.lineInfo; AssertionResultData data( resultType, LazyExpression( false ) ); data.message = CATCH_MOVE( message ); - AssertionResult assertionResult{ m_lastAssertionInfo, + AssertionResult assertionResult{ info, CATCH_MOVE( data ) }; const auto isOk = assertionResult.isOk(); assertionEnded( CATCH_MOVE(assertionResult) ); if ( !isOk ) { - populateReaction( reaction ); + populateReaction( + reaction, info.resultDisposition & ResultDisposition::Normal ); } else if ( resultType == ResultWas::ExplicitSkip ) { // TODO: Need to handle this explicitly, as ExplicitSkip is // considered "OK" reaction.shouldSkip = true; } - resetAssertionInfo(); } + void RunContext::handleUnexpectedExceptionNotThrown( AssertionInfo const& info, AssertionReaction& reaction @@ -665,55 +747,88 @@ namespace Catch { std::string&& message, AssertionReaction& reaction ) { - m_lastAssertionInfo = info; + Detail::g_lastKnownLineInfo = info.lineInfo; AssertionResultData data( ResultWas::ThrewException, LazyExpression( false ) ); data.message = CATCH_MOVE(message); AssertionResult assertionResult{ info, CATCH_MOVE(data) }; assertionEnded( CATCH_MOVE(assertionResult) ); - populateReaction( reaction ); - resetAssertionInfo(); + populateReaction( reaction, + info.resultDisposition & ResultDisposition::Normal ); + } + + void RunContext::populateReaction( AssertionReaction& reaction, + bool has_normal_disposition ) { + reaction.shouldDebugBreak = m_shouldDebugBreak; + reaction.shouldThrow = aborting() || has_normal_disposition; } - void RunContext::populateReaction( AssertionReaction& reaction ) { - reaction.shouldDebugBreak = m_config->shouldDebugBreak(); - reaction.shouldThrow = aborting() || (m_lastAssertionInfo.resultDisposition & ResultDisposition::Normal); + AssertionInfo RunContext::makeDummyAssertionInfo() { + const bool testCaseJustStarted = + Detail::g_lastKnownLineInfo == + m_activeTestCase->getTestCaseInfo().lineInfo; + + return AssertionInfo{ + testCaseJustStarted ? "TEST_CASE"_sr : StringRef(), + Detail::g_lastKnownLineInfo, + testCaseJustStarted ? StringRef() : "{Unknown expression after the reported line}"_sr, + ResultDisposition::Normal + }; } void RunContext::handleIncomplete( AssertionInfo const& info ) { using namespace std::string_literals; - m_lastAssertionInfo = info; + Detail::g_lastKnownLineInfo = info.lineInfo; AssertionResultData data( ResultWas::ThrewException, LazyExpression( false ) ); data.message = "Exception translation was disabled by CATCH_CONFIG_FAST_COMPILE"s; AssertionResult assertionResult{ info, CATCH_MOVE( data ) }; assertionEnded( CATCH_MOVE(assertionResult) ); - resetAssertionInfo(); } + void RunContext::handleNonExpr( AssertionInfo const &info, ResultWas::OfType resultType, AssertionReaction &reaction ) { - m_lastAssertionInfo = info; - AssertionResultData data( resultType, LazyExpression( false ) ); AssertionResult assertionResult{ info, CATCH_MOVE( data ) }; const auto isOk = assertionResult.isOk(); + if ( isOk && !m_includeSuccessfulResults ) { + assertionPassedFastPath( info.lineInfo ); + return; + } + assertionEnded( CATCH_MOVE(assertionResult) ); - if ( !isOk ) { populateReaction( reaction ); } - resetAssertionInfo(); + if ( !isOk ) { + populateReaction( + reaction, info.resultDisposition & ResultDisposition::Normal ); + } } + void IResultCapture::pushScopedMessage( MessageInfo&& message ) { + Detail::g_messages.push_back( CATCH_MOVE( message ) ); + } + + void IResultCapture::popScopedMessage( unsigned int messageId ) { + // Note: On average, it would probably be better to look for the message + // backwards. However, we do not expect to have to deal with more + // messages than low single digits, so the optimization is tiny, + // and we would have to hand-write the loop to avoid terrible + // codegen of reverse iterators in debug mode. + Detail::g_messages.erase( std::find_if( Detail::g_messages.begin(), + Detail::g_messages.end(), + [=]( MessageInfo const& msg ) { + return msg.sequence == + messageId; + } ) ); + } - IResultCapture& getResultCapture() { - if (auto* capture = getCurrentContext().getResultCapture()) - return *capture; - else - CATCH_INTERNAL_ERROR("No result capture instance"); + void IResultCapture::emplaceUnscopedMessage( MessageBuilder&& builder ) { + Detail::g_messageScopes.emplace_back( CATCH_MOVE( builder ) ); } void seedRng(IConfig const& config) { diff --git a/catch2/src/catch2/internal/catch_run_context.hpp b/catch2/src/catch2/internal/catch_run_context.hpp index c66fec0..dee851e 100644 --- a/catch2/src/catch2/internal/catch_run_context.hpp +++ b/catch2/src/catch2/internal/catch_run_context.hpp @@ -10,7 +10,7 @@ #include #include -#include +#include #include #include #include @@ -20,6 +20,7 @@ #include #include #include +#include #include @@ -93,11 +94,6 @@ namespace Catch { void benchmarkEnded( BenchmarkStats<> const& stats ) override; void benchmarkFailed( StringRef error ) override; - void pushScopedMessage( MessageInfo const& message ) override; - void popScopedMessage( MessageInfo const& message ) override; - - void emplaceUnscopedMessage( MessageBuilder&& builder ) override; - std::string getCurrentTestName() const override; const AssertionResult* getLastResult() const override; @@ -108,18 +104,18 @@ namespace Catch { bool lastAssertionPassed() override; - void assertionPassed() override; - public: // !TBD We need to do this another way! bool aborting() const; private: + void assertionPassedFastPath( SourceLineInfo lineInfo ); + // Update the non-thread-safe m_totals from the atomic assertion counts. + void updateTotalsFromAtomics(); void runCurrentTest(); void invokeActiveTestCase(); - void resetAssertionInfo(); bool testForMissingAssertions( Counts& assertions ); void assertionEnded( AssertionResult&& result ); @@ -129,31 +125,39 @@ namespace Catch { ITransientExpression const *expr, bool negated ); - void populateReaction( AssertionReaction& reaction ); + void populateReaction( AssertionReaction& reaction, bool has_normal_disposition ); + + // Creates dummy info for unexpected exceptions/fatal errors, + // where we do not have the access to one, but we still need + // to send one to the reporters. + AssertionInfo makeDummyAssertionInfo(); private: void handleUnfinishedSections(); - + mutable Detail::Mutex m_assertionMutex; TestRunInfo m_runInfo; TestCaseHandle const* m_activeTestCase = nullptr; ITracker* m_testCaseTracker = nullptr; Optional m_lastResult; - IConfig const* m_config; Totals m_totals; + Detail::AtomicCounts m_atomicAssertionCount; IEventListenerPtr m_reporter; - std::vector m_messages; - std::vector m_messageScopes; /* Keeps owners of so-called unscoped messages. */ - AssertionInfo m_lastAssertionInfo; std::vector m_unfinishedSections; std::vector m_activeSections; TrackerContext m_trackerContext; Detail::unique_ptr m_outputRedirect; FatalConditionHandler m_fatalConditionhandler; - bool m_lastAssertionPassed = false; + // Caches m_config->abortAfter() to avoid vptr calls/allow inlining + size_t m_abortAfterXFailedAssertions; bool m_shouldReportUnexpected = true; + // Caches whether `assertionStarting` events should be sent to the reporter. + bool m_reportAssertionStarting; + // Caches whether `assertionEnded` events for successful assertions should be sent to the reporter bool m_includeSuccessfulResults; + // Caches m_config->shouldDebugBreak() to avoid vptr calls/allow inlining + bool m_shouldDebugBreak; }; void seedRng(IConfig const& config); diff --git a/catch2/src/catch2/internal/catch_section.hpp b/catch2/src/catch2/internal/catch_section.hpp index e56c79f..b99a4c9 100644 --- a/catch2/src/catch2/internal/catch_section.hpp +++ b/catch2/src/catch2/internal/catch_section.hpp @@ -62,7 +62,7 @@ namespace Catch { #else // These section definitions imply that at most one section at one level -// will be intered (because only one section's __LINE__ can be equal to +// will be entered (because only one section's __LINE__ can be equal to // the dummy `catchInternalSectionHint` variable from `TEST_CASE`). namespace Catch { diff --git a/catch2/src/catch2/internal/catch_sharding.hpp b/catch2/src/catch2/internal/catch_sharding.hpp index 22561f4..4d7ee26 100644 --- a/catch2/src/catch2/internal/catch_sharding.hpp +++ b/catch2/src/catch2/internal/catch_sharding.hpp @@ -9,7 +9,6 @@ #define CATCH_SHARDING_HPP_INCLUDED #include -#include #include namespace Catch { diff --git a/catch2/src/catch2/internal/catch_string_manip.cpp b/catch2/src/catch2/internal/catch_string_manip.cpp index ce1abaa..6898378 100644 --- a/catch2/src/catch2/internal/catch_string_manip.cpp +++ b/catch2/src/catch2/internal/catch_string_manip.cpp @@ -74,7 +74,7 @@ namespace Catch { std::string origStr = CATCH_MOVE(str); str.clear(); // There is at least one replacement, so reserve with the best guess - // we can make without actually counting the number of occurences. + // we can make without actually counting the number of occurrences. str.reserve(origStr.size() - replaceThis.size() + withThis.size()); do { str.append(origStr, copyBegin, i-copyBegin ); diff --git a/catch2/src/catch2/internal/catch_stringref.cpp b/catch2/src/catch2/internal/catch_stringref.cpp index 232498e..5b59354 100644 --- a/catch2/src/catch2/internal/catch_stringref.cpp +++ b/catch2/src/catch2/internal/catch_stringref.cpp @@ -10,7 +10,6 @@ #include #include #include -#include namespace Catch { StringRef::StringRef( char const* rawChars ) noexcept diff --git a/catch2/src/catch2/internal/catch_template_test_registry.hpp b/catch2/src/catch2/internal/catch_template_test_registry.hpp index 0ea354b..7aec888 100644 --- a/catch2/src/catch2/internal/catch_template_test_registry.hpp +++ b/catch2/src/catch2/internal/catch_template_test_registry.hpp @@ -135,11 +135,11 @@ constexpr char const* tmpl_types[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TmplTypes))};\ constexpr char const* types_list[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TypesList))};\ constexpr auto num_types = sizeof(types_list) / sizeof(types_list[0]);\ - (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestFuncName ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index / num_types]) + '<' + std::string(types_list[index % num_types]) + '>', Tags } ), index++)... };/* NOLINT */\ + (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestFuncName ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index / num_types]) + '<' + types_list[index % num_types] + '>', Tags } ), index++)... };/* NOLINT */\ } \ }; \ - static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){ \ - using TestInit = typename create()), TypeList>::type; \ + static const int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){ \ + using TestInit = typename create(Catch::Detail::priority_tag<1>{})), TypeList>::type; \ TestInit t; \ t.reg_tests(); \ return 0; \ @@ -184,7 +184,7 @@ (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestFunc ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ Name " - " INTERNAL_CATCH_STRINGIZE(TmplList) " - " + std::to_string(index), Tags } ), index++)... };/* NOLINT */\ } \ };\ - static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){ \ + static const int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){ \ using TestInit = typename convert::type; \ TestInit t; \ t.reg_tests(); \ @@ -220,7 +220,7 @@ (void)expander{(reg_test(Types{}, #ClassName, Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index]), Tags } ), index++)... };/* NOLINT */ \ }\ };\ - static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\ + static const int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\ TestNameClass();\ return 0;\ }();\ @@ -267,11 +267,11 @@ constexpr char const* tmpl_types[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TmplTypes))};\ constexpr char const* types_list[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TypesList))};\ constexpr auto num_types = sizeof(types_list) / sizeof(types_list[0]);\ - (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestName::test ), CATCH_INTERNAL_LINEINFO, #ClassName, Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index / num_types]) + '<' + std::string(types_list[index % num_types]) + '>', Tags } ), index++)... };/* NOLINT */ \ + (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestName::test ), CATCH_INTERNAL_LINEINFO, #ClassName, Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index / num_types]) + '<' + types_list[index % num_types] + '>', Tags } ), index++)... };/* NOLINT */ \ }\ };\ - static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\ - using TestInit = typename create()), TypeList>::type;\ + static const int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\ + using TestInit = typename create(Catch::Detail::priority_tag<1>{})), TypeList>::type;\ TestInit t;\ t.reg_tests();\ return 0;\ @@ -319,7 +319,7 @@ (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestName::test ), CATCH_INTERNAL_LINEINFO, #ClassName##_catch_sr, Catch::NameAndTags{ Name " - " INTERNAL_CATCH_STRINGIZE(TmplList) " - " + std::to_string(index), Tags } ), index++)... };/* NOLINT */ \ }\ };\ - static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\ + static const int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\ using TestInit = typename convert::type;\ TestInit t;\ t.reg_tests();\ diff --git a/catch2/src/catch2/internal/catch_thread_support.hpp b/catch2/src/catch2/internal/catch_thread_support.hpp new file mode 100644 index 0000000..c15980b --- /dev/null +++ b/catch2/src/catch2/internal/catch_thread_support.hpp @@ -0,0 +1,49 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 +#ifndef CATCH_THREAD_SUPPORT_HPP_INCLUDED +#define CATCH_THREAD_SUPPORT_HPP_INCLUDED + +#include + +#if defined( CATCH_CONFIG_EXPERIMENTAL_THREAD_SAFE_ASSERTIONS ) +# include +# include +#endif + +#include + +namespace Catch { + namespace Detail { +#if defined( CATCH_CONFIG_EXPERIMENTAL_THREAD_SAFE_ASSERTIONS ) + using Mutex = std::mutex; + using LockGuard = std::lock_guard; + struct AtomicCounts { + std::atomic passed = 0; + std::atomic failed = 0; + std::atomic failedButOk = 0; + std::atomic skipped = 0; + }; +#else // ^^ Use actual mutex, lock and atomics + // vv Dummy implementations for single-thread performance + + struct Mutex { + void lock() {} + void unlock() {} + }; + + struct LockGuard { + LockGuard( Mutex ) {} + }; + + using AtomicCounts = Counts; +#endif + + } // namespace Detail +} // namespace Catch + +#endif // CATCH_THREAD_SUPPORT_HPP_INCLUDED diff --git a/catch2/src/catch2/internal/catch_unique_ptr.hpp b/catch2/src/catch2/internal/catch_unique_ptr.hpp index 49cbc78..8add2a8 100644 --- a/catch2/src/catch2/internal/catch_unique_ptr.hpp +++ b/catch2/src/catch2/internal/catch_unique_ptr.hpp @@ -92,7 +92,7 @@ namespace Detail { } explicit operator bool() const { - return m_ptr; + return m_ptr != nullptr; } friend void swap(unique_ptr& lhs, unique_ptr& rhs) { diff --git a/catch2/src/catch2/internal/catch_unreachable.hpp b/catch2/src/catch2/internal/catch_unreachable.hpp new file mode 100644 index 0000000..fc3f75b --- /dev/null +++ b/catch2/src/catch2/internal/catch_unreachable.hpp @@ -0,0 +1,56 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 +#ifndef CATCH_UNREACHABLE_HPP_INCLUDED +#define CATCH_UNREACHABLE_HPP_INCLUDED + +/**\file + * Polyfill `std::unreachable` + * + * We need something like `std::unreachable` to tell the compiler that + * some macros, e.g. `FAIL` or `SKIP`, do not continue execution in normal + * manner, and should handle it as such, e.g. not warn if there is no return + * from non-void function after a `FAIL` or `SKIP`. + */ + +#include + +#if defined( __cpp_lib_unreachable ) && __cpp_lib_unreachable > 202202L +# include +namespace Catch { + namespace Detail { + using Unreachable = std::unreachable; + } +} // namespace Catch + +#else // vv If we do not have std::unreachable, we implement something similar + +namespace Catch { + namespace Detail { + + [[noreturn]] + inline void Unreachable() noexcept { +# if defined( NDEBUG ) +# if defined( _MSC_VER ) && !defined( __clang__ ) + __assume( false ); +# elif defined( __GNUC__ ) + __builtin_unreachable(); +# else // vv platform without known optimization hint + std::terminate(); +# endif +# else // ^^ NDEBUG + // For non-release builds, we prefer termination on bug over UB + std::terminate(); +# endif // + } + + } // namespace Detail +} // end namespace Catch + +#endif + +#endif // CATCH_UNREACHABLE_HPP_INCLUDED diff --git a/catch2/src/catch2/internal/catch_xmlwriter.cpp b/catch2/src/catch2/internal/catch_xmlwriter.cpp index ccf63a5..67126be 100644 --- a/catch2/src/catch2/internal/catch_xmlwriter.cpp +++ b/catch2/src/catch2/internal/catch_xmlwriter.cpp @@ -47,7 +47,7 @@ namespace { void hexEscapeChar(std::ostream& os, unsigned char c) { std::ios_base::fmtflags f(os.flags()); - os << "\\x" + os << "\\x"_sr << std::uppercase << std::hex << std::setfill('0') << std::setw(2) << static_cast(c); os.flags(f); @@ -66,95 +66,111 @@ namespace { void XmlEncode::encodeTo( std::ostream& os ) const { // Apostrophe escaping not necessary if we always use " to write attributes // (see: http://www.w3.org/TR/xml/#syntax) - - for( std::size_t idx = 0; idx < m_str.size(); ++ idx ) { - unsigned char c = static_cast(m_str[idx]); - switch (c) { - case '<': os << "<"; break; - case '&': os << "&"; break; + size_t last_start = 0; + auto write_to = [&]( size_t idx ) { + if ( last_start < idx ) { + os << m_str.substr( last_start, idx - last_start ); + } + last_start = idx + 1; + }; + + for ( std::size_t idx = 0; idx < m_str.size(); ++idx ) { + unsigned char c = static_cast( m_str[idx] ); + switch ( c ) { + case '<': + write_to( idx ); + os << "<"_sr; + break; + case '&': + write_to( idx ); + os << "&"_sr; + break; case '>': // See: http://www.w3.org/TR/xml/#syntax - if (idx > 2 && m_str[idx - 1] == ']' && m_str[idx - 2] == ']') - os << ">"; - else - os << c; + if ( idx > 2 && m_str[idx - 1] == ']' && m_str[idx - 2] == ']' ) { + write_to( idx ); + os << ">"_sr; + } break; case '\"': - if (m_forWhat == ForAttributes) - os << """; - else - os << c; + if ( m_forWhat == ForAttributes ) { + write_to( idx ); + os << """_sr; + } break; default: // Check for control characters and invalid utf-8 // Escape control characters in standard ascii - // see http://stackoverflow.com/questions/404107/why-are-control-characters-illegal-in-xml-1-0 - if (c < 0x09 || (c > 0x0D && c < 0x20) || c == 0x7F) { - hexEscapeChar(os, c); + // see + // http://stackoverflow.com/questions/404107/why-are-control-characters-illegal-in-xml-1-0 + if ( c < 0x09 || ( c > 0x0D && c < 0x20 ) || c == 0x7F ) { + write_to( idx ); + hexEscapeChar( os, c ); break; } // Plain ASCII: Write it to stream - if (c < 0x7F) { - os << c; + if ( c < 0x7F ) { break; } // UTF-8 territory - // Check if the encoding is valid and if it is not, hex escape bytes. - // Important: We do not check the exact decoded values for validity, only the encoding format - // First check that this bytes is a valid lead byte: - // This means that it is not encoded as 1111 1XXX + // Check if the encoding is valid and if it is not, hex escape + // bytes. Important: We do not check the exact decoded values for + // validity, only the encoding format First check that this bytes is + // a valid lead byte: This means that it is not encoded as 1111 1XXX // Or as 10XX XXXX - if (c < 0xC0 || - c >= 0xF8) { - hexEscapeChar(os, c); + if ( c < 0xC0 || c >= 0xF8 ) { + write_to( idx ); + hexEscapeChar( os, c ); break; } - auto encBytes = trailingBytes(c); - // Are there enough bytes left to avoid accessing out-of-bounds memory? - if (idx + encBytes - 1 >= m_str.size()) { - hexEscapeChar(os, c); + auto encBytes = trailingBytes( c ); + // Are there enough bytes left to avoid accessing out-of-bounds + // memory? + if ( idx + encBytes - 1 >= m_str.size() ) { + write_to( idx ); + hexEscapeChar( os, c ); break; } // The header is valid, check data // The next encBytes bytes must together be a valid utf-8 - // This means: bitpattern 10XX XXXX and the extracted value is sane (ish) + // This means: bitpattern 10XX XXXX and the extracted value is sane + // (ish) bool valid = true; - uint32_t value = headerValue(c); - for (std::size_t n = 1; n < encBytes; ++n) { - unsigned char nc = static_cast(m_str[idx + n]); - valid &= ((nc & 0xC0) == 0x80); - value = (value << 6) | (nc & 0x3F); + uint32_t value = headerValue( c ); + for ( std::size_t n = 1; n < encBytes; ++n ) { + unsigned char nc = static_cast( m_str[idx + n] ); + valid &= ( ( nc & 0xC0 ) == 0x80 ); + value = ( value << 6 ) | ( nc & 0x3F ); } if ( // Wrong bit pattern of following bytes - (!valid) || + ( !valid ) || // Overlong encodings - (value < 0x80) || - (0x80 <= value && value < 0x800 && encBytes > 2) || - (0x800 < value && value < 0x10000 && encBytes > 3) || + ( value < 0x80 ) || + ( 0x80 <= value && value < 0x800 && encBytes > 2 ) || + ( 0x800 < value && value < 0x10000 && encBytes > 3 ) || // Encoded value out of range - (value >= 0x110000) - ) { - hexEscapeChar(os, c); + ( value >= 0x110000 ) ) { + write_to( idx ); + hexEscapeChar( os, c ); break; } // If we got here, this is in fact a valid(ish) utf-8 sequence - for (std::size_t n = 0; n < encBytes; ++n) { - os << m_str[idx + n]; - } idx += encBytes - 1; break; } } + + write_to( m_str.size() ); } std::ostream& operator << ( std::ostream& os, XmlEncode const& xmlEncode ) { diff --git a/catch2/src/catch2/matchers/catch_matchers_container_properties.hpp b/catch2/src/catch2/matchers/catch_matchers_container_properties.hpp index 5f3fc7f..33795fb 100644 --- a/catch2/src/catch2/matchers/catch_matchers_container_properties.hpp +++ b/catch2/src/catch2/matchers/catch_matchers_container_properties.hpp @@ -79,7 +79,7 @@ namespace Catch { //! Creates a matcher that accepts ranges/containers with specific size HasSizeMatcher SizeIs(std::size_t sz); template - std::enable_if_t::value, + std::enable_if_t, SizeMatchesMatcher> SizeIs(Matcher&& m) { return SizeMatchesMatcher{CATCH_FORWARD(m)}; } diff --git a/catch2/src/catch2/matchers/catch_matchers_contains.hpp b/catch2/src/catch2/matchers/catch_matchers_contains.hpp index 877d692..90cfe64 100644 --- a/catch2/src/catch2/matchers/catch_matchers_contains.hpp +++ b/catch2/src/catch2/matchers/catch_matchers_contains.hpp @@ -11,8 +11,8 @@ #include #include -#include #include +#include namespace Catch { namespace Matchers { @@ -74,14 +74,14 @@ namespace Catch { * Uses `std::equal_to` to do the comparison */ template - std::enable_if_t::value, + std::enable_if_t, ContainsElementMatcher>> Contains(T&& elem) { return { CATCH_FORWARD(elem), std::equal_to<>{} }; } //! Creates a matcher that checks whether a range contains element matching a matcher template - std::enable_if_t::value, + std::enable_if_t, ContainsMatcherMatcher> Contains(Matcher&& matcher) { return { CATCH_FORWARD(matcher) }; } diff --git a/catch2/src/catch2/matchers/catch_matchers_range_equals.hpp b/catch2/src/catch2/matchers/catch_matchers_range_equals.hpp index 8130f60..11a1f2f 100644 --- a/catch2/src/catch2/matchers/catch_matchers_range_equals.hpp +++ b/catch2/src/catch2/matchers/catch_matchers_range_equals.hpp @@ -11,8 +11,7 @@ #include #include -#include -#include +#include namespace Catch { namespace Matchers { diff --git a/catch2/src/catch2/matchers/catch_matchers_templated.hpp b/catch2/src/catch2/matchers/catch_matchers_templated.hpp index ba0661a..fc9fcb2 100644 --- a/catch2/src/catch2/matchers/catch_matchers_templated.hpp +++ b/catch2/src/catch2/matchers/catch_matchers_templated.hpp @@ -58,19 +58,19 @@ namespace Matchers { } template - using is_generic_matcher = std::is_base_of< + static constexpr bool is_generic_matcher_v = std::is_base_of< Catch::Matchers::MatcherGenericBase, std::remove_cv_t> - >; + >::value; template - using are_generic_matchers = Catch::Detail::conjunction...>; + static constexpr bool are_generic_matchers_v = Catch::Detail::conjunction>...>::value; template - using is_matcher = std::is_base_of< + static constexpr bool is_matcher_v = std::is_base_of< Catch::Matchers::MatcherUntypedBase, std::remove_cv_t> - >; + >::value; template @@ -143,7 +143,7 @@ namespace Matchers { //! Avoids type nesting for `GenericAllOf && some matcher` case template - friend std::enable_if_t::value, + friend std::enable_if_t, MatchAllOfGeneric> operator && ( MatchAllOfGeneric&& lhs, MatcherRHS const& rhs) { @@ -152,7 +152,7 @@ namespace Matchers { //! Avoids type nesting for `some matcher && GenericAllOf` case template - friend std::enable_if_t::value, + friend std::enable_if_t, MatchAllOfGeneric> operator && ( MatcherLHS const& lhs, MatchAllOfGeneric&& rhs) { @@ -197,7 +197,7 @@ namespace Matchers { //! Avoids type nesting for `GenericAnyOf || some matcher` case template - friend std::enable_if_t::value, + friend std::enable_if_t, MatchAnyOfGeneric> operator || ( MatchAnyOfGeneric&& lhs, MatcherRHS const& rhs) { @@ -206,7 +206,7 @@ namespace Matchers { //! Avoids type nesting for `some matcher || GenericAnyOf` case template - friend std::enable_if_t::value, + friend std::enable_if_t, MatchAnyOfGeneric> operator || ( MatcherLHS const& lhs, MatchAnyOfGeneric&& rhs) { @@ -246,20 +246,20 @@ namespace Matchers { // compose only generic matchers template - std::enable_if_t::value, Detail::MatchAllOfGeneric> + std::enable_if_t, Detail::MatchAllOfGeneric> operator && (MatcherLHS const& lhs, MatcherRHS const& rhs) { return { lhs, rhs }; } template - std::enable_if_t::value, Detail::MatchAnyOfGeneric> + std::enable_if_t, Detail::MatchAnyOfGeneric> operator || (MatcherLHS const& lhs, MatcherRHS const& rhs) { return { lhs, rhs }; } //! Wrap provided generic matcher in generic negator template - std::enable_if_t::value, Detail::MatchNotOfGeneric> + std::enable_if_t, Detail::MatchNotOfGeneric> operator ! (MatcherT const& matcher) { return Detail::MatchNotOfGeneric{matcher}; } @@ -267,25 +267,25 @@ namespace Matchers { // compose mixed generic and non-generic matchers template - std::enable_if_t::value, Detail::MatchAllOfGeneric>> + std::enable_if_t, Detail::MatchAllOfGeneric>> operator && (MatcherLHS const& lhs, MatcherBase const& rhs) { return { lhs, rhs }; } template - std::enable_if_t::value, Detail::MatchAllOfGeneric, MatcherRHS>> + std::enable_if_t, Detail::MatchAllOfGeneric, MatcherRHS>> operator && (MatcherBase const& lhs, MatcherRHS const& rhs) { return { lhs, rhs }; } template - std::enable_if_t::value, Detail::MatchAnyOfGeneric>> + std::enable_if_t, Detail::MatchAnyOfGeneric>> operator || (MatcherLHS const& lhs, MatcherBase const& rhs) { return { lhs, rhs }; } template - std::enable_if_t::value, Detail::MatchAnyOfGeneric, MatcherRHS>> + std::enable_if_t, Detail::MatchAnyOfGeneric, MatcherRHS>> operator || (MatcherBase const& lhs, MatcherRHS const& rhs) { return { lhs, rhs }; } diff --git a/catch2/src/catch2/meson.build b/catch2/src/catch2/meson.build index 2eb5399..60f7777 100644 --- a/catch2/src/catch2/meson.build +++ b/catch2/src/catch2/meson.build @@ -92,6 +92,7 @@ internal_headers = [ 'internal/catch_debug_console.hpp', 'internal/catch_debugger.hpp', 'internal/catch_decomposer.hpp', + 'internal/catch_deprecation_macro.hpp', 'internal/catch_enforce.hpp', 'internal/catch_enum_values_registry.hpp', 'internal/catch_errno_guard.hpp', @@ -144,15 +145,16 @@ internal_headers = [ 'internal/catch_test_failure_exception.hpp', 'internal/catch_test_macro_impl.hpp', 'internal/catch_test_registry.hpp', - 'internal/catch_test_run_info.hpp', 'internal/catch_test_spec_parser.hpp', 'internal/catch_textflow.hpp', + 'internal/catch_thread_support.hpp', 'internal/catch_to_string.hpp', 'internal/catch_uncaught_exceptions.hpp', 'internal/catch_uniform_floating_point_distribution.hpp', 'internal/catch_uniform_integer_distribution.hpp', 'internal/catch_unique_name.hpp', 'internal/catch_unique_ptr.hpp', + 'internal/catch_unreachable.hpp', 'internal/catch_void_type.hpp', 'internal/catch_wildcard_pattern.hpp', 'internal/catch_windows_h_proxy.hpp', @@ -185,6 +187,7 @@ internal_headers = [ 'catch_template_test_macros.hpp', 'catch_test_case_info.hpp', 'catch_test_macros.hpp', + 'catch_test_run_info.hpp', 'catch_test_spec.hpp', 'catch_timer.hpp', 'catch_tostring.hpp', diff --git a/catch2/src/catch2/reporters/catch_reporter_automake.hpp b/catch2/src/catch2/reporters/catch_reporter_automake.hpp index a639428..d920adf 100644 --- a/catch2/src/catch2/reporters/catch_reporter_automake.hpp +++ b/catch2/src/catch2/reporters/catch_reporter_automake.hpp @@ -19,9 +19,11 @@ namespace Catch { public: // GCC5 compat: we cannot use inherited constructor, because it // doesn't implement backport of P0136 - AutomakeReporter(ReporterConfig&& _config): - StreamingReporterBase(CATCH_MOVE(_config)) - {} + AutomakeReporter( ReporterConfig&& _config ): + StreamingReporterBase( CATCH_MOVE( _config ) ) { + m_preferences.shouldReportAllAssertionStarts = false; + } + ~AutomakeReporter() override; static std::string getDescription() { diff --git a/catch2/src/catch2/reporters/catch_reporter_compact.cpp b/catch2/src/catch2/reporters/catch_reporter_compact.cpp index 0f85594..6d2c865 100644 --- a/catch2/src/catch2/reporters/catch_reporter_compact.cpp +++ b/catch2/src/catch2/reporters/catch_reporter_compact.cpp @@ -215,7 +215,8 @@ class AssertionPrinter { << m_config->testSpec() << '\n'; } - m_stream << "RNG seed: " << getSeed() << '\n'; + m_stream << "RNG seed: " << getSeed() << '\n' + << std::flush; } void CompactReporter::assertionEnded( AssertionStats const& _assertionStats ) { diff --git a/catch2/src/catch2/reporters/catch_reporter_compact.hpp b/catch2/src/catch2/reporters/catch_reporter_compact.hpp index d95bbff..a6437c6 100644 --- a/catch2/src/catch2/reporters/catch_reporter_compact.hpp +++ b/catch2/src/catch2/reporters/catch_reporter_compact.hpp @@ -16,7 +16,10 @@ namespace Catch { class CompactReporter final : public StreamingReporterBase { public: - using StreamingReporterBase::StreamingReporterBase; + CompactReporter( ReporterConfig&& _config ): + StreamingReporterBase( CATCH_MOVE( _config ) ) { + m_preferences.shouldReportAllAssertionStarts = false; + } ~CompactReporter() override; diff --git a/catch2/src/catch2/reporters/catch_reporter_console.cpp b/catch2/src/catch2/reporters/catch_reporter_console.cpp index 9529f39..acb4ae8 100644 --- a/catch2/src/catch2/reporters/catch_reporter_console.cpp +++ b/catch2/src/catch2/reporters/catch_reporter_console.cpp @@ -401,7 +401,10 @@ ConsoleReporter::ConsoleReporter(ReporterConfig&& config): { "est run time high mean high std dev", 14, Justification::Right } }; } - }())) {} + }())) { + m_preferences.shouldReportAllAssertionStarts = false; +} + ConsoleReporter::~ConsoleReporter() = default; std::string ConsoleReporter::getDescription() { @@ -416,8 +419,6 @@ void ConsoleReporter::reportInvalidTestSpec( StringRef arg ) { m_stream << "Invalid Filter: " << arg << '\n'; } -void ConsoleReporter::assertionStarting(AssertionInfo const&) {} - void ConsoleReporter::assertionEnded(AssertionStats const& _assertionStats) { AssertionResult const& result = _assertionStats.assertionResult; @@ -529,7 +530,8 @@ void ConsoleReporter::testRunStarting(TestRunInfo const& _testRunInfo) { m_stream << m_colour->guardColour( Colour::BrightYellow ) << "Filters: " << m_config->testSpec() << '\n'; } - m_stream << "Randomness seeded to: " << getSeed() << '\n'; + m_stream << "Randomness seeded to: " << getSeed() << '\n' + << std::flush; } void ConsoleReporter::lazyPrint() { diff --git a/catch2/src/catch2/reporters/catch_reporter_console.hpp b/catch2/src/catch2/reporters/catch_reporter_console.hpp index 2437726..86ecf43 100644 --- a/catch2/src/catch2/reporters/catch_reporter_console.hpp +++ b/catch2/src/catch2/reporters/catch_reporter_console.hpp @@ -26,8 +26,6 @@ namespace Catch { void noMatchingTestCases( StringRef unmatchedSpec ) override; void reportInvalidTestSpec( StringRef arg ) override; - void assertionStarting(AssertionInfo const&) override; - void assertionEnded(AssertionStats const& _assertionStats) override; void sectionStarting(SectionInfo const& _sectionInfo) override; diff --git a/catch2/src/catch2/reporters/catch_reporter_helpers.cpp b/catch2/src/catch2/reporters/catch_reporter_helpers.cpp index ffb32ff..c710ac4 100644 --- a/catch2/src/catch2/reporters/catch_reporter_helpers.cpp +++ b/catch2/src/catch2/reporters/catch_reporter_helpers.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -182,9 +183,29 @@ namespace Catch { out << "All available tags:\n"; } + // minimum whitespace to pad tag counts, possibly overwritten below + size_t maxTagCountLen = 2; + + // determine necessary padding for tag count column + if ( ! tags.empty() ) { + const auto maxTagCount = + std::max_element( tags.begin(), + tags.end(), + []( auto const& lhs, auto const& rhs ) { + return lhs.count < rhs.count; + } ) + ->count; + + // more padding necessary for 3+ digits + if (maxTagCount >= 100) { + auto numDigits = 1 + std::floor( std::log10( maxTagCount ) ); + maxTagCountLen = static_cast( numDigits ); + } + } + for ( auto const& tagCount : tags ) { ReusableStringStream rss; - rss << " " << std::setw( 2 ) << tagCount.count << " "; + rss << " " << std::setw( maxTagCountLen ) << tagCount.count << " "; auto str = rss.str(); auto wrapper = TextFlow::Column( tagCount.all() ) .initialIndent( 0 ) diff --git a/catch2/src/catch2/reporters/catch_reporter_json.cpp b/catch2/src/catch2/reporters/catch_reporter_json.cpp index 6a8e655..4328d56 100644 --- a/catch2/src/catch2/reporters/catch_reporter_json.cpp +++ b/catch2/src/catch2/reporters/catch_reporter_json.cpp @@ -51,6 +51,8 @@ namespace Catch { // not, but for machine-parseable reporters I think the answer // should be yes. m_preferences.shouldReportAllAssertions = true; + // We only handle assertions when they end + m_preferences.shouldReportAllAssertionStarts = false; m_objectWriters.emplace( m_stream ); m_writers.emplace( Writer::Object ); @@ -280,7 +282,6 @@ namespace Catch { endObject(); } - void JsonReporter::assertionStarting( AssertionInfo const& /*assertionInfo*/ ) {} void JsonReporter::assertionEnded( AssertionStats const& assertionStats ) { // TODO: There is lot of different things to handle here, but // we can fill it in later, after we show that the basic diff --git a/catch2/src/catch2/reporters/catch_reporter_json.hpp b/catch2/src/catch2/reporters/catch_reporter_json.hpp index c938ca3..b28aaf8 100644 --- a/catch2/src/catch2/reporters/catch_reporter_json.hpp +++ b/catch2/src/catch2/reporters/catch_reporter_json.hpp @@ -39,7 +39,6 @@ namespace Catch { void sectionStarting( SectionInfo const& sectionInfo ) override; void sectionEnded( SectionStats const& sectionStats ) override; - void assertionStarting( AssertionInfo const& assertionInfo ) override; void assertionEnded( AssertionStats const& assertionStats ) override; //void testRunEndedCumulative() override; diff --git a/catch2/src/catch2/reporters/catch_reporter_junit.cpp b/catch2/src/catch2/reporters/catch_reporter_junit.cpp index 27bdfe2..df34f17 100644 --- a/catch2/src/catch2/reporters/catch_reporter_junit.cpp +++ b/catch2/src/catch2/reporters/catch_reporter_junit.cpp @@ -89,6 +89,7 @@ namespace Catch { { m_preferences.shouldRedirectStdOut = true; m_preferences.shouldReportAllAssertions = false; + m_preferences.shouldReportAllAssertionStarts = false; m_shouldStoreSuccesfulAssertions = false; } diff --git a/catch2/src/catch2/reporters/catch_reporter_multi.cpp b/catch2/src/catch2/reporters/catch_reporter_multi.cpp index 531902b..6bf9bcb 100644 --- a/catch2/src/catch2/reporters/catch_reporter_multi.cpp +++ b/catch2/src/catch2/reporters/catch_reporter_multi.cpp @@ -19,6 +19,8 @@ namespace Catch { reporterish.getPreferences().shouldRedirectStdOut; m_preferences.shouldReportAllAssertions |= reporterish.getPreferences().shouldReportAllAssertions; + m_preferences.shouldReportAllAssertionStarts |= + reporterish.getPreferences().shouldReportAllAssertionStarts; } void MultiReporter::addListener( IEventListenerPtr&& listener ) { diff --git a/catch2/src/catch2/reporters/catch_reporter_multi.hpp b/catch2/src/catch2/reporters/catch_reporter_multi.hpp index 6611383..d206663 100644 --- a/catch2/src/catch2/reporters/catch_reporter_multi.hpp +++ b/catch2/src/catch2/reporters/catch_reporter_multi.hpp @@ -29,6 +29,11 @@ namespace Catch { void updatePreferences(IEventListener const& reporterish); public: + MultiReporter( IConfig const* config ): + IEventListener( config ) { + m_preferences.shouldReportAllAssertionStarts = false; + } + using IEventListener::IEventListener; void addListener( IEventListenerPtr&& listener ); diff --git a/catch2/src/catch2/reporters/catch_reporter_registrars.hpp b/catch2/src/catch2/reporters/catch_reporter_registrars.hpp index a93963f..d971c45 100644 --- a/catch2/src/catch2/reporters/catch_reporter_registrars.hpp +++ b/catch2/src/catch2/reporters/catch_reporter_registrars.hpp @@ -103,22 +103,24 @@ namespace Catch { #if !defined(CATCH_CONFIG_DISABLE) -# define CATCH_REGISTER_REPORTER( name, reporterType ) \ - CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ - CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ - namespace { \ - Catch::ReporterRegistrar INTERNAL_CATCH_UNIQUE_NAME( \ - catch_internal_RegistrarFor )( name ); \ - } \ +# define CATCH_REGISTER_REPORTER( name, reporterType ) \ + CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ + CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ + namespace { \ + const Catch::ReporterRegistrar \ + INTERNAL_CATCH_UNIQUE_NAME( catch_internal_RegistrarFor )( \ + name ); \ + } \ CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION -# define CATCH_REGISTER_LISTENER( listenerType ) \ - CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ - CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ - namespace { \ - Catch::ListenerRegistrar INTERNAL_CATCH_UNIQUE_NAME( \ - catch_internal_RegistrarFor )( #listenerType##_catch_sr ); \ - } \ +# define CATCH_REGISTER_LISTENER( listenerType ) \ + CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ + CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ + namespace { \ + const Catch::ListenerRegistrar \ + INTERNAL_CATCH_UNIQUE_NAME( catch_internal_RegistrarFor )( \ + #listenerType##_catch_sr ); \ + } \ CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION #else // CATCH_CONFIG_DISABLE diff --git a/catch2/src/catch2/reporters/catch_reporter_sonarqube.hpp b/catch2/src/catch2/reporters/catch_reporter_sonarqube.hpp index 509f411..98803a2 100644 --- a/catch2/src/catch2/reporters/catch_reporter_sonarqube.hpp +++ b/catch2/src/catch2/reporters/catch_reporter_sonarqube.hpp @@ -22,6 +22,7 @@ namespace Catch { , xml(m_stream) { m_preferences.shouldRedirectStdOut = true; m_preferences.shouldReportAllAssertions = false; + m_preferences.shouldReportAllAssertionStarts = false; m_shouldStoreSuccesfulAssertions = false; } diff --git a/catch2/src/catch2/reporters/catch_reporter_tap.cpp b/catch2/src/catch2/reporters/catch_reporter_tap.cpp index 67d406f..d7e68bf 100644 --- a/catch2/src/catch2/reporters/catch_reporter_tap.cpp +++ b/catch2/src/catch2/reporters/catch_reporter_tap.cpp @@ -196,7 +196,8 @@ namespace Catch { if ( m_config->testSpec().hasFilters() ) { m_stream << "# filters: " << m_config->testSpec() << '\n'; } - m_stream << "# rng-seed: " << m_config->rngSeed() << '\n'; + m_stream << "# rng-seed: " << m_config->rngSeed() << '\n' + << std::flush; } void TAPReporter::noMatchingTestCases( StringRef unmatchedSpec ) { diff --git a/catch2/src/catch2/reporters/catch_reporter_tap.hpp b/catch2/src/catch2/reporters/catch_reporter_tap.hpp index e6889bb..4664928 100644 --- a/catch2/src/catch2/reporters/catch_reporter_tap.hpp +++ b/catch2/src/catch2/reporters/catch_reporter_tap.hpp @@ -18,6 +18,7 @@ namespace Catch { TAPReporter( ReporterConfig&& config ): StreamingReporterBase( CATCH_MOVE(config) ) { m_preferences.shouldReportAllAssertions = true; + m_preferences.shouldReportAllAssertionStarts = false; } static std::string getDescription() { diff --git a/catch2/src/catch2/reporters/catch_reporter_teamcity.hpp b/catch2/src/catch2/reporters/catch_reporter_teamcity.hpp index 662e989..4adb0e3 100644 --- a/catch2/src/catch2/reporters/catch_reporter_teamcity.hpp +++ b/catch2/src/catch2/reporters/catch_reporter_teamcity.hpp @@ -26,6 +26,7 @@ namespace Catch { : StreamingReporterBase( CATCH_MOVE(_config) ) { m_preferences.shouldRedirectStdOut = true; + m_preferences.shouldReportAllAssertionStarts = false; } ~TeamCityReporter() override; diff --git a/catch2/src/catch2/reporters/catch_reporter_xml.cpp b/catch2/src/catch2/reporters/catch_reporter_xml.cpp index 35a3028..8b7b5a7 100644 --- a/catch2/src/catch2/reporters/catch_reporter_xml.cpp +++ b/catch2/src/catch2/reporters/catch_reporter_xml.cpp @@ -30,6 +30,7 @@ namespace Catch { { m_preferences.shouldRedirectStdOut = true; m_preferences.shouldReportAllAssertions = true; + m_preferences.shouldReportAllAssertionStarts = false; } XmlReporter::~XmlReporter() = default; @@ -86,8 +87,6 @@ namespace Catch { } } - void XmlReporter::assertionStarting( AssertionInfo const& ) { } - void XmlReporter::assertionEnded( AssertionStats const& assertionStats ) { AssertionResult const& result = assertionStats.assertionResult; diff --git a/catch2/src/catch2/reporters/catch_reporter_xml.hpp b/catch2/src/catch2/reporters/catch_reporter_xml.hpp index bead7a8..66f95a8 100644 --- a/catch2/src/catch2/reporters/catch_reporter_xml.hpp +++ b/catch2/src/catch2/reporters/catch_reporter_xml.hpp @@ -35,8 +35,6 @@ namespace Catch { void sectionStarting(SectionInfo const& sectionInfo) override; - void assertionStarting(AssertionInfo const&) override; - void assertionEnded(AssertionStats const& assertionStats) override; void sectionEnded(SectionStats const& sectionStats) override; diff --git a/catch2/tests/BUILD.bazel b/catch2/tests/BUILD.bazel index 5f0362f..58c0520 100644 --- a/catch2/tests/BUILD.bazel +++ b/catch2/tests/BUILD.bazel @@ -21,6 +21,7 @@ cc_test( size = "small", srcs = [ "SelfTest/IntrospectiveTests/Algorithms.tests.cpp", + "SelfTest/IntrospectiveTests/AssertionHandler.tests.cpp", "SelfTest/IntrospectiveTests/Clara.tests.cpp", "SelfTest/IntrospectiveTests/CmdLine.tests.cpp", "SelfTest/IntrospectiveTests/CmdLineHelpers.tests.cpp", @@ -30,6 +31,7 @@ cc_test( "SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp", "SelfTest/IntrospectiveTests/Integer.tests.cpp", "SelfTest/IntrospectiveTests/InternalBenchmark.tests.cpp", + "SelfTest/IntrospectiveTests/Json.tests.cpp", "SelfTest/IntrospectiveTests/Parse.tests.cpp", "SelfTest/IntrospectiveTests/PartTracker.tests.cpp", "SelfTest/IntrospectiveTests/RandomNumberGeneration.tests.cpp", @@ -63,6 +65,7 @@ cc_test( "SelfTest/UsageTests/MatchersRanges.tests.cpp", "SelfTest/UsageTests/Message.tests.cpp", "SelfTest/UsageTests/Misc.tests.cpp", + "SelfTest/UsageTests/Skip.tests.cpp", "SelfTest/UsageTests/ToStringByte.tests.cpp", "SelfTest/UsageTests/ToStringChrono.tests.cpp", "SelfTest/UsageTests/ToStringGeneral.tests.cpp", diff --git a/catch2/tests/CMakeLists.txt b/catch2/tests/CMakeLists.txt index 37a5977..651ac83 100644 --- a/catch2/tests/CMakeLists.txt +++ b/catch2/tests/CMakeLists.txt @@ -1,6 +1,6 @@ include(CatchMiscFunctions) -if (CATCH_BUILD_SURROGATES) +if(CATCH_BUILD_SURROGATES) message(STATUS "Configuring targets for surrogate TUs") # If the folder does not exist before we ask for output redirect to @@ -11,11 +11,9 @@ if (CATCH_BUILD_SURROGATES) # Returns the path to the generated file. function(createSurrogateFileTarget sourceHeader pathToFile) set(pathPrefix ${PROJECT_SOURCE_DIR}/src) - file(RELATIVE_PATH includePath ${pathPrefix} ${sourceHeader}) get_filename_component(basicFileName "${sourceHeader}" NAME_WE) - set(surrogateFilePath ${CMAKE_CURRENT_BINARY_DIR}/surrogates/surrogate_${basicFileName}.cpp) add_custom_command( @@ -41,10 +39,9 @@ if (CATCH_BUILD_SURROGATES) set(${OutArg} ${AllHeaders} PARENT_SCOPE) endfunction() - ExtractCatch2Headers(mainHeaders) - if (NOT mainHeaders) + if(NOT mainHeaders) message(FATAL_ERROR "No headers in the main target were detected. Something is broken.") endif() @@ -53,12 +50,10 @@ if (CATCH_BUILD_SURROGATES) list(APPEND surrogateFiles ${pathToGeneratedFile}) endforeach() - add_executable(Catch2SurrogateTarget ${surrogateFiles} ) target_link_libraries(Catch2SurrogateTarget PRIVATE Catch2WithMain) - endif() #### @@ -66,75 +61,72 @@ endif() # We need to disable property, but CMake doesn't support it # until 3.13 (not yet released) #### -if (MSVC) -configure_file(${CATCH_DIR}/tools/misc/SelfTest.vcxproj.user - ${CMAKE_BINARY_DIR}/tests - COPYONLY) +if(MSVC) + configure_file(${CATCH_DIR}/tools/misc/SelfTest.vcxproj.user ${CMAKE_BINARY_DIR}/tests COPYONLY) endif() #Temporary workaround - # define the sources of the self test # Please keep these ordered alphabetically set(TEST_SOURCES - ${SELF_TEST_DIR}/TestRegistrations.cpp - ${SELF_TEST_DIR}/IntrospectiveTests/Algorithms.tests.cpp - ${SELF_TEST_DIR}/IntrospectiveTests/AssertionHandler.tests.cpp - ${SELF_TEST_DIR}/IntrospectiveTests/Clara.tests.cpp - ${SELF_TEST_DIR}/IntrospectiveTests/CmdLine.tests.cpp - ${SELF_TEST_DIR}/IntrospectiveTests/CmdLineHelpers.tests.cpp - ${SELF_TEST_DIR}/IntrospectiveTests/ColourImpl.tests.cpp - ${SELF_TEST_DIR}/IntrospectiveTests/Details.tests.cpp - ${SELF_TEST_DIR}/IntrospectiveTests/FloatingPoint.tests.cpp - ${SELF_TEST_DIR}/IntrospectiveTests/GeneratorsImpl.tests.cpp - ${SELF_TEST_DIR}/IntrospectiveTests/Integer.tests.cpp - ${SELF_TEST_DIR}/IntrospectiveTests/InternalBenchmark.tests.cpp - ${SELF_TEST_DIR}/IntrospectiveTests/Json.tests.cpp - ${SELF_TEST_DIR}/IntrospectiveTests/Parse.tests.cpp - ${SELF_TEST_DIR}/IntrospectiveTests/PartTracker.tests.cpp - ${SELF_TEST_DIR}/IntrospectiveTests/RandomNumberGeneration.tests.cpp - ${SELF_TEST_DIR}/IntrospectiveTests/Reporters.tests.cpp - ${SELF_TEST_DIR}/IntrospectiveTests/Tag.tests.cpp - ${SELF_TEST_DIR}/IntrospectiveTests/TestCaseInfoHasher.tests.cpp - ${SELF_TEST_DIR}/IntrospectiveTests/TestSpec.tests.cpp - ${SELF_TEST_DIR}/IntrospectiveTests/TestSpecParser.tests.cpp - ${SELF_TEST_DIR}/IntrospectiveTests/TextFlow.tests.cpp - ${SELF_TEST_DIR}/IntrospectiveTests/Sharding.tests.cpp - ${SELF_TEST_DIR}/IntrospectiveTests/Stream.tests.cpp - ${SELF_TEST_DIR}/IntrospectiveTests/String.tests.cpp - ${SELF_TEST_DIR}/IntrospectiveTests/StringManip.tests.cpp - ${SELF_TEST_DIR}/IntrospectiveTests/Xml.tests.cpp - ${SELF_TEST_DIR}/IntrospectiveTests/Traits.tests.cpp - ${SELF_TEST_DIR}/IntrospectiveTests/ToString.tests.cpp - ${SELF_TEST_DIR}/IntrospectiveTests/UniquePtr.tests.cpp - ${SELF_TEST_DIR}/helpers/parse_test_spec.cpp - ${SELF_TEST_DIR}/TimingTests/Sleep.tests.cpp - ${SELF_TEST_DIR}/UsageTests/Approx.tests.cpp - ${SELF_TEST_DIR}/UsageTests/BDD.tests.cpp - ${SELF_TEST_DIR}/UsageTests/Benchmark.tests.cpp - ${SELF_TEST_DIR}/UsageTests/Class.tests.cpp - ${SELF_TEST_DIR}/UsageTests/Compilation.tests.cpp - ${SELF_TEST_DIR}/UsageTests/Condition.tests.cpp - ${SELF_TEST_DIR}/UsageTests/Decomposition.tests.cpp - ${SELF_TEST_DIR}/UsageTests/EnumToString.tests.cpp - ${SELF_TEST_DIR}/UsageTests/Exception.tests.cpp - ${SELF_TEST_DIR}/UsageTests/Generators.tests.cpp - ${SELF_TEST_DIR}/UsageTests/Message.tests.cpp - ${SELF_TEST_DIR}/UsageTests/Misc.tests.cpp - ${SELF_TEST_DIR}/UsageTests/Skip.tests.cpp - ${SELF_TEST_DIR}/UsageTests/ToStringByte.tests.cpp - ${SELF_TEST_DIR}/UsageTests/ToStringChrono.tests.cpp - ${SELF_TEST_DIR}/UsageTests/ToStringGeneral.tests.cpp - ${SELF_TEST_DIR}/UsageTests/ToStringOptional.tests.cpp - ${SELF_TEST_DIR}/UsageTests/ToStringPair.tests.cpp - ${SELF_TEST_DIR}/UsageTests/ToStringTuple.tests.cpp - ${SELF_TEST_DIR}/UsageTests/ToStringVariant.tests.cpp - ${SELF_TEST_DIR}/UsageTests/ToStringVector.tests.cpp - ${SELF_TEST_DIR}/UsageTests/ToStringWhich.tests.cpp - ${SELF_TEST_DIR}/UsageTests/Tricky.tests.cpp - ${SELF_TEST_DIR}/UsageTests/VariadicMacros.tests.cpp - ${SELF_TEST_DIR}/UsageTests/MatchersRanges.tests.cpp - ${SELF_TEST_DIR}/UsageTests/Matchers.tests.cpp - ) + ${SELF_TEST_DIR}/TestRegistrations.cpp + ${SELF_TEST_DIR}/IntrospectiveTests/Algorithms.tests.cpp + ${SELF_TEST_DIR}/IntrospectiveTests/AssertionHandler.tests.cpp + ${SELF_TEST_DIR}/IntrospectiveTests/Clara.tests.cpp + ${SELF_TEST_DIR}/IntrospectiveTests/CmdLine.tests.cpp + ${SELF_TEST_DIR}/IntrospectiveTests/CmdLineHelpers.tests.cpp + ${SELF_TEST_DIR}/IntrospectiveTests/ColourImpl.tests.cpp + ${SELF_TEST_DIR}/IntrospectiveTests/Details.tests.cpp + ${SELF_TEST_DIR}/IntrospectiveTests/FloatingPoint.tests.cpp + ${SELF_TEST_DIR}/IntrospectiveTests/GeneratorsImpl.tests.cpp + ${SELF_TEST_DIR}/IntrospectiveTests/Integer.tests.cpp + ${SELF_TEST_DIR}/IntrospectiveTests/InternalBenchmark.tests.cpp + ${SELF_TEST_DIR}/IntrospectiveTests/Json.tests.cpp + ${SELF_TEST_DIR}/IntrospectiveTests/Parse.tests.cpp + ${SELF_TEST_DIR}/IntrospectiveTests/PartTracker.tests.cpp + ${SELF_TEST_DIR}/IntrospectiveTests/RandomNumberGeneration.tests.cpp + ${SELF_TEST_DIR}/IntrospectiveTests/Reporters.tests.cpp + ${SELF_TEST_DIR}/IntrospectiveTests/Tag.tests.cpp + ${SELF_TEST_DIR}/IntrospectiveTests/TestCaseInfoHasher.tests.cpp + ${SELF_TEST_DIR}/IntrospectiveTests/TestSpec.tests.cpp + ${SELF_TEST_DIR}/IntrospectiveTests/TestSpecParser.tests.cpp + ${SELF_TEST_DIR}/IntrospectiveTests/TextFlow.tests.cpp + ${SELF_TEST_DIR}/IntrospectiveTests/Sharding.tests.cpp + ${SELF_TEST_DIR}/IntrospectiveTests/Stream.tests.cpp + ${SELF_TEST_DIR}/IntrospectiveTests/String.tests.cpp + ${SELF_TEST_DIR}/IntrospectiveTests/StringManip.tests.cpp + ${SELF_TEST_DIR}/IntrospectiveTests/Xml.tests.cpp + ${SELF_TEST_DIR}/IntrospectiveTests/Traits.tests.cpp + ${SELF_TEST_DIR}/IntrospectiveTests/ToString.tests.cpp + ${SELF_TEST_DIR}/IntrospectiveTests/UniquePtr.tests.cpp + ${SELF_TEST_DIR}/helpers/parse_test_spec.cpp + ${SELF_TEST_DIR}/TimingTests/Sleep.tests.cpp + ${SELF_TEST_DIR}/UsageTests/Approx.tests.cpp + ${SELF_TEST_DIR}/UsageTests/BDD.tests.cpp + ${SELF_TEST_DIR}/UsageTests/Benchmark.tests.cpp + ${SELF_TEST_DIR}/UsageTests/Class.tests.cpp + ${SELF_TEST_DIR}/UsageTests/Compilation.tests.cpp + ${SELF_TEST_DIR}/UsageTests/Condition.tests.cpp + ${SELF_TEST_DIR}/UsageTests/Decomposition.tests.cpp + ${SELF_TEST_DIR}/UsageTests/EnumToString.tests.cpp + ${SELF_TEST_DIR}/UsageTests/Exception.tests.cpp + ${SELF_TEST_DIR}/UsageTests/Generators.tests.cpp + ${SELF_TEST_DIR}/UsageTests/Message.tests.cpp + ${SELF_TEST_DIR}/UsageTests/Misc.tests.cpp + ${SELF_TEST_DIR}/UsageTests/Skip.tests.cpp + ${SELF_TEST_DIR}/UsageTests/ToStringByte.tests.cpp + ${SELF_TEST_DIR}/UsageTests/ToStringChrono.tests.cpp + ${SELF_TEST_DIR}/UsageTests/ToStringGeneral.tests.cpp + ${SELF_TEST_DIR}/UsageTests/ToStringOptional.tests.cpp + ${SELF_TEST_DIR}/UsageTests/ToStringPair.tests.cpp + ${SELF_TEST_DIR}/UsageTests/ToStringTuple.tests.cpp + ${SELF_TEST_DIR}/UsageTests/ToStringVariant.tests.cpp + ${SELF_TEST_DIR}/UsageTests/ToStringVector.tests.cpp + ${SELF_TEST_DIR}/UsageTests/ToStringWhich.tests.cpp + ${SELF_TEST_DIR}/UsageTests/Tricky.tests.cpp + ${SELF_TEST_DIR}/UsageTests/VariadicMacros.tests.cpp + ${SELF_TEST_DIR}/UsageTests/MatchersRanges.tests.cpp + ${SELF_TEST_DIR}/UsageTests/Matchers.tests.cpp +) set(TEST_HEADERS ${SELF_TEST_DIR}/helpers/parse_test_spec.hpp @@ -142,46 +134,45 @@ set(TEST_HEADERS ${SELF_TEST_DIR}/helpers/type_with_lit_0_comparisons.hpp ) - # Specify the headers, too, so CLion recognises them as project files set(HEADERS - ${TOP_LEVEL_HEADERS} - ${EXTERNAL_HEADERS} - ${INTERNAL_HEADERS} - ${REPORTER_HEADERS} - ${BENCHMARK_HEADERS} - ${BENCHMARK_SOURCES} + ${TOP_LEVEL_HEADERS} + ${EXTERNAL_HEADERS} + ${INTERNAL_HEADERS} + ${REPORTER_HEADERS} + ${BENCHMARK_HEADERS} + ${BENCHMARK_SOURCES} ) # Provide some groupings for IDEs -#SOURCE_GROUP("benchmark" FILES ${BENCHMARK_HEADERS} ${BENCHMARK_SOURCES}) -#SOURCE_GROUP("Tests" FILES ${TEST_SOURCES}) +#source_group("benchmark" FILES ${BENCHMARK_HEADERS} ${BENCHMARK_SOURCES}) +#source_group("Tests" FILES ${TEST_SOURCES}) include(CTest) add_executable(SelfTest ${TEST_SOURCES} ${TEST_HEADERS}) target_include_directories(SelfTest PRIVATE ${SELF_TEST_DIR}) target_link_libraries(SelfTest PRIVATE Catch2WithMain) -if (BUILD_SHARED_LIBS AND WIN32) - add_custom_command(TARGET SelfTest PRE_LINK - COMMAND ${CMAKE_COMMAND} -E copy_if_different $ - $ $ - ) +if(BUILD_SHARED_LIBS AND WIN32) + add_custom_command(TARGET SelfTest PRE_LINK + COMMAND ${CMAKE_COMMAND} -E copy_if_different $ + $ $ + ) endif() -if (CATCH_ENABLE_COVERAGE) - set(ENABLE_COVERAGE ON CACHE BOOL "Enable coverage build." FORCE) - find_package(codecov) - add_coverage(SelfTest) - list(APPEND LCOV_REMOVE_PATTERNS "'/usr/*'") - coverage_evaluate() +if(CATCH_ENABLE_COVERAGE) + set(ENABLE_COVERAGE ON CACHE BOOL "Enable coverage build." FORCE) + find_package(codecov) + add_coverage(SelfTest) + list(APPEND LCOV_REMOVE_PATTERNS "'/usr/*'") + coverage_evaluate() endif() # configure unit tests via CTest add_test(NAME RunTests COMMAND $ --order rand --rng-seed time) set_tests_properties(RunTests PROPERTIES - FAIL_REGULAR_EXPRESSION "Filters:" - COST 15 + FAIL_REGULAR_EXPRESSION "Filters:" + COST 15 ) # Because CTest does not allow us to check both return code _and_ expected @@ -189,8 +180,8 @@ set_tests_properties(RunTests PROPERTIES # the output, the second time we check the exit code. add_test(NAME List::Tests::Output COMMAND $ --list-tests --verbosity high) set_tests_properties(List::Tests::Output PROPERTIES - PASS_REGULAR_EXPRESSION "[0-9]+ test cases" - FAIL_REGULAR_EXPRESSION "Hidden Test" + PASS_REGULAR_EXPRESSION "[0-9]+ test cases" + FAIL_REGULAR_EXPRESSION "Hidden Test" ) # This should be equivalent to the old --list-test-names-only and be usable # with --input-file. @@ -198,35 +189,34 @@ add_test(NAME List::Tests::Quiet COMMAND $ --list-tests -- # Sadly we cannot ask for start-of-line and end-of-line in a ctest regex, # so we fail if we see space/tab at the start... set_tests_properties(List::Tests::Quiet PROPERTIES - PASS_REGULAR_EXPRESSION "\"#1905 -- test spec parser properly clears internal state between compound tests\"[\r\n]" - FAIL_REGULAR_EXPRESSION "[ \t]\"#1905 -- test spec parser properly clears internal state between compound tests\"" + PASS_REGULAR_EXPRESSION "\"#1905 -- test spec parser properly clears internal state between compound tests\"[\r\n]" + FAIL_REGULAR_EXPRESSION "[ \t]\"#1905 -- test spec parser properly clears internal state between compound tests\"" ) add_test(NAME List::Tests::ExitCode COMMAND $ --list-tests --verbosity high) add_test(NAME List::Tests::XmlOutput COMMAND $ --list-tests --verbosity high -r xml) set_tests_properties(List::Tests::XmlOutput PROPERTIES - PASS_REGULAR_EXPRESSION "[0-9]+" - FAIL_REGULAR_EXPRESSION "[0-9]+ test cases" + PASS_REGULAR_EXPRESSION "[0-9]+" + FAIL_REGULAR_EXPRESSION "[0-9]+ test cases" ) add_test(NAME List::Tags::Output COMMAND $ --list-tags) set_tests_properties(List::Tags::Output PROPERTIES - PASS_REGULAR_EXPRESSION "[0-9]+ tags" - FAIL_REGULAR_EXPRESSION "\\[\\.\\]") + PASS_REGULAR_EXPRESSION "[0-9]+ tags" + FAIL_REGULAR_EXPRESSION "\\[\\.\\]") add_test(NAME List::Tags::ExitCode COMMAND $ --list-tags) add_test(NAME List::Tags::XmlOutput COMMAND $ --list-tags -r xml) set_tests_properties(List::Tags::XmlOutput PROPERTIES - PASS_REGULAR_EXPRESSION "18" - FAIL_REGULAR_EXPRESSION "[0-9]+ tags" + PASS_REGULAR_EXPRESSION "18" + FAIL_REGULAR_EXPRESSION "[0-9]+ tags" ) - add_test(NAME List::Reporters::Output COMMAND $ --list-reporters) set_tests_properties(List::Reporters::Output PROPERTIES PASS_REGULAR_EXPRESSION "Available reporters:") add_test(NAME List::Reporters::ExitCode COMMAND $ --list-reporters) add_test(NAME List::Reporters::XmlOutput COMMAND $ --list-reporters -r xml) set_tests_properties(List::Reporters::XmlOutput PROPERTIES - PASS_REGULAR_EXPRESSION "compact" - FAIL_REGULAR_EXPRESSION "Available reporters:" + PASS_REGULAR_EXPRESSION "compact" + FAIL_REGULAR_EXPRESSION "Available reporters:" ) add_test(NAME List::Listeners::Output @@ -263,8 +253,8 @@ add_test(NAME TestSpecs::CombiningMatchingAndNonMatchingIsOk-1 COMMAND $ Tracker, "___nonexistent_test___") set_tests_properties(TestSpecs::CombiningMatchingAndNonMatchingIsOk-2 PROPERTIES - PASS_REGULAR_EXPRESSION "No test cases matched '\"___nonexistent_test___\"'" - FAIL_REGULAR_EXPRESSION "No tests ran" + PASS_REGULAR_EXPRESSION "No test cases matched '\"___nonexistent_test___\"'" + FAIL_REGULAR_EXPRESSION "No tests ran" ) add_test(NAME TestSpecs::NoMatchedTestsFail @@ -283,7 +273,7 @@ add_test(NAME TestSpecs::OverrideAllSkipFailure ) add_test(NAME TestSpecs::NonMatchingTestSpecIsRoundTrippable - COMMAND $ Tracker, "this test does not exist" "[nor does this tag]" + COMMAND $ Tracker, "this test does not exist" "[nor does this tag]" ) set_tests_properties(TestSpecs::NonMatchingTestSpecIsRoundTrippable PROPERTIES @@ -352,10 +342,9 @@ set_tests_properties(FilteredSection::GeneratorsDontCauseInfiniteLoop-2 PASS_REGULAR_EXPRESSION "All tests passed \\(4 assertions in 1 test case\\)" ) -# AppVeyor has a Python 2.7 in path, but doesn't have .py files as autorunnable add_test(NAME ApprovalTests COMMAND - ${PYTHON_EXECUTABLE} + Python3::Interpreter ${CATCH_DIR}/tools/scripts/approvalTests.py $ "${CMAKE_CURRENT_BINARY_DIR}" @@ -418,7 +407,7 @@ set_tests_properties(TagAlias PROPERTIES FAIL_REGULAR_EXPRESSION "0 matching test cases" ) -add_test(NAME RandomTestOrdering COMMAND ${PYTHON_EXECUTABLE} +add_test(NAME RandomTestOrdering COMMAND Python3::Interpreter ${CATCH_DIR}/tests/TestScripts/testRandomOrder.py $) set_tests_properties(RandomTestOrdering PROPERTIES @@ -427,7 +416,7 @@ set_tests_properties(RandomTestOrdering add_test(NAME CheckConvenienceHeaders COMMAND - ${PYTHON_EXECUTABLE} ${CATCH_DIR}/tools/scripts/checkConvenienceHeaders.py + Python3::Interpreter ${CATCH_DIR}/tools/scripts/checkConvenienceHeaders.py ) set_tests_properties(CheckConvenienceHeaders PROPERTIES @@ -447,7 +436,6 @@ set_tests_properties("Benchmarking::SkipBenchmarkMacros" FAIL_REGULAR_EXPRESSION "benchmark name" ) - add_test(NAME "Benchmarking::FailureReporting::OptimizedOut" COMMAND $ "Failing benchmarks" -c "empty" -r xml @@ -510,7 +498,7 @@ set_tests_properties("ErrorHandling::InvalidTestSpecExitsEarly" FAIL_REGULAR_EXPRESSION "No tests ran" ) -if (MSVC) +if(MSVC) set(_NullFile "NUL") else() set(_NullFile "/dev/null") @@ -519,7 +507,7 @@ endif() # This test checks that there is nothing written out from the process, # but if CMake is running the tests under Valgrind or similar tool, then # that will write its own output to stdout and the test would fail. -if (NOT MEMORYCHECK_COMMAND) +if(NOT MEMORYCHECK_COMMAND) add_test(NAME "MultiReporter::CapturingReportersDontPropagateStdOut" COMMAND $ "Sends stuff to stdout and stderr" @@ -608,76 +596,104 @@ set_tests_properties("Reporters::JUnit::NamespacesAreNormalized" PASS_REGULAR_EXPRESSION "testcase classname=\"SelfTest(\.exe)?\\.A\\.B\\.TestClass\"" ) -if (CATCH_ENABLE_CONFIGURE_TESTS) - foreach(testName "DefaultReporter" "Disable" "DisableStringification" - "ExperimentalRedirect") - - add_test(NAME "CMakeConfig::${testName}" - COMMAND - "${PYTHON_EXECUTABLE}" "${CMAKE_CURRENT_LIST_DIR}/TestScripts/testConfigure${testName}.py" "${CATCH_DIR}" "${CMAKE_CURRENT_BINARY_DIR}" - ) - set_tests_properties("CMakeConfig::${testName}" - PROPERTIES - COST 240 - LABELS "uses-python" - ) - - endforeach() -endif() - -if (CATCH_ENABLE_CMAKE_HELPER_TESTS) - add_test(NAME "CMakeHelper::DiscoverTests" +if(CATCH_ENABLE_CONFIGURE_TESTS) + foreach(testName "DefaultReporter" "Disable" "DisableStringification" + "ExperimentalRedirect") + add_test(NAME "CMakeConfig::${testName}" COMMAND - "${PYTHON_EXECUTABLE}" "${CMAKE_CURRENT_LIST_DIR}/TestScripts/DiscoverTests/VerifyRegistration.py" "${CATCH_DIR}" "${CMAKE_CURRENT_BINARY_DIR}" + Python3::Interpreter "${CMAKE_CURRENT_LIST_DIR}/TestScripts/testConfigure${testName}.py" "${CATCH_DIR}" "${CMAKE_CURRENT_BINARY_DIR}" ) - set_tests_properties("CMakeHelper::DiscoverTests" + set_tests_properties("CMakeConfig::${testName}" PROPERTIES COST 240 LABELS "uses-python" ) + endforeach() endif() -foreach (reporterName # "Automake" - the simple .trs format does not support any kind of comments/metadata - "compact" - "console" - "JUnit" - "SonarQube" - "TAP" - # "TeamCity" - does not seem to support test suite-level metadata/comments - "XML" - "JSON") - - add_test(NAME "Reporters:Filters:${reporterName}" - COMMAND - $ [comparisons][string-case] "CaseInsensitiveLess is case insensitive" - --reporter ${reporterName} - ) - # Different regex for these two reporters, because the commas end up xml-escaped - if (reporterName MATCHES "JUnit|XML") - set(testCaseNameFormat ""CaseInsensitiveLess is case insensitive"") - elseif(reporterName MATCHES "JSON") - set(testCaseNameFormat "\\\\\"CaseInsensitiveLess is case insensitive\\\\\"") - else() - set(testCaseNameFormat "\"CaseInsensitiveLess is case insensitive\"") - endif() - set_tests_properties("Reporters:Filters:${reporterName}" - PROPERTIES - PASS_REGULAR_EXPRESSION "[fF]ilters.+\\[comparisons\\] \\[string-case\\] ${testCaseNameFormat}" - ) +if(CATCH_ENABLE_CMAKE_HELPER_TESTS) + add_test(NAME "CMakeHelper::DiscoverTests" + COMMAND + Python3::Interpreter "${CMAKE_CURRENT_LIST_DIR}/TestScripts/DiscoverTests/VerifyRegistration.py" "${CATCH_DIR}" "${CMAKE_CURRENT_BINARY_DIR}" + ) + set_tests_properties("CMakeHelper::DiscoverTests" + PROPERTIES + COST 240 + LABELS "uses-python" + ) +endif() - add_test(NAME "Reporters:RngSeed:${reporterName}" - COMMAND - $ "Factorials are computed" - --reporter ${reporterName} - --rng-seed 18181818 - ) - set_tests_properties("Reporters:RngSeed:${reporterName}" - PROPERTIES - PASS_REGULAR_EXPRESSION "18181818" - ) +foreach(reporterName # "Automake" - the simple .trs format does not support any kind of comments/metadata + "compact" + "console" + "JUnit" + "SonarQube" + "TAP" + # "TeamCity" - does not seem to support test suite-level metadata/comments + "XML" + "JSON") + add_test(NAME "Reporters:Filters:${reporterName}" + COMMAND + $ [comparisons][string-case] "CaseInsensitiveLess is case insensitive" + --reporter ${reporterName} + ) + # Different regex for these two reporters, because the commas end up xml-escaped + if(reporterName MATCHES "JUnit|XML") + set(testCaseNameFormat ""CaseInsensitiveLess is case insensitive"") + elseif(reporterName MATCHES "JSON") + set(testCaseNameFormat "\\\\\"CaseInsensitiveLess is case insensitive\\\\\"") + else() + set(testCaseNameFormat "\"CaseInsensitiveLess is case insensitive\"") + endif() + set_tests_properties("Reporters:Filters:${reporterName}" + PROPERTIES + PASS_REGULAR_EXPRESSION "[fF]ilters.+\\[comparisons\\] \\[string-case\\] ${testCaseNameFormat}" + ) + add_test(NAME "Reporters:RngSeed:${reporterName}" + COMMAND + $ "Factorials are computed" + --reporter ${reporterName} + --rng-seed 18181818 + ) + set_tests_properties("Reporters:RngSeed:${reporterName}" + PROPERTIES + PASS_REGULAR_EXPRESSION "18181818" + ) endforeach() +add_test(NAME "Bazel::RngSeedEnvVar::JustEnv" + COMMAND + $ "Factorials are computed" +) +set_tests_properties("Bazel::RngSeedEnvVar::JustEnv" + PROPERTIES + ENVIRONMENT "BAZEL_TEST=1;TEST_RANDOM_SEED=18181818" + PASS_REGULAR_EXPRESSION "Randomness seeded to: 18181818" +) + +add_test(NAME "Bazel::RngSeedEnvVar::EnvHasPriorityOverCLI" + COMMAND + $ "Factorials are computed" + --rng-seed 17171717 +) +set_tests_properties("Bazel::RngSeedEnvVar::EnvHasPriorityOverCLI" + PROPERTIES + ENVIRONMENT "BAZEL_TEST=1;TEST_RANDOM_SEED=18181818" + PASS_REGULAR_EXPRESSION "Randomness seeded to: 18181818" +) + +add_test(NAME "Bazel::RngSeedEnvVar::MalformedValueIsIgnored" + COMMAND + $ "Factorials are computed" + --rng-seed 17171717 +) +set_tests_properties("Bazel::RngSeedEnvVar::MalformedValueIsIgnored" + PROPERTIES + ENVIRONMENT "BAZEL_TEST=1;TEST_RANDOM_SEED=XOXOXOXO" + PASS_REGULAR_EXPRESSION "Randomness seeded to: 17171717" +) + -list(APPEND CATCH_WARNING_TARGETS SelfTest) -set(CATCH_WARNING_TARGETS ${CATCH_WARNING_TARGETS} PARENT_SCOPE) +list(APPEND CATCH_TEST_TARGETS SelfTest) +set(CATCH_TEST_TARGETS ${CATCH_TEST_TARGETS} PARENT_SCOPE) diff --git a/catch2/tests/ExtraTests/CMakeLists.txt b/catch2/tests/ExtraTests/CMakeLists.txt index 3c38d67..fbcc346 100644 --- a/catch2/tests/ExtraTests/CMakeLists.txt +++ b/catch2/tests/ExtraTests/CMakeLists.txt @@ -1,16 +1,11 @@ -# -# Build extra tests. -# +cmake_minimum_required(VERSION 3.16) +project(Catch2ExtraTests LANGUAGES CXX) -cmake_minimum_required( VERSION 3.16 ) - -project( Catch2ExtraTests LANGUAGES CXX ) - -message( STATUS "Extra tests included" ) +message(STATUS "Extra tests included") add_test( NAME TestShardingIntegration - COMMAND ${PYTHON_EXECUTABLE} ${CATCH_DIR}/tests/TestScripts/testSharding.py $ + COMMAND Python3::Interpreter ${CATCH_DIR}/tests/TestScripts/testSharding.py $ ) set_tests_properties(TestShardingIntegration PROPERTIES @@ -21,8 +16,7 @@ add_test( NAME TestSharding::OverlyLargeShardIndex COMMAND $ --shard-index 5 --shard-count 5 ) -set_tests_properties( - TestSharding::OverlyLargeShardIndex +set_tests_properties(TestSharding::OverlyLargeShardIndex PROPERTIES PASS_REGULAR_EXPRESSION "The shard count \\(5\\) must be greater than the shard index \\(5\\)" ) @@ -31,8 +25,7 @@ set_tests_properties( # they have non-trivial execution time, so they are categorized as # extra tests, so that they are run less. add_test(NAME MinDuration::SimpleThreshold COMMAND $ --min-duration 0.950 [min_duration_test]) -set_tests_properties( - MinDuration::SimpleThreshold +set_tests_properties(MinDuration::SimpleThreshold PROPERTIES PASS_REGULAR_EXPRESSION "s: sleep_for_1000ms" FAIL_REGULAR_EXPRESSION "sleep_for_100ms" @@ -43,8 +36,7 @@ set_tests_properties( # -d yes overrides the threshold, so we should see the faster test even # with a ridiculous high min duration threshold add_test(NAME MinDuration::DurationOverrideYes COMMAND $ --min-duration 1.0 -d yes [min_duration_test]) -set_tests_properties( - MinDuration::DurationOverrideYes +set_tests_properties(MinDuration::DurationOverrideYes PROPERTIES PASS_REGULAR_EXPRESSION "s: sleep_for_100ms" ) @@ -52,27 +44,24 @@ set_tests_properties( # -d no overrides the threshold, so we should never see any tests even # with ridiculously low min duration threshold add_test(NAME MinDuration::DurationOverrideNo COMMAND $ --min-duration 0.0001 -d no [min_duration_test]) -set_tests_properties( - MinDuration::DurationOverrideNo +set_tests_properties(MinDuration::DurationOverrideNo PROPERTIES FAIL_REGULAR_EXPRESSION "sleep_for_250ms" ) - # ------------ end of duration reporting tests # define folders used: -set( TESTS_DIR ${CATCH_DIR}/tests/ExtraTests ) +set(TESTS_DIR ${CATCH_DIR}/tests/ExtraTests) add_executable(PrefixedMacros ${TESTS_DIR}/X01-PrefixedMacros.cpp) -target_compile_definitions( PrefixedMacros PRIVATE CATCH_CONFIG_PREFIX_ALL CATCH_CONFIG_RUNTIME_STATIC_REQUIRE ) +target_compile_definitions(PrefixedMacros PRIVATE CATCH_CONFIG_PREFIX_ALL CATCH_CONFIG_RUNTIME_STATIC_REQUIRE) # Macro configuration does not touch the compiled parts, so we can link # it against the main library -target_link_libraries( PrefixedMacros Catch2WithMain ) +target_link_libraries(PrefixedMacros Catch2WithMain) add_test(NAME CATCH_CONFIG_PREFIX_ALL COMMAND PrefixedMacros -s) -set_tests_properties( - CATCH_CONFIG_PREFIX_ALL +set_tests_properties(CATCH_CONFIG_PREFIX_ALL PROPERTIES PASS_REGULAR_EXPRESSION "CATCH_" FAIL_REGULAR_EXPRESSION @@ -81,67 +70,51 @@ set_tests_properties( " REQUIRE; REQUIRE_FALSE; REQUIRE_THROWS; REQUIRE_THROWS_AS; REQUIRE_THROWS_WITH; REQUIRE_THROWS_MATCHES; REQUIRE_NOTHROW; CHECK; CHECK_FALSE; CHECKED_IF; CHECKED_ELSE; CHECK_NOFAIL; CHECK_THROWS; CHECK_THROWS_AS; CHECK_THROWS_WITH; CHECK_THROWS_MATCHES; CHECK_NOTHROW; REQUIRE_THAT; CHECK_THAT" ) - add_executable(DisabledMacros ${TESTS_DIR}/X02-DisabledMacros.cpp) -target_compile_definitions( DisabledMacros PRIVATE CATCH_CONFIG_DISABLE ) +target_compile_definitions(DisabledMacros PRIVATE CATCH_CONFIG_DISABLE) # Macro configuration does not touch the compiled parts, so we can link # it against the main library -target_link_libraries( DisabledMacros Catch2WithMain ) +target_link_libraries(DisabledMacros Catch2WithMain) add_test(NAME CATCH_CONFIG_DISABLE-1 COMMAND DisabledMacros -s) -set_tests_properties( - CATCH_CONFIG_DISABLE-1 +set_tests_properties(CATCH_CONFIG_DISABLE-1 PROPERTIES PASS_REGULAR_EXPRESSION "No tests ran" FAIL_REGULAR_EXPRESSION "This should not happen" ) add_test(NAME CATCH_CONFIG_DISABLE-2 COMMAND DisabledMacros --list-tests) -set_tests_properties( - CATCH_CONFIG_DISABLE-2 +set_tests_properties(CATCH_CONFIG_DISABLE-2 PROPERTIES PASS_REGULAR_EXPRESSION "0 test cases" ) -add_executable( DisabledExceptions-DefaultHandler ${TESTS_DIR}/X03-DisabledExceptions-DefaultHandler.cpp ) -add_executable( DisabledExceptions-CustomHandler ${TESTS_DIR}/X04-DisabledExceptions-CustomHandler.cpp ) +add_executable(DisabledExceptions-DefaultHandler ${TESTS_DIR}/X03-DisabledExceptions-DefaultHandler.cpp) +add_executable(DisabledExceptions-CustomHandler ${TESTS_DIR}/X04-DisabledExceptions-CustomHandler.cpp) foreach(target DisabledExceptions-DefaultHandler DisabledExceptions-CustomHandler) - target_compile_options( ${target} + target_compile_options(${target} PUBLIC $<$:/EHs-c-;/D_HAS_EXCEPTIONS=0> - $<$,$,$>:-fno-exceptions> + $<$,$,$,$>:-fno-exceptions> ) target_link_libraries(${target} Catch2_buildall_interface) endforeach() -target_compile_definitions( DisabledExceptions-CustomHandler PUBLIC CATCH_CONFIG_DISABLE_EXCEPTIONS_CUSTOM_HANDLER ) +target_compile_definitions(DisabledExceptions-CustomHandler PUBLIC CATCH_CONFIG_DISABLE_EXCEPTIONS_CUSTOM_HANDLER) add_test(NAME CATCH_CONFIG_DISABLE_EXCEPTIONS-1 COMMAND DisabledExceptions-DefaultHandler "Tests that run") -set_tests_properties( - CATCH_CONFIG_DISABLE_EXCEPTIONS-1 +set_tests_properties(CATCH_CONFIG_DISABLE_EXCEPTIONS-1 PROPERTIES PASS_REGULAR_EXPRESSION "assertions: 4 \| 2 passed \| 2 failed" FAIL_REGULAR_EXPRESSION "abort;terminate;fatal" ) -add_executable( BazelReporter ${TESTS_DIR}/X30-BazelReporter.cpp ) -target_compile_definitions( BazelReporter PRIVATE CATCH_CONFIG_BAZEL_SUPPORT ) -target_link_libraries(BazelReporter Catch2_buildall_interface) -add_test(NAME CATCH_CONFIG_BAZEL_REPORTER-1 - COMMAND - "${PYTHON_EXECUTABLE}" "${CATCH_DIR}/tests/TestScripts/testBazelReporter.py" $ "${CMAKE_CURRENT_BINARY_DIR}" -) -set_tests_properties(CATCH_CONFIG_BAZEL_REPORTER-1 - PROPERTIES - LABELS "uses-python" -) - # We must now test this works without the build flag. -add_executable( BazelReporterNoCatchConfig ${TESTS_DIR}/X30-BazelReporter.cpp ) +add_executable(BazelReporterNoCatchConfig ${TESTS_DIR}/X30-BazelReporter.cpp) target_link_libraries(BazelReporterNoCatchConfig Catch2WithMain) add_test(NAME NO_CATCH_CONFIG_BAZEL_REPORTER-1 COMMAND - "${PYTHON_EXECUTABLE}" "${CATCH_DIR}/tests/TestScripts/testBazelReporter.py" $ "${CMAKE_CURRENT_BINARY_DIR}" + Python3::Interpreter "${CATCH_DIR}/tests/TestScripts/testBazelReporter.py" $ "${CMAKE_CURRENT_BINARY_DIR}" ) set_tests_properties(NO_CATCH_CONFIG_BAZEL_REPORTER-1 PROPERTIES @@ -159,10 +132,9 @@ set_tests_properties(BazelEnv::TESTBRIDGE_TEST_ONLY PASS_REGULAR_EXPRESSION "All tests passed \\(1 assertion in 1 test case\\)" ) - add_test(NAME BazelEnv::Sharding COMMAND - "${PYTHON_EXECUTABLE}" "${CATCH_DIR}/tests/TestScripts/testBazelSharding.py" + Python3::Interpreter "${CATCH_DIR}/tests/TestScripts/testBazelSharding.py" $ "${CMAKE_CURRENT_BINARY_DIR}" ) @@ -171,87 +143,74 @@ set_tests_properties(BazelEnv::Sharding LABELS "uses-python" ) - # The default handler on Windows leads to the just-in-time debugger firing, # which makes this test unsuitable for CI and headless runs, as it opens # up an interactive dialog. -if (NOT WIN32) +if(NOT WIN32) add_test(NAME CATCH_CONFIG_DISABLE_EXCEPTIONS-2 COMMAND DisabledExceptions-DefaultHandler "Tests that abort") - set_tests_properties( - CATCH_CONFIG_DISABLE_EXCEPTIONS-2 + set_tests_properties(CATCH_CONFIG_DISABLE_EXCEPTIONS-2 PROPERTIES PASS_REGULAR_EXPRESSION "Catch will terminate" ) endif() - add_test(NAME CATCH_CONFIG_DISABLE_EXCEPTIONS-3 COMMAND DisabledExceptions-CustomHandler "Tests that run") -set_tests_properties( - CATCH_CONFIG_DISABLE_EXCEPTIONS-3 +set_tests_properties(CATCH_CONFIG_DISABLE_EXCEPTIONS-3 PROPERTIES PASS_REGULAR_EXPRESSION "assertions: 4 \| 2 passed \| 2 failed" FAIL_REGULAR_EXPRESSION "====== CUSTOM HANDLER ======" ) add_test(NAME CATCH_CONFIG_DISABLE_EXCEPTIONS-4 COMMAND DisabledExceptions-CustomHandler "Tests that abort") -set_tests_properties( - CATCH_CONFIG_DISABLE_EXCEPTIONS-4 +set_tests_properties(CATCH_CONFIG_DISABLE_EXCEPTIONS-4 PROPERTIES PASS_REGULAR_EXPRESSION "====== CUSTOM HANDLER ======" ) - add_executable(DeferredStaticChecks ${TESTS_DIR}/X05-DeferredStaticChecks.cpp) target_link_libraries(DeferredStaticChecks PRIVATE Catch2WithMain) target_compile_definitions(DeferredStaticChecks PRIVATE "CATCH_CONFIG_RUNTIME_STATIC_REQUIRE") add_test(NAME DeferredStaticChecks COMMAND DeferredStaticChecks -r compact) -set_tests_properties( - DeferredStaticChecks +set_tests_properties(DeferredStaticChecks PROPERTIES PASS_REGULAR_EXPRESSION "test cases: 1 \\| 1 failed\nassertions: 3 \\| 3 failed" ) - add_executable(FallbackStringifier ${TESTS_DIR}/X10-FallbackStringifier.cpp) -target_compile_definitions( FallbackStringifier PRIVATE CATCH_CONFIG_FALLBACK_STRINGIFIER=fallbackStringifier ) -target_link_libraries( FallbackStringifier Catch2WithMain ) +target_compile_definitions(FallbackStringifier PRIVATE CATCH_CONFIG_FALLBACK_STRINGIFIER=fallbackStringifier) +target_link_libraries(FallbackStringifier Catch2WithMain) add_test(NAME FallbackStringifier COMMAND FallbackStringifier -r compact -s) -set_tests_properties( - FallbackStringifier +set_tests_properties(FallbackStringifier PROPERTIES PASS_REGULAR_EXPRESSION "foo{} for: { !!! }" ) - add_executable(DisableStringification ${TESTS_DIR}/X11-DisableStringification.cpp) -target_compile_definitions( DisableStringification PRIVATE CATCH_CONFIG_DISABLE_STRINGIFICATION ) +target_compile_definitions(DisableStringification PRIVATE CATCH_CONFIG_DISABLE_STRINGIFICATION) target_link_libraries(DisableStringification Catch2WithMain) add_test(NAME CATCH_CONFIG_DISABLE_STRINGIFICATION COMMAND DisableStringification -r compact -s) -set_tests_properties( - CATCH_CONFIG_DISABLE_STRINGIFICATION +set_tests_properties(CATCH_CONFIG_DISABLE_STRINGIFICATION PROPERTIES PASS_REGULAR_EXPRESSION "Disabled by CATCH_CONFIG_DISABLE_STRINGIFICATION" FAIL_REGULAR_EXPRESSION "Hidden{} == Hidden{}" ) - # This test touches windows.h, so it should only be compiled under msvc -if (MSVC) - # This test fails if it does not compile and succeeds otherwise - add_executable(WindowsHeader ${TESTS_DIR}/X90-WindowsHeaderInclusion.cpp) - target_link_libraries( WindowsHeader Catch2WithMain ) - add_test(NAME WindowsHeader COMMAND WindowsHeader -r compact) - list(APPEND CATCH_WARNING_TARGETS ${EXTRA_TEST_BINARIES} WindowsHeader) +if(MSVC) + # This test fails if it does not compile and succeeds otherwise + add_executable(WindowsHeader ${TESTS_DIR}/X90-WindowsHeaderInclusion.cpp) + target_link_libraries(WindowsHeader Catch2WithMain) + add_test(NAME WindowsHeader COMMAND WindowsHeader -r compact) + list(APPEND CATCH_TEST_TARGETS ${EXTRA_TEST_BINARIES} WindowsHeader) endif() - add_executable(PartialTestCaseEvents ${TESTS_DIR}/X21-PartialTestCaseEvents.cpp) target_link_libraries(PartialTestCaseEvents PRIVATE Catch2WithMain) add_test( NAME PartialTestCaseEvents - COMMAND ${PYTHON_EXECUTABLE} ${CATCH_DIR}/tests/TestScripts/testPartialTestCaseEvent.py $ + COMMAND Python3::Interpreter ${CATCH_DIR}/tests/TestScripts/testPartialTestCaseEvent.py $ ) set_tests_properties(PartialTestCaseEvents PROPERTIES @@ -264,22 +223,19 @@ add_test( NAME BenchmarksInCumulativeReporter COMMAND BenchmarksInCumulativeReporter --reporter testReporter ) -set_tests_properties( - BenchmarksInCumulativeReporter +set_tests_properties(BenchmarksInCumulativeReporter PROPERTIES PASS_REGULAR_EXPRESSION "1\n2\n3\n4\n5\n" COST 30 ) - add_executable(CasingInReporterNames ${TESTS_DIR}/X23-CasingInReporterNames.cpp) target_link_libraries(CasingInReporterNames PRIVATE Catch2::Catch2WithMain) add_test( NAME Reporters::registration-is-case-preserving COMMAND CasingInReporterNames --list-reporters ) -set_tests_properties( - Reporters::registration-is-case-preserving +set_tests_properties(Reporters::registration-is-case-preserving PROPERTIES PASS_REGULAR_EXPRESSION "testReporterCASED" ) @@ -287,8 +243,7 @@ add_test( NAME Reporters::selection-is-case-insensitive COMMAND CasingInReporterNames -r testReportercased ) -set_tests_properties( - Reporters::selection-is-case-insensitive +set_tests_properties(Reporters::selection-is-case-insensitive PROPERTIES PASS_REGULAR_EXPRESSION "TestReporter constructed" ) @@ -300,15 +255,13 @@ add_test( COMMAND CapturedStdoutInTestCaseEvents --reporter test-reporter ) -set_tests_properties( - Reporters::CapturedStdOutInEvents +set_tests_properties(Reporters::CapturedStdOutInEvents PROPERTIES PASS_REGULAR_EXPRESSION "X27 - TestReporter constructed" FAIL_REGULAR_EXPRESSION "X27 ERROR" ) - -if (MSVC) +if(MSVC) set(_NullFile "NUL") else() set(_NullFile "/dev/null") @@ -320,7 +273,7 @@ target_link_libraries(ListenerStdoutCaptureInMultireporter PRIVATE Catch2::Catch # This test checks that there is nothing written out from the process, # but if CMake is running the tests under Valgrind or similar tool, then # that will write its own output to stdout and the test would fail. -if (NOT MEMORYCHECK_COMMAND) +if(NOT MEMORYCHECK_COMMAND) add_test( NAME MultiReporter::NoncapturingListenerDoesntCauseStdoutPassThrough COMMAND ListenerStdoutCaptureInMultireporter @@ -328,15 +281,13 @@ if (NOT MEMORYCHECK_COMMAND) --reporter junit::out=${_NullFile} ) - set_tests_properties( - MultiReporter::NoncapturingListenerDoesntCauseStdoutPassThrough + set_tests_properties(MultiReporter::NoncapturingListenerDoesntCauseStdoutPassThrough PROPERTIES PASS_REGULAR_EXPRESSION "X24 - NonCapturingListener initialized" FAIL_REGULAR_EXPRESSION "X24 - FooBarBaz" ) endif() - add_executable(ListenerCanAskForCapturedStdout ${TESTS_DIR}/X25-ListenerCanAskForCapturedStdout.cpp) target_link_libraries(ListenerCanAskForCapturedStdout PRIVATE Catch2::Catch2WithMain) add_test( @@ -345,8 +296,7 @@ add_test( --reporter compact::out=${_NullFile} --reporter console::out=${_NullFile} ) -set_tests_properties( - MultiReporter::CapturingListenerCausesStdoutCapture +set_tests_properties(MultiReporter::CapturingListenerCausesStdoutCapture PROPERTIES PASS_REGULAR_EXPRESSION "CapturingListener initialized" FAIL_REGULAR_EXPRESSION "X25 - ERROR" @@ -359,8 +309,7 @@ add_test( COMMAND ReporterPreferencesForPassingAssertionsIsRespected --reporter test-reporter ) -set_tests_properties( - Reporters::PreferencesForPassingAssertionsIsRespected +set_tests_properties(Reporters::PreferencesForPassingAssertionsIsRespected PROPERTIES PASS_REGULAR_EXPRESSION "X26 - TestReporter constructed" FAIL_REGULAR_EXPRESSION "X26 - assertionEnded" @@ -371,8 +320,7 @@ add_test( --reporter test-reporter --reporter console::out=${_NullFile} ) -set_tests_properties( - MultiReporter::PreferencesForPassingAssertionsIsRespected +set_tests_properties(MultiReporter::PreferencesForPassingAssertionsIsRespected PROPERTIES PASS_REGULAR_EXPRESSION "X26 - TestReporter constructed" FAIL_REGULAR_EXPRESSION "X26 - assertionEnded" @@ -384,8 +332,7 @@ add_test( NAME ListenersGetEventsBeforeReporters COMMAND ListenersGetEventsBeforeReporters --reporter test-reporter ) -set_tests_properties( - ListenersGetEventsBeforeReporters +set_tests_properties(ListenersGetEventsBeforeReporters PROPERTIES PASS_REGULAR_EXPRESSION "X28 - TestReporter constructed" FAIL_REGULAR_EXPRESSION "X28 - ERROR" @@ -398,21 +345,18 @@ add_test( COMMAND CustomArgumentsForReporters --reporter "test-reporter::Xa b=c 1::Xz:e = 1234" ) -set_tests_properties( - CustomArgumentsForReporters +set_tests_properties(CustomArgumentsForReporters PROPERTIES PASS_REGULAR_EXPRESSION "Xa b=c 1::Xz:e = 1234" ) - add_executable(DuplicatedTestCases-SameNameAndTags ${TESTS_DIR}/X31-DuplicatedTestCases.cpp) target_link_libraries(DuplicatedTestCases-SameNameAndTags PRIVATE Catch2::Catch2WithMain) add_test( NAME DuplicatedTestCases::SameNameAndTags COMMAND $ ) -set_tests_properties( - DuplicatedTestCases::SameNameAndTags +set_tests_properties(DuplicatedTestCases::SameNameAndTags PROPERTIES PASS_REGULAR_EXPRESSION "error: .* already defined\\." ) @@ -423,8 +367,7 @@ add_test( NAME DuplicatedTestCases::SameNameDifferentTags COMMAND $ ) -set_tests_properties( - DuplicatedTestCases::SameNameDifferentTags +set_tests_properties(DuplicatedTestCases::SameNameDifferentTags PROPERTIES FAIL_REGULAR_EXPRESSION "error: .* already defined\\." ) @@ -435,8 +378,7 @@ add_test( NAME DuplicatedTestCases::DuplicatedTestCaseMethods COMMAND $ ) -set_tests_properties( - DuplicatedTestCases::DuplicatedTestCaseMethods +set_tests_properties(DuplicatedTestCases::DuplicatedTestCaseMethods PROPERTIES PASS_REGULAR_EXPRESSION "error: .* already defined\\." ) @@ -447,21 +389,18 @@ add_test( NAME DuplicatedTestCases::DuplicatedTestCaseMethodsDifferentFixtures COMMAND $ ) -set_tests_properties( - DuplicatedTestCases::DuplicatedTestCaseMethodsDifferentFixtures +set_tests_properties(DuplicatedTestCases::DuplicatedTestCaseMethodsDifferentFixtures PROPERTIES FAIL_REGULAR_EXPRESSION "error: .* already defined\\." ) - add_executable(DuplicatedReporters ${TESTS_DIR}/X35-DuplicatedReporterNames.cpp) target_link_libraries(DuplicatedReporters PRIVATE Catch2::Catch2WithMain) add_test( NAME Reporters::RegistrationErrorsAreCaught COMMAND $ ) -set_tests_properties( - Reporters::RegistrationErrorsAreCaught +set_tests_properties(Reporters::RegistrationErrorsAreCaught PROPERTIES PASS_REGULAR_EXPRESSION "Errors occurred during startup!" ) @@ -472,13 +411,56 @@ add_test( NAME Reporters::CrashInJunitReporter COMMAND ${CMAKE_COMMAND} -E env $ --reporter JUnit ) -set_tests_properties( - Reporters::CrashInJunitReporter +set_tests_properties(Reporters::CrashInJunitReporter PROPERTIES PASS_REGULAR_EXPRESSION "" LABELS "uses-signals" ) + +add_executable(QuickExitInTest ${TESTS_DIR}/X40-QuickExit.cpp) +target_link_libraries(QuickExitInTest PRIVATE Catch2::Catch2WithMain) +add_test( + NAME BazelEnv::TEST_PREMATURE_EXIT_FILE + COMMAND + Python3::Interpreter + "${CATCH_DIR}/tests/TestScripts/testBazelExitGuardFile.py" + $ + "${CMAKE_CURRENT_BINARY_DIR}" + "bazel" +) +set_tests_properties(BazelEnv::TEST_PREMATURE_EXIT_FILE + PROPERTIES + LABELS "uses-python" +) +add_test( + NAME PrematureExitGuardFileCanBeUsedFromCLI::CheckAfterCrash + COMMAND + Python3::Interpreter + "${CATCH_DIR}/tests/TestScripts/testBazelExitGuardFile.py" + $ + "${CMAKE_CURRENT_BINARY_DIR}" + "cli" +) +set_tests_properties(PrematureExitGuardFileCanBeUsedFromCLI::CheckAfterCrash + PROPERTIES + LABELS "uses-python" +) +add_test( + NAME PrematureExitGuardFileCanBeUsedFromCLI::CheckWithoutCrash + COMMAND + Python3::Interpreter + "${CATCH_DIR}/tests/TestScripts/testBazelExitGuardFile.py" + $ + "${CMAKE_CURRENT_BINARY_DIR}" + "no-crash" +) +set_tests_properties(PrematureExitGuardFileCanBeUsedFromCLI::CheckWithoutCrash + PROPERTIES + LABELS "uses-python" +) + + add_executable(AssertionStartingEventGoesBeforeAssertionIsEvaluated X20-AssertionStartingEventGoesBeforeAssertionIsEvaluated.cpp ) @@ -493,8 +475,7 @@ add_test( #add_executable(DebugBreakMacros ${TESTS_DIR}/X12-CustomDebugBreakMacro.cpp) #target_link_libraries(DebugBreakMacros Catch2) #add_test(NAME DebugBreakMacros COMMAND DebugBreakMacros --break) -#set_tests_properties( -# DebugBreakMacros +#set_tests_properties(DebugBreakMacros # PROPERTIES # PASS_REGULAR_EXPRESSION "Pretty please, break into debugger" #) @@ -521,7 +502,6 @@ add_test( COMMAND $ --list-listeners ) - add_executable(AllSkipped ${TESTS_DIR}/X93-AllSkipped.cpp) target_link_libraries(AllSkipped PRIVATE Catch2::Catch2WithMain) @@ -534,29 +514,28 @@ set_tests_properties(TestSpecs::SkippingAllTestsFails WILL_FAIL ON ) -set( EXTRA_TEST_BINARIES - AllSkipped - PrefixedMacros - DisabledMacros - DisabledExceptions-DefaultHandler - DisabledExceptions-CustomHandler - FallbackStringifier - DisableStringification - PartialTestCaseEvents - DuplicatedTestCases-SameNameAndTags - DuplicatedTestCases-SameNameDifferentTags - DuplicatedTestCases-DuplicatedTestCaseMethods - NoTests - ListenersGetEventsBeforeReporters -# DebugBreakMacros +set(EXTRA_TEST_BINARIES + AllSkipped + PrefixedMacros + DisabledMacros + DisabledExceptions-DefaultHandler + DisabledExceptions-CustomHandler + FallbackStringifier + DisableStringification + PartialTestCaseEvents + DuplicatedTestCases-SameNameAndTags + DuplicatedTestCases-SameNameDifferentTags + DuplicatedTestCases-DuplicatedTestCaseMethods + NoTests + ListenersGetEventsBeforeReporters +# DebugBreakMacros ) # Notice that we are modifying EXTRA_TEST_BINARIES destructively, do not # use it after this point! list(FILTER EXTRA_TEST_BINARIES EXCLUDE REGEX "DisabledExceptions.*") -list(APPEND CATCH_WARNING_TARGETS ${EXTRA_TEST_BINARIES}) -set(CATCH_WARNING_TARGETS ${CATCH_WARNING_TARGETS} PARENT_SCOPE) - +list(APPEND CATCH_TEST_TARGETS ${EXTRA_TEST_BINARIES}) +set(CATCH_TEST_TARGETS ${CATCH_TEST_TARGETS} PARENT_SCOPE) # This sets up a one-off executable that compiles against the amalgamated # files, and then runs it for a super simple check that the amalgamated @@ -570,8 +549,7 @@ target_include_directories(AmalgamatedTestCompilation PRIVATE ${CATCH_DIR}/extra target_compile_features(AmalgamatedTestCompilation PRIVATE cxx_std_14) add_test(NAME AmalgamatedFileTest COMMAND AmalgamatedTestCompilation) -set_tests_properties( - AmalgamatedFileTest +set_tests_properties(AmalgamatedFileTest PROPERTIES PASS_REGULAR_EXPRESSION "All tests passed \\(14 assertions in 3 test cases\\)" ) diff --git a/catch2/tests/ExtraTests/X40-QuickExit.cpp b/catch2/tests/ExtraTests/X40-QuickExit.cpp new file mode 100644 index 0000000..3afb7b5 --- /dev/null +++ b/catch2/tests/ExtraTests/X40-QuickExit.cpp @@ -0,0 +1,28 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +/**\file + * Call ~~quick_exit~~ inside a test. + * + * This is used to test whether Catch2 properly creates the crash guard + * file based on provided arguments. + */ + +#include + +#include + +TEST_CASE("quick_exit", "[quick_exit]") { + // Return 0 as fake "successful" exit, while there should be a guard + // file created and kept. + std::exit(0); + // We cannot use quick_exit because libstdc++ on older MacOS versions didn't support it yet. + // std::quick_exit(0); +} + +TEST_CASE("pass") {} diff --git a/catch2/tests/SelfTest/Baselines/automake.sw.approved.txt b/catch2/tests/SelfTest/Baselines/automake.sw.approved.txt index 7be343a..4a6886d 100644 --- a/catch2/tests/SelfTest/Baselines/automake.sw.approved.txt +++ b/catch2/tests/SelfTest/Baselines/automake.sw.approved.txt @@ -26,6 +26,7 @@ Nor would this :test-result: PASS #2152 - ULP checks between differently signed values were wrong - double :test-result: PASS #2152 - ULP checks between differently signed values were wrong - float :test-result: XFAIL #2615 - Throwing in constructor generator fails test case but does not abort +:test-result: PASS #3001: Enum-based bitfields can be captured :test-result: XFAIL #748 - captures with unexpected exceptions :test-result: PASS #809 :test-result: PASS #833 @@ -95,6 +96,8 @@ Nor would this :test-result: PASS Approximate comparisons with mixed numeric types :test-result: PASS Arbitrary predicate matcher :test-result: PASS Assertion macros support bit operators and bool conversions +:test-result: XFAIL Assertions can be nested - CHECK +:test-result: XFAIL Assertions can be nested - REQUIRE :test-result: PASS Assertions then sections :test-result: PASS Basic use of the Contains range matcher :test-result: PASS Basic use of the Empty range matcher @@ -102,6 +105,8 @@ Nor would this :test-result: PASS CAPTURE can deal with complex expressions involving commas :test-result: PASS CAPTURE parses string and character constants :test-result: PASS Capture and info messages +:test-result: FAIL Captures do not leave block with an exception +:test-result: FAIL Captures outlive section end :test-result: PASS CaseInsensitiveEqualsTo is case insensitive :test-result: PASS CaseInsensitiveLess is case insensitive :test-result: PASS Character pretty printing @@ -117,6 +122,7 @@ Nor would this :test-result: PASS Combining templated and concrete matchers :test-result: PASS Combining templated matchers :test-result: PASS Commas in various macros are allowed +:test-result: PASS Comparing (and stringifying) volatile pointers works :test-result: PASS Comparing function pointers :test-result: PASS Comparison ops :test-result: PASS Comparison with explicitly convertible types @@ -148,9 +154,11 @@ Nor would this :test-result: PASS Exception matchers that succeed :test-result: PASS Exception message can be matched :test-result: PASS Exception messages can be tested for +:test-result: PASS Exception thrown inside stringify does not fail the test :test-result: PASS Exceptions matchers :test-result: FAIL Expected exceptions that don't throw or unexpected exceptions fail the test :test-result: FAIL FAIL aborts the test +:test-result: XFAIL FAIL can be nested in assertion :test-result: FAIL FAIL does not require an argument :test-result: FAIL FAIL_CHECK does not abort the test :test-result: PASS Factorials are computed @@ -175,7 +183,7 @@ Nor would this :test-result: XFAIL Inequality checks that should fail :test-result: PASS Inequality checks that should succeed :test-result: PASS JsonWriter -:test-result: PASS JsonWriter escapes charaters in strings properly +:test-result: PASS JsonWriter escapes characters in strings properly :test-result: PASS Lambdas in assertions :test-result: PASS Less-than inequalities with different epsilons :test-result: PASS ManuallyRegistered @@ -226,6 +234,9 @@ Nor would this :test-result: PASS Scenario: Do that thing with the thing :test-result: PASS Scenario: This is a really long scenario name to see how the list command deals with wrapping :test-result: PASS Scenario: Vector resizing affects size and capacity +:test-result: FAIL Scoped message applies to all assertions in scope +:test-result: FAIL Scoped messages do not leave block with an exception +:test-result: FAIL Scoped messages outlive section end A string sent directly to stdout A string sent directly to stderr A string sent to stderr via clog @@ -262,6 +273,10 @@ Message from section two :test-result: PASS TemplateTest: vectors can be sized and resized - int :test-result: PASS TemplateTest: vectors can be sized and resized - std::string :test-result: PASS TemplateTest: vectors can be sized and resized - std::tuple +:test-result: FAIL TemplateTestSig: compiles with a single int parameter - 1 +:test-result: FAIL TemplateTestSig: compiles with a single int parameter - 3 +:test-result: FAIL TemplateTestSig: compiles with a single int parameter - 6 +:test-result: FAIL TemplateTestSig: compiles with two type parameters - int,int :test-result: PASS TemplateTestSig: vectors can be sized and resized - (std::tuple), 6 :test-result: PASS TemplateTestSig: vectors can be sized and resized - float,4 :test-result: PASS TemplateTestSig: vectors can be sized and resized - int,5 @@ -399,6 +414,7 @@ b1! :test-result: PASS stringify( vectors ) :test-result: PASS stringify( vectors ) :test-result: PASS strlen3 +:test-result: PASS system_clock timepoint with non-default duration :test-result: PASS tables :test-result: PASS tags with dots in later positions are not parsed as hidden :test-result: SKIP tests can be skipped dynamically at runtime diff --git a/catch2/tests/SelfTest/Baselines/automake.sw.multi.approved.txt b/catch2/tests/SelfTest/Baselines/automake.sw.multi.approved.txt index 0cd24e4..b0d30b8 100644 --- a/catch2/tests/SelfTest/Baselines/automake.sw.multi.approved.txt +++ b/catch2/tests/SelfTest/Baselines/automake.sw.multi.approved.txt @@ -24,6 +24,7 @@ :test-result: PASS #2152 - ULP checks between differently signed values were wrong - double :test-result: PASS #2152 - ULP checks between differently signed values were wrong - float :test-result: XFAIL #2615 - Throwing in constructor generator fails test case but does not abort +:test-result: PASS #3001: Enum-based bitfields can be captured :test-result: XFAIL #748 - captures with unexpected exceptions :test-result: PASS #809 :test-result: PASS #833 @@ -93,6 +94,8 @@ :test-result: PASS Approximate comparisons with mixed numeric types :test-result: PASS Arbitrary predicate matcher :test-result: PASS Assertion macros support bit operators and bool conversions +:test-result: XFAIL Assertions can be nested - CHECK +:test-result: XFAIL Assertions can be nested - REQUIRE :test-result: PASS Assertions then sections :test-result: PASS Basic use of the Contains range matcher :test-result: PASS Basic use of the Empty range matcher @@ -100,6 +103,8 @@ :test-result: PASS CAPTURE can deal with complex expressions involving commas :test-result: PASS CAPTURE parses string and character constants :test-result: PASS Capture and info messages +:test-result: FAIL Captures do not leave block with an exception +:test-result: FAIL Captures outlive section end :test-result: PASS CaseInsensitiveEqualsTo is case insensitive :test-result: PASS CaseInsensitiveLess is case insensitive :test-result: PASS Character pretty printing @@ -115,6 +120,7 @@ :test-result: PASS Combining templated and concrete matchers :test-result: PASS Combining templated matchers :test-result: PASS Commas in various macros are allowed +:test-result: PASS Comparing (and stringifying) volatile pointers works :test-result: PASS Comparing function pointers :test-result: PASS Comparison ops :test-result: PASS Comparison with explicitly convertible types @@ -146,9 +152,11 @@ :test-result: PASS Exception matchers that succeed :test-result: PASS Exception message can be matched :test-result: PASS Exception messages can be tested for +:test-result: PASS Exception thrown inside stringify does not fail the test :test-result: PASS Exceptions matchers :test-result: FAIL Expected exceptions that don't throw or unexpected exceptions fail the test :test-result: FAIL FAIL aborts the test +:test-result: XFAIL FAIL can be nested in assertion :test-result: FAIL FAIL does not require an argument :test-result: FAIL FAIL_CHECK does not abort the test :test-result: PASS Factorials are computed @@ -173,7 +181,7 @@ :test-result: XFAIL Inequality checks that should fail :test-result: PASS Inequality checks that should succeed :test-result: PASS JsonWriter -:test-result: PASS JsonWriter escapes charaters in strings properly +:test-result: PASS JsonWriter escapes characters in strings properly :test-result: PASS Lambdas in assertions :test-result: PASS Less-than inequalities with different epsilons :test-result: PASS ManuallyRegistered @@ -224,6 +232,9 @@ :test-result: PASS Scenario: Do that thing with the thing :test-result: PASS Scenario: This is a really long scenario name to see how the list command deals with wrapping :test-result: PASS Scenario: Vector resizing affects size and capacity +:test-result: FAIL Scoped message applies to all assertions in scope +:test-result: FAIL Scoped messages do not leave block with an exception +:test-result: FAIL Scoped messages outlive section end :test-result: FAIL Sends stuff to stdout and stderr :test-result: PASS Some simple comparisons between doubles :test-result: FAIL Standard output from all sections is reported @@ -255,6 +266,10 @@ :test-result: PASS TemplateTest: vectors can be sized and resized - int :test-result: PASS TemplateTest: vectors can be sized and resized - std::string :test-result: PASS TemplateTest: vectors can be sized and resized - std::tuple +:test-result: FAIL TemplateTestSig: compiles with a single int parameter - 1 +:test-result: FAIL TemplateTestSig: compiles with a single int parameter - 3 +:test-result: FAIL TemplateTestSig: compiles with a single int parameter - 6 +:test-result: FAIL TemplateTestSig: compiles with two type parameters - int,int :test-result: PASS TemplateTestSig: vectors can be sized and resized - (std::tuple), 6 :test-result: PASS TemplateTestSig: vectors can be sized and resized - float,4 :test-result: PASS TemplateTestSig: vectors can be sized and resized - int,5 @@ -388,6 +403,7 @@ :test-result: PASS stringify( vectors ) :test-result: PASS stringify( vectors ) :test-result: PASS strlen3 +:test-result: PASS system_clock timepoint with non-default duration :test-result: PASS tables :test-result: PASS tags with dots in later positions are not parsed as hidden :test-result: SKIP tests can be skipped dynamically at runtime diff --git a/catch2/tests/SelfTest/Baselines/compact.sw.approved.txt b/catch2/tests/SelfTest/Baselines/compact.sw.approved.txt index b7f48cb..cacb898 100644 --- a/catch2/tests/SelfTest/Baselines/compact.sw.approved.txt +++ b/catch2/tests/SelfTest/Baselines/compact.sw.approved.txt @@ -84,8 +84,10 @@ Matchers.tests.cpp:: passed: smallest_non_zero, WithinULP( -smalles Matchers.tests.cpp:: passed: smallest_non_zero, !WithinULP( -smallest_non_zero, 1 ) for: 0.0 not is within 1 ULPs of -4.9406564584124654e-324 ([-9.8813129168249309e-324, -0.0000000000000000e+00]) Matchers.tests.cpp:: passed: smallest_non_zero, WithinULP( -smallest_non_zero, 2 ) for: 0.0f is within 2 ULPs of -1.40129846e-45f ([-4.20389539e-45, 1.40129846e-45]) Matchers.tests.cpp:: passed: smallest_non_zero, !WithinULP( -smallest_non_zero, 1 ) for: 0.0f not is within 1 ULPs of -1.40129846e-45f ([-2.80259693e-45, -0.00000000e+00]) -Generators.tests.cpp:: failed: unexpected exception with message: 'failure to init' -Exception.tests.cpp:: failed: unexpected exception with message: 'answer := 42' with 1 message: 'expected exception' +Generators.tests.cpp:: failed: unexpected exception with message: 'failure to init'; expression was: {Unknown expression after the reported line} +Compilation.tests.cpp:: passed: bf.e == 1 for: 1 == 1 +Compilation.tests.cpp:: passed: 1 == bf.e for: 1 == 1 +Exception.tests.cpp:: failed: unexpected exception with message: 'expected exception'; expression was: {Unknown expression after the reported line} Exception.tests.cpp:: failed: unexpected exception with message: 'answer := 42'; expression was: thisThrows() with 1 message: 'expected exception' Exception.tests.cpp:: passed: thisThrows() with 1 message: 'answer := 42' Compilation.tests.cpp:: passed: 42 == f for: 42 == {?} @@ -332,6 +334,11 @@ Compilation.tests.cpp:: passed: !(lhs & rhs) for: !(Val: 1 & Val: 2 Compilation.tests.cpp:: passed: HasBitOperators{ 1 } & HasBitOperators{ 1 } for: Val: 1 & Val: 1 Compilation.tests.cpp:: passed: lhs ^ rhs for: Val: 1 ^ Val: 2 Compilation.tests.cpp:: passed: !(lhs ^ lhs) for: !(Val: 1 ^ Val: 1) +AssertionHandler.tests.cpp:: failed: i > 10 for: 2 > 10 +AssertionHandler.tests.cpp:: failed: unexpected exception with message: '{ nested assertion failed }'; expression was: foo( 2 ) == 2 +AssertionHandler.tests.cpp:: passed: true +AssertionHandler.tests.cpp:: failed: i > 10 for: 2 > 10 +AssertionHandler.tests.cpp:: failed: unexpected exception with message: '{ nested assertion failed }'; expression was: foo( 2 ) == 2 Tricky.tests.cpp:: passed: true Tricky.tests.cpp:: passed: true Tricky.tests.cpp:: passed: true @@ -363,6 +370,9 @@ Message.tests.cpp:: passed: with 7 messages: 'custom_index_op{ Message.tests.cpp:: passed: with 11 messages: '("comma, in string", "escaped, \", ") := "escaped, ", "' and '"single quote in string,'," := "single quote in string,',"' and '"some escapes, \\,\\\\" := "some escapes, \,\\"' and '"some, ), unmatched, } prenheses {[<" := "some, ), unmatched, } prenheses {[<"' and ''"' := '"'' and ''\'' := '''' and '',' := ','' and ''}' := '}'' and '')' := ')'' and ''(' := '('' and ''{' := '{'' ToStringGeneral.tests.cpp:: passed: true with 1 message: 'i := 2' ToStringGeneral.tests.cpp:: passed: true with 1 message: '3' +Message.tests.cpp:: failed: false with 1 message: 'a := 1' +Message.tests.cpp:: passed: true with 1 message: 'a := 1' +Message.tests.cpp:: failed: false with 1 message: 'a := 1' Details.tests.cpp:: passed: eq( "", "" ) for: true Details.tests.cpp:: passed: !(eq( "", "a" )) for: !false Details.tests.cpp:: passed: eq( "a", "a" ) for: true @@ -473,6 +483,13 @@ Tricky.tests.cpp:: passed: std::vector{1, 2} == std::vector: passed: std::vector{1, 2} == std::vector{1, 2} for: { 1, 2 } == { 1, 2 } Tricky.tests.cpp:: passed: true Tricky.tests.cpp:: passed: std::vector{1, 2} == std::vector{1, 2} for: { 1, 2 } == { 1, 2 } +Misc.tests.cpp:: passed: !(ptr) for: !0 +Misc.tests.cpp:: passed: ptr == ptr for: 0 == 0 +Misc.tests.cpp:: passed: !(ptr != ptr) for: !(0 != 0) +Misc.tests.cpp:: passed: !(ptr < ptr) for: !(0 < 0) +Misc.tests.cpp:: passed: ptr <= ptr for: 0 <= 0 +Misc.tests.cpp:: passed: !(ptr > ptr) for: !(0 > 0) +Misc.tests.cpp:: passed: ptr >= ptr for: 0 >= 0 Tricky.tests.cpp:: passed: a for: 0x Tricky.tests.cpp:: passed: a == &foo for: 0x == 0x RandomNumberGeneration.tests.cpp:: passed: SimplePcg32{} == SimplePcg32{} for: {?} == {?} @@ -625,6 +642,9 @@ Exception.tests.cpp:: passed: thisThrows(), StartsWith( "expected" Exception.tests.cpp:: passed: thisThrows(), EndsWith( "exception" ) for: "expected exception" ends with: "exception" Exception.tests.cpp:: passed: thisThrows(), ContainsSubstring( "except" ) for: "expected exception" contains: "except" Exception.tests.cpp:: passed: thisThrows(), ContainsSubstring( "exCept", Catch::CaseSensitive::No ) for: "expected exception" contains: "except" (case insensitive) +ToString.tests.cpp:: passed: tos == tos for: { stringification failed with an exception: "Invalid" } +== +{ stringification failed with an exception: "Invalid" } Matchers.tests.cpp:: passed: throwsDerivedException(), DerivedException, Message( "DerivedException::what" ) for: DerivedException::what exception message matches "DerivedException::what" Matchers.tests.cpp:: passed: throwsDerivedException(), DerivedException, !Message( "derivedexception::what" ) for: DerivedException::what not exception message matches "derivedexception::what" Matchers.tests.cpp:: passed: throwsSpecialException( 2 ), SpecialException, !Message( "DerivedException::what" ) for: SpecialException::what not exception message matches "DerivedException::what" @@ -633,6 +653,8 @@ Exception.tests.cpp:: failed: unexpected exception with message: 'e Exception.tests.cpp:: failed: expected exception, got none; expression was: thisDoesntThrow(), std::domain_error Exception.tests.cpp:: failed: unexpected exception with message: 'expected exception'; expression was: thisThrows() Message.tests.cpp:: failed: explicitly with 1 message: 'This is a failure' +AssertionHandler.tests.cpp:: failed: explicitly with 1 message: 'Throw a Catch::TestFailureException' +AssertionHandler.tests.cpp:: failed: unexpected exception with message: '{ nested assertion failed }'; expression was: do_fail() Message.tests.cpp:: failed: explicitly Message.tests.cpp:: failed: explicitly with 1 message: 'This is a failure' Message.tests.cpp:: warning: 'This message appears in the output' @@ -802,6 +824,10 @@ GeneratorsImpl.tests.cpp:: passed: filter([](int) { return false; } GeneratorsImpl.tests.cpp:: passed: filter([](int) { return false; }, values({ 1, 2, 3 })), Catch::GeneratorException GeneratorsImpl.tests.cpp:: passed: gen.get() == 1 for: 1 == 1 GeneratorsImpl.tests.cpp:: passed: gen.next() for: true +GeneratorsImpl.tests.cpp:: passed: gen.get() == 3 for: 3 == 3 +GeneratorsImpl.tests.cpp:: passed: !(gen.next()) for: !false +GeneratorsImpl.tests.cpp:: passed: gen.get() == 1 for: 1 == 1 +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true GeneratorsImpl.tests.cpp:: passed: gen.get() == 2 for: 2 == 2 GeneratorsImpl.tests.cpp:: passed: !(gen.next()) for: !false GeneratorsImpl.tests.cpp:: passed: gen.get() == 1 for: 1 == 1 @@ -1732,6 +1758,11 @@ BDD.tests.cpp:: passed: v.capacity() >= 10 for: 10 >= 10 BDD.tests.cpp:: passed: v.size() == 0 for: 0 == 0 BDD.tests.cpp:: passed: v.capacity() >= 10 for: 10 >= 10 BDD.tests.cpp:: passed: v.size() == 0 for: 0 == 0 +Message.tests.cpp:: failed: false with 1 message: 'This will be reported multiple times' +Message.tests.cpp:: failed: false with 1 message: 'This will be reported multiple times' +Message.tests.cpp:: failed: false with 1 message: 'Should be in scope at the end' +Message.tests.cpp:: passed: true with 1 message: 'Should survive a section end' +Message.tests.cpp:: failed: false with 1 message: 'Should survive a section end' A string sent directly to stdout A string sent directly to stderr A string sent to stderr via clog @@ -2392,7 +2423,7 @@ Exception.tests.cpp:: failed: unexpected exception with message: 'u Exception.tests.cpp:: failed: unexpected exception with message: 'expected exception'; expression was: thisThrows() == 0 Exception.tests.cpp:: failed: unexpected exception with message: 'expected exception'; expression was: thisThrows() == 0 Exception.tests.cpp:: failed: unexpected exception with message: 'expected exception'; expression was: thisThrows() == 0 -Exception.tests.cpp:: failed: unexpected exception with message: 'unexpected exception' +Exception.tests.cpp:: failed: unexpected exception with message: 'unexpected exception'; expression was: {Unknown expression after the reported line} Tricky.tests.cpp:: passed: Tricky.tests.cpp:: passed: Tricky.tests.cpp:: passed: @@ -2534,18 +2565,18 @@ Skip.tests.cpp:: skipped: Skip.tests.cpp:: skipped: Skip.tests.cpp:: failed: explicitly loose text artifact -Clara.tests.cpp:: passed: with 1 message: 'Catch::Clara::Detail::is_unary_function::value' -Clara.tests.cpp:: passed: with 1 message: 'Catch::Clara::Detail::is_unary_function::value' -Clara.tests.cpp:: passed: with 1 message: 'Catch::Clara::Detail::is_unary_function::value' -Clara.tests.cpp:: passed: with 1 message: 'Catch::Clara::Detail::is_unary_function::value' -Clara.tests.cpp:: passed: with 1 message: 'Catch::Clara::Detail::is_unary_function::value' -Clara.tests.cpp:: passed: with 1 message: 'Catch::Clara::Detail::is_unary_function::value' -Clara.tests.cpp:: passed: with 1 message: '!(Catch::Clara::Detail::is_unary_function::value)' -Clara.tests.cpp:: passed: with 1 message: '!(Catch::Clara::Detail::is_unary_function::value)' -Clara.tests.cpp:: passed: with 1 message: '!(Catch::Clara::Detail::is_unary_function::value)' -Clara.tests.cpp:: passed: with 1 message: '!(Catch::Clara::Detail::is_unary_function::value)' -Clara.tests.cpp:: passed: with 1 message: '!(Catch::Clara::Detail::is_unary_function::value)' -Clara.tests.cpp:: passed: with 1 message: '!(Catch::Clara::Detail::is_unary_function::value)' +Clara.tests.cpp:: passed: with 1 message: 'Catch::Clara::Detail::is_unary_function_v' +Clara.tests.cpp:: passed: with 1 message: 'Catch::Clara::Detail::is_unary_function_v' +Clara.tests.cpp:: passed: with 1 message: 'Catch::Clara::Detail::is_unary_function_v' +Clara.tests.cpp:: passed: with 1 message: 'Catch::Clara::Detail::is_unary_function_v' +Clara.tests.cpp:: passed: with 1 message: 'Catch::Clara::Detail::is_unary_function_v' +Clara.tests.cpp:: passed: with 1 message: 'Catch::Clara::Detail::is_unary_function_v' +Clara.tests.cpp:: passed: with 1 message: '!(Catch::Clara::Detail::is_unary_function_v)' +Clara.tests.cpp:: passed: with 1 message: '!(Catch::Clara::Detail::is_unary_function_v)' +Clara.tests.cpp:: passed: with 1 message: '!(Catch::Clara::Detail::is_unary_function_v)' +Clara.tests.cpp:: passed: with 1 message: '!(Catch::Clara::Detail::is_unary_function_v)' +Clara.tests.cpp:: passed: with 1 message: '!(Catch::Clara::Detail::is_unary_function_v)' +Clara.tests.cpp:: passed: with 1 message: '!(Catch::Clara::Detail::is_unary_function_v)' Message.tests.cpp:: failed: explicitly with 1 message: 'Previous info should not be seen' Message.tests.cpp:: failed: explicitly with 1 message: 'previous unscoped info SHOULD not be seen' Misc.tests.cpp:: passed: l == std::numeric_limits::max() for: 9223372036854775807 (0x) @@ -2749,6 +2780,9 @@ Generators.tests.cpp:: passed: data.str.size() == data.len for: 3 = Generators.tests.cpp:: passed: data.str.size() == data.len for: 3 == 3 Generators.tests.cpp:: passed: data.str.size() == data.len for: 5 == 5 Generators.tests.cpp:: passed: data.str.size() == data.len for: 4 == 4 +ToStringChrono.tests.cpp:: passed: tp1 == tp2 for: {iso8601-timestamp} +== +{iso8601-timestamp} Generators.tests.cpp:: passed: strlen(std::get<0>(data)) == static_cast(std::get<1>(data)) for: 5 == 5 Generators.tests.cpp:: passed: strlen(std::get<0>(data)) == static_cast(std::get<1>(data)) for: 6 == 6 Generators.tests.cpp:: passed: strlen(std::get<0>(data)) == static_cast(std::get<1>(data)) for: 5 == 5 @@ -2854,7 +2888,7 @@ InternalBenchmark.tests.cpp:: passed: med == 18. for: 18.0 == 18.0 InternalBenchmark.tests.cpp:: passed: q3 == 23. for: 23.0 == 23.0 Misc.tests.cpp:: passed: Misc.tests.cpp:: passed: -test cases: 419 | 313 passed | 86 failed | 6 skipped | 14 failed as expected -assertions: 2269 | 2087 passed | 147 failed | 35 failed as expected +test cases: 435 | 317 passed | 95 failed | 6 skipped | 17 failed as expected +assertions: 2303 | 2105 passed | 157 failed | 41 failed as expected diff --git a/catch2/tests/SelfTest/Baselines/compact.sw.multi.approved.txt b/catch2/tests/SelfTest/Baselines/compact.sw.multi.approved.txt index 9e3e537..10395c9 100644 --- a/catch2/tests/SelfTest/Baselines/compact.sw.multi.approved.txt +++ b/catch2/tests/SelfTest/Baselines/compact.sw.multi.approved.txt @@ -82,8 +82,10 @@ Matchers.tests.cpp:: passed: smallest_non_zero, WithinULP( -smalles Matchers.tests.cpp:: passed: smallest_non_zero, !WithinULP( -smallest_non_zero, 1 ) for: 0.0 not is within 1 ULPs of -4.9406564584124654e-324 ([-9.8813129168249309e-324, -0.0000000000000000e+00]) Matchers.tests.cpp:: passed: smallest_non_zero, WithinULP( -smallest_non_zero, 2 ) for: 0.0f is within 2 ULPs of -1.40129846e-45f ([-4.20389539e-45, 1.40129846e-45]) Matchers.tests.cpp:: passed: smallest_non_zero, !WithinULP( -smallest_non_zero, 1 ) for: 0.0f not is within 1 ULPs of -1.40129846e-45f ([-2.80259693e-45, -0.00000000e+00]) -Generators.tests.cpp:: failed: unexpected exception with message: 'failure to init' -Exception.tests.cpp:: failed: unexpected exception with message: 'answer := 42' with 1 message: 'expected exception' +Generators.tests.cpp:: failed: unexpected exception with message: 'failure to init'; expression was: {Unknown expression after the reported line} +Compilation.tests.cpp:: passed: bf.e == 1 for: 1 == 1 +Compilation.tests.cpp:: passed: 1 == bf.e for: 1 == 1 +Exception.tests.cpp:: failed: unexpected exception with message: 'expected exception'; expression was: {Unknown expression after the reported line} Exception.tests.cpp:: failed: unexpected exception with message: 'answer := 42'; expression was: thisThrows() with 1 message: 'expected exception' Exception.tests.cpp:: passed: thisThrows() with 1 message: 'answer := 42' Compilation.tests.cpp:: passed: 42 == f for: 42 == {?} @@ -330,6 +332,11 @@ Compilation.tests.cpp:: passed: !(lhs & rhs) for: !(Val: 1 & Val: 2 Compilation.tests.cpp:: passed: HasBitOperators{ 1 } & HasBitOperators{ 1 } for: Val: 1 & Val: 1 Compilation.tests.cpp:: passed: lhs ^ rhs for: Val: 1 ^ Val: 2 Compilation.tests.cpp:: passed: !(lhs ^ lhs) for: !(Val: 1 ^ Val: 1) +AssertionHandler.tests.cpp:: failed: i > 10 for: 2 > 10 +AssertionHandler.tests.cpp:: failed: unexpected exception with message: '{ nested assertion failed }'; expression was: foo( 2 ) == 2 +AssertionHandler.tests.cpp:: passed: true +AssertionHandler.tests.cpp:: failed: i > 10 for: 2 > 10 +AssertionHandler.tests.cpp:: failed: unexpected exception with message: '{ nested assertion failed }'; expression was: foo( 2 ) == 2 Tricky.tests.cpp:: passed: true Tricky.tests.cpp:: passed: true Tricky.tests.cpp:: passed: true @@ -361,6 +368,9 @@ Message.tests.cpp:: passed: with 7 messages: 'custom_index_op{ Message.tests.cpp:: passed: with 11 messages: '("comma, in string", "escaped, \", ") := "escaped, ", "' and '"single quote in string,'," := "single quote in string,',"' and '"some escapes, \\,\\\\" := "some escapes, \,\\"' and '"some, ), unmatched, } prenheses {[<" := "some, ), unmatched, } prenheses {[<"' and ''"' := '"'' and ''\'' := '''' and '',' := ','' and ''}' := '}'' and '')' := ')'' and ''(' := '('' and ''{' := '{'' ToStringGeneral.tests.cpp:: passed: true with 1 message: 'i := 2' ToStringGeneral.tests.cpp:: passed: true with 1 message: '3' +Message.tests.cpp:: failed: false with 1 message: 'a := 1' +Message.tests.cpp:: passed: true with 1 message: 'a := 1' +Message.tests.cpp:: failed: false with 1 message: 'a := 1' Details.tests.cpp:: passed: eq( "", "" ) for: true Details.tests.cpp:: passed: !(eq( "", "a" )) for: !false Details.tests.cpp:: passed: eq( "a", "a" ) for: true @@ -471,6 +481,13 @@ Tricky.tests.cpp:: passed: std::vector{1, 2} == std::vector: passed: std::vector{1, 2} == std::vector{1, 2} for: { 1, 2 } == { 1, 2 } Tricky.tests.cpp:: passed: true Tricky.tests.cpp:: passed: std::vector{1, 2} == std::vector{1, 2} for: { 1, 2 } == { 1, 2 } +Misc.tests.cpp:: passed: !(ptr) for: !0 +Misc.tests.cpp:: passed: ptr == ptr for: 0 == 0 +Misc.tests.cpp:: passed: !(ptr != ptr) for: !(0 != 0) +Misc.tests.cpp:: passed: !(ptr < ptr) for: !(0 < 0) +Misc.tests.cpp:: passed: ptr <= ptr for: 0 <= 0 +Misc.tests.cpp:: passed: !(ptr > ptr) for: !(0 > 0) +Misc.tests.cpp:: passed: ptr >= ptr for: 0 >= 0 Tricky.tests.cpp:: passed: a for: 0x Tricky.tests.cpp:: passed: a == &foo for: 0x == 0x RandomNumberGeneration.tests.cpp:: passed: SimplePcg32{} == SimplePcg32{} for: {?} == {?} @@ -623,6 +640,9 @@ Exception.tests.cpp:: passed: thisThrows(), StartsWith( "expected" Exception.tests.cpp:: passed: thisThrows(), EndsWith( "exception" ) for: "expected exception" ends with: "exception" Exception.tests.cpp:: passed: thisThrows(), ContainsSubstring( "except" ) for: "expected exception" contains: "except" Exception.tests.cpp:: passed: thisThrows(), ContainsSubstring( "exCept", Catch::CaseSensitive::No ) for: "expected exception" contains: "except" (case insensitive) +ToString.tests.cpp:: passed: tos == tos for: { stringification failed with an exception: "Invalid" } +== +{ stringification failed with an exception: "Invalid" } Matchers.tests.cpp:: passed: throwsDerivedException(), DerivedException, Message( "DerivedException::what" ) for: DerivedException::what exception message matches "DerivedException::what" Matchers.tests.cpp:: passed: throwsDerivedException(), DerivedException, !Message( "derivedexception::what" ) for: DerivedException::what not exception message matches "derivedexception::what" Matchers.tests.cpp:: passed: throwsSpecialException( 2 ), SpecialException, !Message( "DerivedException::what" ) for: SpecialException::what not exception message matches "DerivedException::what" @@ -631,6 +651,8 @@ Exception.tests.cpp:: failed: unexpected exception with message: 'e Exception.tests.cpp:: failed: expected exception, got none; expression was: thisDoesntThrow(), std::domain_error Exception.tests.cpp:: failed: unexpected exception with message: 'expected exception'; expression was: thisThrows() Message.tests.cpp:: failed: explicitly with 1 message: 'This is a failure' +AssertionHandler.tests.cpp:: failed: explicitly with 1 message: 'Throw a Catch::TestFailureException' +AssertionHandler.tests.cpp:: failed: unexpected exception with message: '{ nested assertion failed }'; expression was: do_fail() Message.tests.cpp:: failed: explicitly Message.tests.cpp:: failed: explicitly with 1 message: 'This is a failure' Message.tests.cpp:: warning: 'This message appears in the output' @@ -800,6 +822,10 @@ GeneratorsImpl.tests.cpp:: passed: filter([](int) { return false; } GeneratorsImpl.tests.cpp:: passed: filter([](int) { return false; }, values({ 1, 2, 3 })), Catch::GeneratorException GeneratorsImpl.tests.cpp:: passed: gen.get() == 1 for: 1 == 1 GeneratorsImpl.tests.cpp:: passed: gen.next() for: true +GeneratorsImpl.tests.cpp:: passed: gen.get() == 3 for: 3 == 3 +GeneratorsImpl.tests.cpp:: passed: !(gen.next()) for: !false +GeneratorsImpl.tests.cpp:: passed: gen.get() == 1 for: 1 == 1 +GeneratorsImpl.tests.cpp:: passed: gen.next() for: true GeneratorsImpl.tests.cpp:: passed: gen.get() == 2 for: 2 == 2 GeneratorsImpl.tests.cpp:: passed: !(gen.next()) for: !false GeneratorsImpl.tests.cpp:: passed: gen.get() == 1 for: 1 == 1 @@ -1730,6 +1756,11 @@ BDD.tests.cpp:: passed: v.capacity() >= 10 for: 10 >= 10 BDD.tests.cpp:: passed: v.size() == 0 for: 0 == 0 BDD.tests.cpp:: passed: v.capacity() >= 10 for: 10 >= 10 BDD.tests.cpp:: passed: v.size() == 0 for: 0 == 0 +Message.tests.cpp:: failed: false with 1 message: 'This will be reported multiple times' +Message.tests.cpp:: failed: false with 1 message: 'This will be reported multiple times' +Message.tests.cpp:: failed: false with 1 message: 'Should be in scope at the end' +Message.tests.cpp:: passed: true with 1 message: 'Should survive a section end' +Message.tests.cpp:: failed: false with 1 message: 'Should survive a section end' Approx.tests.cpp:: passed: d == Approx( 1.23 ) for: 1.22999999999999998 == Approx( 1.22999999999999998 ) @@ -2385,7 +2416,7 @@ Exception.tests.cpp:: failed: unexpected exception with message: 'u Exception.tests.cpp:: failed: unexpected exception with message: 'expected exception'; expression was: thisThrows() == 0 Exception.tests.cpp:: failed: unexpected exception with message: 'expected exception'; expression was: thisThrows() == 0 Exception.tests.cpp:: failed: unexpected exception with message: 'expected exception'; expression was: thisThrows() == 0 -Exception.tests.cpp:: failed: unexpected exception with message: 'unexpected exception' +Exception.tests.cpp:: failed: unexpected exception with message: 'unexpected exception'; expression was: {Unknown expression after the reported line} Tricky.tests.cpp:: passed: Tricky.tests.cpp:: passed: Tricky.tests.cpp:: passed: @@ -2526,18 +2557,18 @@ Skip.tests.cpp:: failed: explicitly Skip.tests.cpp:: skipped: Skip.tests.cpp:: skipped: Skip.tests.cpp:: failed: explicitly -Clara.tests.cpp:: passed: with 1 message: 'Catch::Clara::Detail::is_unary_function::value' -Clara.tests.cpp:: passed: with 1 message: 'Catch::Clara::Detail::is_unary_function::value' -Clara.tests.cpp:: passed: with 1 message: 'Catch::Clara::Detail::is_unary_function::value' -Clara.tests.cpp:: passed: with 1 message: 'Catch::Clara::Detail::is_unary_function::value' -Clara.tests.cpp:: passed: with 1 message: 'Catch::Clara::Detail::is_unary_function::value' -Clara.tests.cpp:: passed: with 1 message: 'Catch::Clara::Detail::is_unary_function::value' -Clara.tests.cpp:: passed: with 1 message: '!(Catch::Clara::Detail::is_unary_function::value)' -Clara.tests.cpp:: passed: with 1 message: '!(Catch::Clara::Detail::is_unary_function::value)' -Clara.tests.cpp:: passed: with 1 message: '!(Catch::Clara::Detail::is_unary_function::value)' -Clara.tests.cpp:: passed: with 1 message: '!(Catch::Clara::Detail::is_unary_function::value)' -Clara.tests.cpp:: passed: with 1 message: '!(Catch::Clara::Detail::is_unary_function::value)' -Clara.tests.cpp:: passed: with 1 message: '!(Catch::Clara::Detail::is_unary_function::value)' +Clara.tests.cpp:: passed: with 1 message: 'Catch::Clara::Detail::is_unary_function_v' +Clara.tests.cpp:: passed: with 1 message: 'Catch::Clara::Detail::is_unary_function_v' +Clara.tests.cpp:: passed: with 1 message: 'Catch::Clara::Detail::is_unary_function_v' +Clara.tests.cpp:: passed: with 1 message: 'Catch::Clara::Detail::is_unary_function_v' +Clara.tests.cpp:: passed: with 1 message: 'Catch::Clara::Detail::is_unary_function_v' +Clara.tests.cpp:: passed: with 1 message: 'Catch::Clara::Detail::is_unary_function_v' +Clara.tests.cpp:: passed: with 1 message: '!(Catch::Clara::Detail::is_unary_function_v)' +Clara.tests.cpp:: passed: with 1 message: '!(Catch::Clara::Detail::is_unary_function_v)' +Clara.tests.cpp:: passed: with 1 message: '!(Catch::Clara::Detail::is_unary_function_v)' +Clara.tests.cpp:: passed: with 1 message: '!(Catch::Clara::Detail::is_unary_function_v)' +Clara.tests.cpp:: passed: with 1 message: '!(Catch::Clara::Detail::is_unary_function_v)' +Clara.tests.cpp:: passed: with 1 message: '!(Catch::Clara::Detail::is_unary_function_v)' Message.tests.cpp:: failed: explicitly with 1 message: 'Previous info should not be seen' Message.tests.cpp:: failed: explicitly with 1 message: 'previous unscoped info SHOULD not be seen' Misc.tests.cpp:: passed: l == std::numeric_limits::max() for: 9223372036854775807 (0x) @@ -2738,6 +2769,9 @@ Generators.tests.cpp:: passed: data.str.size() == data.len for: 3 = Generators.tests.cpp:: passed: data.str.size() == data.len for: 3 == 3 Generators.tests.cpp:: passed: data.str.size() == data.len for: 5 == 5 Generators.tests.cpp:: passed: data.str.size() == data.len for: 4 == 4 +ToStringChrono.tests.cpp:: passed: tp1 == tp2 for: {iso8601-timestamp} +== +{iso8601-timestamp} Generators.tests.cpp:: passed: strlen(std::get<0>(data)) == static_cast(std::get<1>(data)) for: 5 == 5 Generators.tests.cpp:: passed: strlen(std::get<0>(data)) == static_cast(std::get<1>(data)) for: 6 == 6 Generators.tests.cpp:: passed: strlen(std::get<0>(data)) == static_cast(std::get<1>(data)) for: 5 == 5 @@ -2843,7 +2877,7 @@ InternalBenchmark.tests.cpp:: passed: med == 18. for: 18.0 == 18.0 InternalBenchmark.tests.cpp:: passed: q3 == 23. for: 23.0 == 23.0 Misc.tests.cpp:: passed: Misc.tests.cpp:: passed: -test cases: 419 | 313 passed | 86 failed | 6 skipped | 14 failed as expected -assertions: 2269 | 2087 passed | 147 failed | 35 failed as expected +test cases: 435 | 317 passed | 95 failed | 6 skipped | 17 failed as expected +assertions: 2303 | 2105 passed | 157 failed | 41 failed as expected diff --git a/catch2/tests/SelfTest/Baselines/console.std.approved.txt b/catch2/tests/SelfTest/Baselines/console.std.approved.txt index 495264b..c1512db 100644 --- a/catch2/tests/SelfTest/Baselines/console.std.approved.txt +++ b/catch2/tests/SelfTest/Baselines/console.std.approved.txt @@ -34,6 +34,7 @@ Generators.tests.cpp: ............................................................................... Generators.tests.cpp:: FAILED: + {Unknown expression after the reported line} due to unexpected exception with message: failure to init @@ -45,8 +46,8 @@ Exception.tests.cpp: ............................................................................... Exception.tests.cpp:: FAILED: -due to unexpected exception with messages: - answer := 42 + {Unknown expression after the reported line} +due to unexpected exception with message: expected exception ------------------------------------------------------------------------------- @@ -346,6 +347,60 @@ Exception.tests.cpp:: FAILED: due to unexpected exception with message: unexpected exception +------------------------------------------------------------------------------- +Assertions can be nested - CHECK +------------------------------------------------------------------------------- +AssertionHandler.tests.cpp: +............................................................................... + +AssertionHandler.tests.cpp:: FAILED: + REQUIRE( i > 10 ) +with expansion: + 2 > 10 + +AssertionHandler.tests.cpp:: FAILED: + CHECK( foo( 2 ) == 2 ) +due to unexpected exception with message: + { nested assertion failed } + +------------------------------------------------------------------------------- +Assertions can be nested - REQUIRE +------------------------------------------------------------------------------- +AssertionHandler.tests.cpp: +............................................................................... + +AssertionHandler.tests.cpp:: FAILED: + REQUIRE( i > 10 ) +with expansion: + 2 > 10 + +AssertionHandler.tests.cpp:: FAILED: + REQUIRE( foo( 2 ) == 2 ) +due to unexpected exception with message: + { nested assertion failed } + +------------------------------------------------------------------------------- +Captures do not leave block with an exception +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: FAILED: + REQUIRE( false ) +with message: + a := 1 + +------------------------------------------------------------------------------- +Captures outlive section end +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: FAILED: + REQUIRE( false ) +with message: + a := 1 + ------------------------------------------------------------------------------- Contains string matcher ------------------------------------------------------------------------------- @@ -596,6 +651,21 @@ Message.tests.cpp:: FAILED: explicitly with message: This is a failure +------------------------------------------------------------------------------- +FAIL can be nested in assertion +------------------------------------------------------------------------------- +AssertionHandler.tests.cpp: +............................................................................... + +AssertionHandler.tests.cpp:: FAILED: +explicitly with message: + Throw a Catch::TestFailureException + +AssertionHandler.tests.cpp:: FAILED: + CHECK_NOTHROW( do_fail() ) +due to unexpected exception with message: + { nested assertion failed } + ------------------------------------------------------------------------------- FAIL does not require an argument ------------------------------------------------------------------------------- @@ -986,6 +1056,44 @@ with expansion: "this string contains 'abc' as a substring" matches "this string contains 'abc' as a" case sensitively +------------------------------------------------------------------------------- +Scoped message applies to all assertions in scope +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: FAILED: + CHECK( false ) +with message: + This will be reported multiple times + +Message.tests.cpp:: FAILED: + CHECK( false ) +with message: + This will be reported multiple times + +------------------------------------------------------------------------------- +Scoped messages do not leave block with an exception +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: FAILED: + REQUIRE( false ) +with message: + Should be in scope at the end + +------------------------------------------------------------------------------- +Scoped messages outlive section end +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: FAILED: + REQUIRE( false ) +with message: + Should survive a section end + A string sent directly to stdout A string sent directly to stderr A string sent to stderr via clog @@ -1248,6 +1356,7 @@ Exception.tests.cpp: ............................................................................... Exception.tests.cpp:: FAILED: + {Unknown expression after the reported line} due to unexpected exception with message: unexpected exception @@ -1610,6 +1719,6 @@ due to unexpected exception with message: Why would you throw a std::string? =============================================================================== -test cases: 419 | 327 passed | 71 failed | 7 skipped | 14 failed as expected -assertions: 2252 | 2087 passed | 130 failed | 35 failed as expected +test cases: 435 | 335 passed | 76 failed | 7 skipped | 17 failed as expected +assertions: 2282 | 2105 passed | 136 failed | 41 failed as expected diff --git a/catch2/tests/SelfTest/Baselines/console.sw.approved.txt b/catch2/tests/SelfTest/Baselines/console.sw.approved.txt index a53f40d..7fd5951 100644 --- a/catch2/tests/SelfTest/Baselines/console.sw.approved.txt +++ b/catch2/tests/SelfTest/Baselines/console.sw.approved.txt @@ -768,9 +768,26 @@ Generators.tests.cpp: ............................................................................... Generators.tests.cpp:: FAILED: + {Unknown expression after the reported line} due to unexpected exception with message: failure to init +------------------------------------------------------------------------------- +#3001: Enum-based bitfields can be captured +------------------------------------------------------------------------------- +Compilation.tests.cpp: +............................................................................... + +Compilation.tests.cpp:: PASSED: + REQUIRE( bf.e == 1 ) +with expansion: + 1 == 1 + +Compilation.tests.cpp:: PASSED: + REQUIRE( 1 == bf.e ) +with expansion: + 1 == 1 + ------------------------------------------------------------------------------- #748 - captures with unexpected exceptions outside assertions @@ -779,8 +796,8 @@ Exception.tests.cpp: ............................................................................... Exception.tests.cpp:: FAILED: -due to unexpected exception with messages: - answer := 42 + {Unknown expression after the reported line} +due to unexpected exception with message: expected exception ------------------------------------------------------------------------------- @@ -2565,6 +2582,41 @@ Compilation.tests.cpp:: PASSED: with expansion: !(Val: 1 ^ Val: 1) +------------------------------------------------------------------------------- +Assertions can be nested - CHECK +------------------------------------------------------------------------------- +AssertionHandler.tests.cpp: +............................................................................... + +AssertionHandler.tests.cpp:: FAILED: + REQUIRE( i > 10 ) +with expansion: + 2 > 10 + +AssertionHandler.tests.cpp:: FAILED: + CHECK( foo( 2 ) == 2 ) +due to unexpected exception with message: + { nested assertion failed } + +AssertionHandler.tests.cpp:: PASSED: + CHECK( true ) + +------------------------------------------------------------------------------- +Assertions can be nested - REQUIRE +------------------------------------------------------------------------------- +AssertionHandler.tests.cpp: +............................................................................... + +AssertionHandler.tests.cpp:: FAILED: + REQUIRE( i > 10 ) +with expansion: + 2 > 10 + +AssertionHandler.tests.cpp:: FAILED: + REQUIRE( foo( 2 ) == 2 ) +due to unexpected exception with message: + { nested assertion failed } + ------------------------------------------------------------------------------- Assertions then sections ------------------------------------------------------------------------------- @@ -2865,6 +2917,40 @@ ToStringGeneral.tests.cpp:: PASSED: with message: 3 +------------------------------------------------------------------------------- +Captures do not leave block with an exception +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: FAILED: + REQUIRE( false ) +with message: + a := 1 + +------------------------------------------------------------------------------- +Captures outlive section end + Dummy section +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: PASSED: + CHECK( true ) +with message: + a := 1 + +------------------------------------------------------------------------------- +Captures outlive section end +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: FAILED: + REQUIRE( false ) +with message: + a := 1 + ------------------------------------------------------------------------------- CaseInsensitiveEqualsTo is case insensitive Degenerate cases @@ -3469,6 +3555,47 @@ Tricky.tests.cpp:: PASSED: with expansion: { 1, 2 } == { 1, 2 } +------------------------------------------------------------------------------- +Comparing (and stringifying) volatile pointers works +------------------------------------------------------------------------------- +Misc.tests.cpp: +............................................................................... + +Misc.tests.cpp:: PASSED: + REQUIRE_FALSE( ptr ) +with expansion: + !0 + +Misc.tests.cpp:: PASSED: + REQUIRE( ptr == ptr ) +with expansion: + 0 == 0 + +Misc.tests.cpp:: PASSED: + REQUIRE_FALSE( ptr != ptr ) +with expansion: + !(0 != 0) + +Misc.tests.cpp:: PASSED: + REQUIRE_FALSE( ptr < ptr ) +with expansion: + !(0 < 0) + +Misc.tests.cpp:: PASSED: + REQUIRE( ptr <= ptr ) +with expansion: + 0 <= 0 + +Misc.tests.cpp:: PASSED: + REQUIRE_FALSE( ptr > ptr ) +with expansion: + !(0 > 0) + +Misc.tests.cpp:: PASSED: + REQUIRE( ptr >= ptr ) +with expansion: + 0 >= 0 + ------------------------------------------------------------------------------- Comparing function pointers ------------------------------------------------------------------------------- @@ -4470,6 +4597,19 @@ Exception.tests.cpp:: PASSED: with expansion: "expected exception" contains: "except" (case insensitive) +------------------------------------------------------------------------------- +Exception thrown inside stringify does not fail the test +------------------------------------------------------------------------------- +ToString.tests.cpp: +............................................................................... + +ToString.tests.cpp:: PASSED: + CHECK( tos == tos ) +with expansion: + { stringification failed with an exception: "Invalid" } + == + { stringification failed with an exception: "Invalid" } + ------------------------------------------------------------------------------- Exceptions matchers ------------------------------------------------------------------------------- @@ -4526,6 +4666,21 @@ Message.tests.cpp:: FAILED: explicitly with message: This is a failure +------------------------------------------------------------------------------- +FAIL can be nested in assertion +------------------------------------------------------------------------------- +AssertionHandler.tests.cpp: +............................................................................... + +AssertionHandler.tests.cpp:: FAILED: +explicitly with message: + Throw a Catch::TestFailureException + +AssertionHandler.tests.cpp:: FAILED: + CHECK_NOTHROW( do_fail() ) +due to unexpected exception with message: + { nested assertion failed } + ------------------------------------------------------------------------------- FAIL does not require an argument ------------------------------------------------------------------------------- @@ -5899,6 +6054,34 @@ GeneratorsImpl.tests.cpp:: PASSED: GeneratorsImpl.tests.cpp:: PASSED: REQUIRE_THROWS_AS( filter([](int) { return false; }, values({ 1, 2, 3 })), Catch::GeneratorException ) +------------------------------------------------------------------------------- +Generators internals + Filter generator + Out-of-line predicates are copied into the generator +------------------------------------------------------------------------------- +GeneratorsImpl.tests.cpp: +............................................................................... + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == 1 ) +with expansion: + 1 == 1 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == 3 ) +with expansion: + 3 == 3 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE_FALSE( gen.next() ) +with expansion: + !false + ------------------------------------------------------------------------------- Generators internals Take generator @@ -7652,7 +7835,7 @@ with expansion: ""custom"" == ""custom"" ------------------------------------------------------------------------------- -JsonWriter escapes charaters in strings properly +JsonWriter escapes characters in strings properly Quote in a string is escaped ------------------------------------------------------------------------------- Json.tests.cpp: @@ -7664,7 +7847,7 @@ with expansion: ""\""" == ""\""" ------------------------------------------------------------------------------- -JsonWriter escapes charaters in strings properly +JsonWriter escapes characters in strings properly Backslash in a string is escaped ------------------------------------------------------------------------------- Json.tests.cpp: @@ -7676,7 +7859,7 @@ with expansion: ""\\"" == ""\\"" ------------------------------------------------------------------------------- -JsonWriter escapes charaters in strings properly +JsonWriter escapes characters in strings properly Forward slash in a string is **not** escaped ------------------------------------------------------------------------------- Json.tests.cpp: @@ -7688,7 +7871,7 @@ with expansion: ""/"" == ""/"" ------------------------------------------------------------------------------- -JsonWriter escapes charaters in strings properly +JsonWriter escapes characters in strings properly Backspace in a string is escaped ------------------------------------------------------------------------------- Json.tests.cpp: @@ -7700,7 +7883,7 @@ with expansion: ""\b"" == ""\b"" ------------------------------------------------------------------------------- -JsonWriter escapes charaters in strings properly +JsonWriter escapes characters in strings properly Formfeed in a string is escaped ------------------------------------------------------------------------------- Json.tests.cpp: @@ -7712,7 +7895,7 @@ with expansion: ""\f"" == ""\f"" ------------------------------------------------------------------------------- -JsonWriter escapes charaters in strings properly +JsonWriter escapes characters in strings properly linefeed in a string is escaped ------------------------------------------------------------------------------- Json.tests.cpp: @@ -7724,7 +7907,7 @@ with expansion: ""\n"" == ""\n"" ------------------------------------------------------------------------------- -JsonWriter escapes charaters in strings properly +JsonWriter escapes characters in strings properly carriage return in a string is escaped ------------------------------------------------------------------------------- Json.tests.cpp: @@ -7736,7 +7919,7 @@ with expansion: ""\r"" == ""\r"" ------------------------------------------------------------------------------- -JsonWriter escapes charaters in strings properly +JsonWriter escapes characters in strings properly tab in a string is escaped ------------------------------------------------------------------------------- Json.tests.cpp: @@ -7748,7 +7931,7 @@ with expansion: ""\t"" == ""\t"" ------------------------------------------------------------------------------- -JsonWriter escapes charaters in strings properly +JsonWriter escapes characters in strings properly combination of characters is escaped ------------------------------------------------------------------------------- Json.tests.cpp: @@ -11024,6 +11207,56 @@ BDD.tests.cpp:: PASSED: with expansion: 0 == 0 +------------------------------------------------------------------------------- +Scoped message applies to all assertions in scope +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: FAILED: + CHECK( false ) +with message: + This will be reported multiple times + +Message.tests.cpp:: FAILED: + CHECK( false ) +with message: + This will be reported multiple times + +------------------------------------------------------------------------------- +Scoped messages do not leave block with an exception +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: FAILED: + REQUIRE( false ) +with message: + Should be in scope at the end + +------------------------------------------------------------------------------- +Scoped messages outlive section end + Dummy section +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: PASSED: + CHECK( true ) +with message: + Should survive a section end + +------------------------------------------------------------------------------- +Scoped messages outlive section end +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: FAILED: + REQUIRE( false ) +with message: + Should survive a section end + A string sent directly to stdout A string sent directly to stderr A string sent to stderr via clog @@ -12526,6 +12759,42 @@ Misc.tests.cpp:: PASSED: with expansion: 5 >= 5 +------------------------------------------------------------------------------- +TemplateTestSig: compiles with a single int parameter - 1 +------------------------------------------------------------------------------- +Misc.tests.cpp: +............................................................................... + + +No assertions in test case 'TemplateTestSig: compiles with a single int parameter - 1' + +------------------------------------------------------------------------------- +TemplateTestSig: compiles with a single int parameter - 3 +------------------------------------------------------------------------------- +Misc.tests.cpp: +............................................................................... + + +No assertions in test case 'TemplateTestSig: compiles with a single int parameter - 3' + +------------------------------------------------------------------------------- +TemplateTestSig: compiles with a single int parameter - 6 +------------------------------------------------------------------------------- +Misc.tests.cpp: +............................................................................... + + +No assertions in test case 'TemplateTestSig: compiles with a single int parameter - 6' + +------------------------------------------------------------------------------- +TemplateTestSig: compiles with two type parameters - int,int +------------------------------------------------------------------------------- +Misc.tests.cpp: +............................................................................... + + +No assertions in test case 'TemplateTestSig: compiles with two type parameters - int,int' + ------------------------------------------------------------------------------- TemplateTestSig: vectors can be sized and resized - (std::tuple), 6 ------------------------------------------------------------------------------- @@ -15747,6 +16016,7 @@ Exception.tests.cpp: ............................................................................... Exception.tests.cpp:: FAILED: + {Unknown expression after the reported line} due to unexpected exception with message: unexpected exception @@ -16668,51 +16938,51 @@ Clara.tests.cpp: Clara.tests.cpp:: PASSED: with message: - Catch::Clara::Detail::is_unary_function::value + Catch::Clara::Detail::is_unary_function_v Clara.tests.cpp:: PASSED: with message: - Catch::Clara::Detail::is_unary_function::value + Catch::Clara::Detail::is_unary_function_v Clara.tests.cpp:: PASSED: with message: - Catch::Clara::Detail::is_unary_function::value + Catch::Clara::Detail::is_unary_function_v Clara.tests.cpp:: PASSED: with message: - Catch::Clara::Detail::is_unary_function::value + Catch::Clara::Detail::is_unary_function_v Clara.tests.cpp:: PASSED: with message: - Catch::Clara::Detail::is_unary_function::value + Catch::Clara::Detail::is_unary_function_v Clara.tests.cpp:: PASSED: with message: - Catch::Clara::Detail::is_unary_function::value + Catch::Clara::Detail::is_unary_function_v Clara.tests.cpp:: PASSED: with message: - !(Catch::Clara::Detail::is_unary_function::value) + !(Catch::Clara::Detail::is_unary_function_v) Clara.tests.cpp:: PASSED: with message: - !(Catch::Clara::Detail::is_unary_function::value) + !(Catch::Clara::Detail::is_unary_function_v) Clara.tests.cpp:: PASSED: with message: - !(Catch::Clara::Detail::is_unary_function::value) + !(Catch::Clara::Detail::is_unary_function_v) Clara.tests.cpp:: PASSED: with message: - !(Catch::Clara::Detail::is_unary_function::value) + !(Catch::Clara::Detail::is_unary_function_v) Clara.tests.cpp:: PASSED: with message: - !(Catch::Clara::Detail::is_unary_function::value) + !(Catch::Clara::Detail::is_unary_function_v) Clara.tests.cpp:: PASSED: with message: - !(Catch::Clara::Detail::is_unary_function::value) + !(Catch::Clara::Detail::is_unary_function_v) ------------------------------------------------------------------------------- just failure @@ -18221,6 +18491,19 @@ Generators.tests.cpp:: PASSED: with expansion: 4 == 4 +------------------------------------------------------------------------------- +system_clock timepoint with non-default duration +------------------------------------------------------------------------------- +ToStringChrono.tests.cpp: +............................................................................... + +ToStringChrono.tests.cpp:: PASSED: + CHECK( tp1 == tp2 ) +with expansion: + {iso8601-timestamp} + == + {iso8601-timestamp} + ------------------------------------------------------------------------------- tables ------------------------------------------------------------------------------- @@ -19012,6 +19295,6 @@ Misc.tests.cpp: Misc.tests.cpp:: PASSED: =============================================================================== -test cases: 419 | 313 passed | 86 failed | 6 skipped | 14 failed as expected -assertions: 2269 | 2087 passed | 147 failed | 35 failed as expected +test cases: 435 | 317 passed | 95 failed | 6 skipped | 17 failed as expected +assertions: 2303 | 2105 passed | 157 failed | 41 failed as expected diff --git a/catch2/tests/SelfTest/Baselines/console.sw.multi.approved.txt b/catch2/tests/SelfTest/Baselines/console.sw.multi.approved.txt index 418ccf7..08ab1b2 100644 --- a/catch2/tests/SelfTest/Baselines/console.sw.multi.approved.txt +++ b/catch2/tests/SelfTest/Baselines/console.sw.multi.approved.txt @@ -766,9 +766,26 @@ Generators.tests.cpp: ............................................................................... Generators.tests.cpp:: FAILED: + {Unknown expression after the reported line} due to unexpected exception with message: failure to init +------------------------------------------------------------------------------- +#3001: Enum-based bitfields can be captured +------------------------------------------------------------------------------- +Compilation.tests.cpp: +............................................................................... + +Compilation.tests.cpp:: PASSED: + REQUIRE( bf.e == 1 ) +with expansion: + 1 == 1 + +Compilation.tests.cpp:: PASSED: + REQUIRE( 1 == bf.e ) +with expansion: + 1 == 1 + ------------------------------------------------------------------------------- #748 - captures with unexpected exceptions outside assertions @@ -777,8 +794,8 @@ Exception.tests.cpp: ............................................................................... Exception.tests.cpp:: FAILED: -due to unexpected exception with messages: - answer := 42 + {Unknown expression after the reported line} +due to unexpected exception with message: expected exception ------------------------------------------------------------------------------- @@ -2563,6 +2580,41 @@ Compilation.tests.cpp:: PASSED: with expansion: !(Val: 1 ^ Val: 1) +------------------------------------------------------------------------------- +Assertions can be nested - CHECK +------------------------------------------------------------------------------- +AssertionHandler.tests.cpp: +............................................................................... + +AssertionHandler.tests.cpp:: FAILED: + REQUIRE( i > 10 ) +with expansion: + 2 > 10 + +AssertionHandler.tests.cpp:: FAILED: + CHECK( foo( 2 ) == 2 ) +due to unexpected exception with message: + { nested assertion failed } + +AssertionHandler.tests.cpp:: PASSED: + CHECK( true ) + +------------------------------------------------------------------------------- +Assertions can be nested - REQUIRE +------------------------------------------------------------------------------- +AssertionHandler.tests.cpp: +............................................................................... + +AssertionHandler.tests.cpp:: FAILED: + REQUIRE( i > 10 ) +with expansion: + 2 > 10 + +AssertionHandler.tests.cpp:: FAILED: + REQUIRE( foo( 2 ) == 2 ) +due to unexpected exception with message: + { nested assertion failed } + ------------------------------------------------------------------------------- Assertions then sections ------------------------------------------------------------------------------- @@ -2863,6 +2915,40 @@ ToStringGeneral.tests.cpp:: PASSED: with message: 3 +------------------------------------------------------------------------------- +Captures do not leave block with an exception +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: FAILED: + REQUIRE( false ) +with message: + a := 1 + +------------------------------------------------------------------------------- +Captures outlive section end + Dummy section +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: PASSED: + CHECK( true ) +with message: + a := 1 + +------------------------------------------------------------------------------- +Captures outlive section end +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: FAILED: + REQUIRE( false ) +with message: + a := 1 + ------------------------------------------------------------------------------- CaseInsensitiveEqualsTo is case insensitive Degenerate cases @@ -3467,6 +3553,47 @@ Tricky.tests.cpp:: PASSED: with expansion: { 1, 2 } == { 1, 2 } +------------------------------------------------------------------------------- +Comparing (and stringifying) volatile pointers works +------------------------------------------------------------------------------- +Misc.tests.cpp: +............................................................................... + +Misc.tests.cpp:: PASSED: + REQUIRE_FALSE( ptr ) +with expansion: + !0 + +Misc.tests.cpp:: PASSED: + REQUIRE( ptr == ptr ) +with expansion: + 0 == 0 + +Misc.tests.cpp:: PASSED: + REQUIRE_FALSE( ptr != ptr ) +with expansion: + !(0 != 0) + +Misc.tests.cpp:: PASSED: + REQUIRE_FALSE( ptr < ptr ) +with expansion: + !(0 < 0) + +Misc.tests.cpp:: PASSED: + REQUIRE( ptr <= ptr ) +with expansion: + 0 <= 0 + +Misc.tests.cpp:: PASSED: + REQUIRE_FALSE( ptr > ptr ) +with expansion: + !(0 > 0) + +Misc.tests.cpp:: PASSED: + REQUIRE( ptr >= ptr ) +with expansion: + 0 >= 0 + ------------------------------------------------------------------------------- Comparing function pointers ------------------------------------------------------------------------------- @@ -4468,6 +4595,19 @@ Exception.tests.cpp:: PASSED: with expansion: "expected exception" contains: "except" (case insensitive) +------------------------------------------------------------------------------- +Exception thrown inside stringify does not fail the test +------------------------------------------------------------------------------- +ToString.tests.cpp: +............................................................................... + +ToString.tests.cpp:: PASSED: + CHECK( tos == tos ) +with expansion: + { stringification failed with an exception: "Invalid" } + == + { stringification failed with an exception: "Invalid" } + ------------------------------------------------------------------------------- Exceptions matchers ------------------------------------------------------------------------------- @@ -4524,6 +4664,21 @@ Message.tests.cpp:: FAILED: explicitly with message: This is a failure +------------------------------------------------------------------------------- +FAIL can be nested in assertion +------------------------------------------------------------------------------- +AssertionHandler.tests.cpp: +............................................................................... + +AssertionHandler.tests.cpp:: FAILED: +explicitly with message: + Throw a Catch::TestFailureException + +AssertionHandler.tests.cpp:: FAILED: + CHECK_NOTHROW( do_fail() ) +due to unexpected exception with message: + { nested assertion failed } + ------------------------------------------------------------------------------- FAIL does not require an argument ------------------------------------------------------------------------------- @@ -5897,6 +6052,34 @@ GeneratorsImpl.tests.cpp:: PASSED: GeneratorsImpl.tests.cpp:: PASSED: REQUIRE_THROWS_AS( filter([](int) { return false; }, values({ 1, 2, 3 })), Catch::GeneratorException ) +------------------------------------------------------------------------------- +Generators internals + Filter generator + Out-of-line predicates are copied into the generator +------------------------------------------------------------------------------- +GeneratorsImpl.tests.cpp: +............................................................................... + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == 1 ) +with expansion: + 1 == 1 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.next() ) +with expansion: + true + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE( gen.get() == 3 ) +with expansion: + 3 == 3 + +GeneratorsImpl.tests.cpp:: PASSED: + REQUIRE_FALSE( gen.next() ) +with expansion: + !false + ------------------------------------------------------------------------------- Generators internals Take generator @@ -7650,7 +7833,7 @@ with expansion: ""custom"" == ""custom"" ------------------------------------------------------------------------------- -JsonWriter escapes charaters in strings properly +JsonWriter escapes characters in strings properly Quote in a string is escaped ------------------------------------------------------------------------------- Json.tests.cpp: @@ -7662,7 +7845,7 @@ with expansion: ""\""" == ""\""" ------------------------------------------------------------------------------- -JsonWriter escapes charaters in strings properly +JsonWriter escapes characters in strings properly Backslash in a string is escaped ------------------------------------------------------------------------------- Json.tests.cpp: @@ -7674,7 +7857,7 @@ with expansion: ""\\"" == ""\\"" ------------------------------------------------------------------------------- -JsonWriter escapes charaters in strings properly +JsonWriter escapes characters in strings properly Forward slash in a string is **not** escaped ------------------------------------------------------------------------------- Json.tests.cpp: @@ -7686,7 +7869,7 @@ with expansion: ""/"" == ""/"" ------------------------------------------------------------------------------- -JsonWriter escapes charaters in strings properly +JsonWriter escapes characters in strings properly Backspace in a string is escaped ------------------------------------------------------------------------------- Json.tests.cpp: @@ -7698,7 +7881,7 @@ with expansion: ""\b"" == ""\b"" ------------------------------------------------------------------------------- -JsonWriter escapes charaters in strings properly +JsonWriter escapes characters in strings properly Formfeed in a string is escaped ------------------------------------------------------------------------------- Json.tests.cpp: @@ -7710,7 +7893,7 @@ with expansion: ""\f"" == ""\f"" ------------------------------------------------------------------------------- -JsonWriter escapes charaters in strings properly +JsonWriter escapes characters in strings properly linefeed in a string is escaped ------------------------------------------------------------------------------- Json.tests.cpp: @@ -7722,7 +7905,7 @@ with expansion: ""\n"" == ""\n"" ------------------------------------------------------------------------------- -JsonWriter escapes charaters in strings properly +JsonWriter escapes characters in strings properly carriage return in a string is escaped ------------------------------------------------------------------------------- Json.tests.cpp: @@ -7734,7 +7917,7 @@ with expansion: ""\r"" == ""\r"" ------------------------------------------------------------------------------- -JsonWriter escapes charaters in strings properly +JsonWriter escapes characters in strings properly tab in a string is escaped ------------------------------------------------------------------------------- Json.tests.cpp: @@ -7746,7 +7929,7 @@ with expansion: ""\t"" == ""\t"" ------------------------------------------------------------------------------- -JsonWriter escapes charaters in strings properly +JsonWriter escapes characters in strings properly combination of characters is escaped ------------------------------------------------------------------------------- Json.tests.cpp: @@ -11022,6 +11205,56 @@ BDD.tests.cpp:: PASSED: with expansion: 0 == 0 +------------------------------------------------------------------------------- +Scoped message applies to all assertions in scope +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: FAILED: + CHECK( false ) +with message: + This will be reported multiple times + +Message.tests.cpp:: FAILED: + CHECK( false ) +with message: + This will be reported multiple times + +------------------------------------------------------------------------------- +Scoped messages do not leave block with an exception +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: FAILED: + REQUIRE( false ) +with message: + Should be in scope at the end + +------------------------------------------------------------------------------- +Scoped messages outlive section end + Dummy section +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: PASSED: + CHECK( true ) +with message: + Should survive a section end + +------------------------------------------------------------------------------- +Scoped messages outlive section end +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: FAILED: + REQUIRE( false ) +with message: + Should survive a section end + ------------------------------------------------------------------------------- Sends stuff to stdout and stderr ------------------------------------------------------------------------------- @@ -12519,6 +12752,42 @@ Misc.tests.cpp:: PASSED: with expansion: 5 >= 5 +------------------------------------------------------------------------------- +TemplateTestSig: compiles with a single int parameter - 1 +------------------------------------------------------------------------------- +Misc.tests.cpp: +............................................................................... + + +No assertions in test case 'TemplateTestSig: compiles with a single int parameter - 1' + +------------------------------------------------------------------------------- +TemplateTestSig: compiles with a single int parameter - 3 +------------------------------------------------------------------------------- +Misc.tests.cpp: +............................................................................... + + +No assertions in test case 'TemplateTestSig: compiles with a single int parameter - 3' + +------------------------------------------------------------------------------- +TemplateTestSig: compiles with a single int parameter - 6 +------------------------------------------------------------------------------- +Misc.tests.cpp: +............................................................................... + + +No assertions in test case 'TemplateTestSig: compiles with a single int parameter - 6' + +------------------------------------------------------------------------------- +TemplateTestSig: compiles with two type parameters - int,int +------------------------------------------------------------------------------- +Misc.tests.cpp: +............................................................................... + + +No assertions in test case 'TemplateTestSig: compiles with two type parameters - int,int' + ------------------------------------------------------------------------------- TemplateTestSig: vectors can be sized and resized - (std::tuple), 6 ------------------------------------------------------------------------------- @@ -15740,6 +16009,7 @@ Exception.tests.cpp: ............................................................................... Exception.tests.cpp:: FAILED: + {Unknown expression after the reported line} due to unexpected exception with message: unexpected exception @@ -16660,51 +16930,51 @@ Clara.tests.cpp: Clara.tests.cpp:: PASSED: with message: - Catch::Clara::Detail::is_unary_function::value + Catch::Clara::Detail::is_unary_function_v Clara.tests.cpp:: PASSED: with message: - Catch::Clara::Detail::is_unary_function::value + Catch::Clara::Detail::is_unary_function_v Clara.tests.cpp:: PASSED: with message: - Catch::Clara::Detail::is_unary_function::value + Catch::Clara::Detail::is_unary_function_v Clara.tests.cpp:: PASSED: with message: - Catch::Clara::Detail::is_unary_function::value + Catch::Clara::Detail::is_unary_function_v Clara.tests.cpp:: PASSED: with message: - Catch::Clara::Detail::is_unary_function::value + Catch::Clara::Detail::is_unary_function_v Clara.tests.cpp:: PASSED: with message: - Catch::Clara::Detail::is_unary_function::value + Catch::Clara::Detail::is_unary_function_v Clara.tests.cpp:: PASSED: with message: - !(Catch::Clara::Detail::is_unary_function::value) + !(Catch::Clara::Detail::is_unary_function_v) Clara.tests.cpp:: PASSED: with message: - !(Catch::Clara::Detail::is_unary_function::value) + !(Catch::Clara::Detail::is_unary_function_v) Clara.tests.cpp:: PASSED: with message: - !(Catch::Clara::Detail::is_unary_function::value) + !(Catch::Clara::Detail::is_unary_function_v) Clara.tests.cpp:: PASSED: with message: - !(Catch::Clara::Detail::is_unary_function::value) + !(Catch::Clara::Detail::is_unary_function_v) Clara.tests.cpp:: PASSED: with message: - !(Catch::Clara::Detail::is_unary_function::value) + !(Catch::Clara::Detail::is_unary_function_v) Clara.tests.cpp:: PASSED: with message: - !(Catch::Clara::Detail::is_unary_function::value) + !(Catch::Clara::Detail::is_unary_function_v) ------------------------------------------------------------------------------- just failure @@ -18210,6 +18480,19 @@ Generators.tests.cpp:: PASSED: with expansion: 4 == 4 +------------------------------------------------------------------------------- +system_clock timepoint with non-default duration +------------------------------------------------------------------------------- +ToStringChrono.tests.cpp: +............................................................................... + +ToStringChrono.tests.cpp:: PASSED: + CHECK( tp1 == tp2 ) +with expansion: + {iso8601-timestamp} + == + {iso8601-timestamp} + ------------------------------------------------------------------------------- tables ------------------------------------------------------------------------------- @@ -19001,6 +19284,6 @@ Misc.tests.cpp: Misc.tests.cpp:: PASSED: =============================================================================== -test cases: 419 | 313 passed | 86 failed | 6 skipped | 14 failed as expected -assertions: 2269 | 2087 passed | 147 failed | 35 failed as expected +test cases: 435 | 317 passed | 95 failed | 6 skipped | 17 failed as expected +assertions: 2303 | 2105 passed | 157 failed | 41 failed as expected diff --git a/catch2/tests/SelfTest/Baselines/console.swa4.approved.txt b/catch2/tests/SelfTest/Baselines/console.swa4.approved.txt index 41b7612..63fb211 100644 --- a/catch2/tests/SelfTest/Baselines/console.swa4.approved.txt +++ b/catch2/tests/SelfTest/Baselines/console.swa4.approved.txt @@ -768,9 +768,26 @@ Generators.tests.cpp: ............................................................................... Generators.tests.cpp:: FAILED: + {Unknown expression after the reported line} due to unexpected exception with message: failure to init +------------------------------------------------------------------------------- +#3001: Enum-based bitfields can be captured +------------------------------------------------------------------------------- +Compilation.tests.cpp: +............................................................................... + +Compilation.tests.cpp:: PASSED: + REQUIRE( bf.e == 1 ) +with expansion: + 1 == 1 + +Compilation.tests.cpp:: PASSED: + REQUIRE( 1 == bf.e ) +with expansion: + 1 == 1 + ------------------------------------------------------------------------------- #748 - captures with unexpected exceptions outside assertions @@ -779,8 +796,8 @@ Exception.tests.cpp: ............................................................................... Exception.tests.cpp:: FAILED: -due to unexpected exception with messages: - answer := 42 + {Unknown expression after the reported line} +due to unexpected exception with message: expected exception ------------------------------------------------------------------------------- @@ -951,6 +968,6 @@ Condition.tests.cpp:: FAILED: CHECK( true != true ) =============================================================================== -test cases: 33 | 27 passed | 3 failed | 3 failed as expected -assertions: 102 | 94 passed | 4 failed | 4 failed as expected +test cases: 34 | 28 passed | 3 failed | 3 failed as expected +assertions: 104 | 96 passed | 4 failed | 4 failed as expected diff --git a/catch2/tests/SelfTest/Baselines/junit.sw.approved.txt b/catch2/tests/SelfTest/Baselines/junit.sw.approved.txt index c3571f3..c12b617 100644 --- a/catch2/tests/SelfTest/Baselines/junit.sw.approved.txt +++ b/catch2/tests/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + @@ -53,19 +53,21 @@ Nor would this - + FAILED: + {Unknown expression after the reported line} failure to init at Generators.tests.cpp: + - + FAILED: + {Unknown expression after the reported line} expected exception -answer := 42 at Exception.tests.cpp: @@ -389,6 +391,38 @@ at Exception.tests.cpp: + + + +FAILED: + REQUIRE( i > 10 ) +with expansion: + 2 > 10 +at AssertionHandler.tests.cpp: + + +FAILED: + CHECK( foo( 2 ) == 2 ) +{ nested assertion failed } +at AssertionHandler.tests.cpp: + + + + + +FAILED: + REQUIRE( i > 10 ) +with expansion: + 2 > 10 +at AssertionHandler.tests.cpp: + + +FAILED: + REQUIRE( foo( 2 ) == 2 ) +{ nested assertion failed } +at AssertionHandler.tests.cpp: + + @@ -410,6 +444,23 @@ at Exception.tests.cpp: + + +FAILED: + REQUIRE( false ) +a := 1 +at Message.tests.cpp: + + + + +FAILED: + REQUIRE( false ) +a := 1 +at Message.tests.cpp: + + + @@ -437,6 +488,7 @@ at Exception.tests.cpp: + @@ -693,6 +745,7 @@ at Matchers.tests.cpp: + @@ -720,6 +773,20 @@ This is a failure at Message.tests.cpp: + + + +FAILED: +Throw a Catch::TestFailureException +at AssertionHandler.tests.cpp: + + +FAILED: + CHECK_NOTHROW( do_fail() ) +{ nested assertion failed } +at AssertionHandler.tests.cpp: + + FAILED: @@ -779,6 +846,7 @@ at Message.tests.cpp: + @@ -929,16 +997,16 @@ at Condition.tests.cpp: - - - - - - - - - - + + + + + + + + + + @@ -1348,6 +1416,37 @@ at Matchers.tests.cpp: + + +FAILED: + CHECK( false ) +This will be reported multiple times +at Message.tests.cpp: + + +FAILED: + CHECK( false ) +This will be reported multiple times +at Message.tests.cpp: + + + + +FAILED: + REQUIRE( false ) +Should be in scope at the end +at Message.tests.cpp: + + + + +FAILED: + REQUIRE( false ) +Should survive a section end +at Message.tests.cpp: + + + A string sent directly to stdout @@ -1475,6 +1574,10 @@ at Misc.tests.cpp: + + + + @@ -1833,8 +1936,9 @@ at Exception.tests.cpp: - + FAILED: + {Unknown expression after the reported line} unexpected exception at Exception.tests.cpp: @@ -2232,6 +2336,7 @@ at Message.tests.cpp: + diff --git a/catch2/tests/SelfTest/Baselines/junit.sw.multi.approved.txt b/catch2/tests/SelfTest/Baselines/junit.sw.multi.approved.txt index 55f5520..e844ca6 100644 --- a/catch2/tests/SelfTest/Baselines/junit.sw.multi.approved.txt +++ b/catch2/tests/SelfTest/Baselines/junit.sw.multi.approved.txt @@ -1,6 +1,6 @@ - + @@ -52,19 +52,21 @@ Nor would this - + FAILED: + {Unknown expression after the reported line} failure to init at Generators.tests.cpp: + - + FAILED: + {Unknown expression after the reported line} expected exception -answer := 42 at Exception.tests.cpp: @@ -388,6 +390,38 @@ at Exception.tests.cpp: + + + +FAILED: + REQUIRE( i > 10 ) +with expansion: + 2 > 10 +at AssertionHandler.tests.cpp: + + +FAILED: + CHECK( foo( 2 ) == 2 ) +{ nested assertion failed } +at AssertionHandler.tests.cpp: + + + + + +FAILED: + REQUIRE( i > 10 ) +with expansion: + 2 > 10 +at AssertionHandler.tests.cpp: + + +FAILED: + REQUIRE( foo( 2 ) == 2 ) +{ nested assertion failed } +at AssertionHandler.tests.cpp: + + @@ -409,6 +443,23 @@ at Exception.tests.cpp: + + +FAILED: + REQUIRE( false ) +a := 1 +at Message.tests.cpp: + + + + +FAILED: + REQUIRE( false ) +a := 1 +at Message.tests.cpp: + + + @@ -436,6 +487,7 @@ at Exception.tests.cpp: + @@ -692,6 +744,7 @@ at Matchers.tests.cpp: + @@ -719,6 +772,20 @@ This is a failure at Message.tests.cpp: + + + +FAILED: +Throw a Catch::TestFailureException +at AssertionHandler.tests.cpp: + + +FAILED: + CHECK_NOTHROW( do_fail() ) +{ nested assertion failed } +at AssertionHandler.tests.cpp: + + FAILED: @@ -778,6 +845,7 @@ at Message.tests.cpp: + @@ -928,16 +996,16 @@ at Condition.tests.cpp: - - - - - - - - - - + + + + + + + + + + @@ -1347,6 +1415,37 @@ at Matchers.tests.cpp: + + +FAILED: + CHECK( false ) +This will be reported multiple times +at Message.tests.cpp: + + +FAILED: + CHECK( false ) +This will be reported multiple times +at Message.tests.cpp: + + + + +FAILED: + REQUIRE( false ) +Should be in scope at the end +at Message.tests.cpp: + + + + +FAILED: + REQUIRE( false ) +Should survive a section end +at Message.tests.cpp: + + + A string sent directly to stdout @@ -1474,6 +1573,10 @@ at Misc.tests.cpp: + + + + @@ -1832,8 +1935,9 @@ at Exception.tests.cpp: - + FAILED: + {Unknown expression after the reported line} unexpected exception at Exception.tests.cpp: @@ -2231,6 +2335,7 @@ at Message.tests.cpp: + diff --git a/catch2/tests/SelfTest/Baselines/sonarqube.sw.approved.txt b/catch2/tests/SelfTest/Baselines/sonarqube.sw.approved.txt index af06793..d79abd3 100644 --- a/catch2/tests/SelfTest/Baselines/sonarqube.sw.approved.txt +++ b/catch2/tests/SelfTest/Baselines/sonarqube.sw.approved.txt @@ -3,6 +3,49 @@ + + +FAILED: + REQUIRE( i > 10 ) +with expansion: + 2 > 10 +at AssertionHandler.tests.cpp: + + +FAILED: + CHECK( foo( 2 ) == 2 ) +{ nested assertion failed } +at AssertionHandler.tests.cpp: + + + + +FAILED: + REQUIRE( i > 10 ) +with expansion: + 2 > 10 +at AssertionHandler.tests.cpp: + + +FAILED: + REQUIRE( foo( 2 ) == 2 ) +{ nested assertion failed } +at AssertionHandler.tests.cpp: + + + + +FAILED: +Throw a Catch::TestFailureException +at AssertionHandler.tests.cpp: + + +FAILED: + CHECK_NOTHROW( do_fail() ) +{ nested assertion failed } +at AssertionHandler.tests.cpp: + + FAILED: @@ -110,6 +153,7 @@ at AssertionHandler.tests.cpp: + @@ -173,16 +217,16 @@ at AssertionHandler.tests.cpp: - - - - - - - - - - + + + + + + + + + + @@ -344,6 +388,7 @@ at AssertionHandler.tests.cpp: + @@ -612,6 +657,7 @@ at Class.tests.cpp: + @@ -1008,10 +1054,10 @@ at Decomposition.tests.cpp: - + FAILED: + {Unknown expression after the reported line} expected exception -answer := 42 at Exception.tests.cpp: @@ -1142,8 +1188,9 @@ at Exception.tests.cpp: - + FAILED: + {Unknown expression after the reported line} unexpected exception at Exception.tests.cpp: @@ -1161,8 +1208,9 @@ at Exception.tests.cpp: - + FAILED: + {Unknown expression after the reported line} failure to init at Generators.tests.cpp: @@ -1634,6 +1682,23 @@ at Matchers.tests.cpp: + + +FAILED: + REQUIRE( false ) +a := 1 +at Message.tests.cpp: + + + + +FAILED: + REQUIRE( false ) +a := 1 +at Message.tests.cpp: + + + FAILED: @@ -1723,6 +1788,37 @@ at Message.tests.cpp: + + +FAILED: + CHECK( false ) +This will be reported multiple times +at Message.tests.cpp: + + +FAILED: + CHECK( false ) +This will be reported multiple times +at Message.tests.cpp: + + + + +FAILED: + REQUIRE( false ) +Should be in scope at the end +at Message.tests.cpp: + + + + +FAILED: + REQUIRE( false ) +Should survive a section end +at Message.tests.cpp: + + + @@ -1839,6 +1935,7 @@ at Misc.tests.cpp: + @@ -1893,6 +1990,10 @@ at Misc.tests.cpp: + + + + @@ -2200,6 +2301,7 @@ at Skip.tests.cpp: + diff --git a/catch2/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt b/catch2/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt index 2d8d510..98a06c1 100644 --- a/catch2/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt +++ b/catch2/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt @@ -2,6 +2,49 @@ + + +FAILED: + REQUIRE( i > 10 ) +with expansion: + 2 > 10 +at AssertionHandler.tests.cpp: + + +FAILED: + CHECK( foo( 2 ) == 2 ) +{ nested assertion failed } +at AssertionHandler.tests.cpp: + + + + +FAILED: + REQUIRE( i > 10 ) +with expansion: + 2 > 10 +at AssertionHandler.tests.cpp: + + +FAILED: + REQUIRE( foo( 2 ) == 2 ) +{ nested assertion failed } +at AssertionHandler.tests.cpp: + + + + +FAILED: +Throw a Catch::TestFailureException +at AssertionHandler.tests.cpp: + + +FAILED: + CHECK_NOTHROW( do_fail() ) +{ nested assertion failed } +at AssertionHandler.tests.cpp: + + FAILED: @@ -109,6 +152,7 @@ at AssertionHandler.tests.cpp: + @@ -172,16 +216,16 @@ at AssertionHandler.tests.cpp: - - - - - - - - - - + + + + + + + + + + @@ -343,6 +387,7 @@ at AssertionHandler.tests.cpp: + @@ -611,6 +656,7 @@ at Class.tests.cpp: + @@ -1007,10 +1053,10 @@ at Decomposition.tests.cpp: - + FAILED: + {Unknown expression after the reported line} expected exception -answer := 42 at Exception.tests.cpp: @@ -1141,8 +1187,9 @@ at Exception.tests.cpp: - + FAILED: + {Unknown expression after the reported line} unexpected exception at Exception.tests.cpp: @@ -1160,8 +1207,9 @@ at Exception.tests.cpp: - + FAILED: + {Unknown expression after the reported line} failure to init at Generators.tests.cpp: @@ -1633,6 +1681,23 @@ at Matchers.tests.cpp: + + +FAILED: + REQUIRE( false ) +a := 1 +at Message.tests.cpp: + + + + +FAILED: + REQUIRE( false ) +a := 1 +at Message.tests.cpp: + + + FAILED: @@ -1722,6 +1787,37 @@ at Message.tests.cpp: + + +FAILED: + CHECK( false ) +This will be reported multiple times +at Message.tests.cpp: + + +FAILED: + CHECK( false ) +This will be reported multiple times +at Message.tests.cpp: + + + + +FAILED: + REQUIRE( false ) +Should be in scope at the end +at Message.tests.cpp: + + + + +FAILED: + REQUIRE( false ) +Should survive a section end +at Message.tests.cpp: + + + @@ -1838,6 +1934,7 @@ at Misc.tests.cpp: + @@ -1892,6 +1989,10 @@ at Misc.tests.cpp: + + + + @@ -2199,6 +2300,7 @@ at Skip.tests.cpp: + diff --git a/catch2/tests/SelfTest/Baselines/tap.sw.approved.txt b/catch2/tests/SelfTest/Baselines/tap.sw.approved.txt index 801946d..3e5d183 100644 --- a/catch2/tests/SelfTest/Baselines/tap.sw.approved.txt +++ b/catch2/tests/SelfTest/Baselines/tap.sw.approved.txt @@ -165,9 +165,13 @@ ok {test-number} - smallest_non_zero, WithinULP( -smallest_non_zero, 2 ) for: 0. # #2152 - ULP checks between differently signed values were wrong - float ok {test-number} - smallest_non_zero, !WithinULP( -smallest_non_zero, 1 ) for: 0.0f not is within 1 ULPs of -1.40129846e-45f ([-2.80259693e-45, -0.00000000e+00]) # #2615 - Throwing in constructor generator fails test case but does not abort -not ok {test-number} - unexpected exception with message: 'failure to init' +not ok {test-number} - unexpected exception with message: 'failure to init'; expression was: {Unknown expression after the reported line} +# #3001: Enum-based bitfields can be captured +ok {test-number} - bf.e == 1 for: 1 == 1 +# #3001: Enum-based bitfields can be captured +ok {test-number} - 1 == bf.e for: 1 == 1 # #748 - captures with unexpected exceptions -not ok {test-number} - unexpected exception with message: 'answer := 42' with 1 message: 'expected exception' +not ok {test-number} - unexpected exception with message: 'expected exception'; expression was: {Unknown expression after the reported line} # #748 - captures with unexpected exceptions not ok {test-number} - unexpected exception with message: 'answer := 42'; expression was: thisThrows() with 1 message: 'expected exception' # #748 - captures with unexpected exceptions @@ -612,6 +616,16 @@ ok {test-number} - HasBitOperators{ 1 } & HasBitOperators{ 1 } for: Val: 1 & Val ok {test-number} - lhs ^ rhs for: Val: 1 ^ Val: 2 # Assertion macros support bit operators and bool conversions ok {test-number} - !(lhs ^ lhs) for: !(Val: 1 ^ Val: 1) +# Assertions can be nested - CHECK +not ok {test-number} - i > 10 for: 2 > 10 +# Assertions can be nested - CHECK +not ok {test-number} - unexpected exception with message: '{ nested assertion failed }'; expression was: foo( 2 ) == 2 +# Assertions can be nested - CHECK +ok {test-number} - true +# Assertions can be nested - REQUIRE +not ok {test-number} - i > 10 for: 2 > 10 +# Assertions can be nested - REQUIRE +not ok {test-number} - unexpected exception with message: '{ nested assertion failed }'; expression was: foo( 2 ) == 2 # Assertions then sections ok {test-number} - true # Assertions then sections @@ -674,6 +688,12 @@ ok {test-number} - with 11 messages: '("comma, in string", "escaped, \", ") := " ok {test-number} - true with 1 message: 'i := 2' # Capture and info messages ok {test-number} - true with 1 message: '3' +# Captures do not leave block with an exception +not ok {test-number} - false with 1 message: 'a := 1' +# Captures outlive section end +ok {test-number} - true with 1 message: 'a := 1' +# Captures outlive section end +not ok {test-number} - false with 1 message: 'a := 1' # CaseInsensitiveEqualsTo is case insensitive ok {test-number} - eq( "", "" ) for: true # CaseInsensitiveEqualsTo is case insensitive @@ -846,6 +866,20 @@ ok {test-number} - std::vector{1, 2} == std::vector{1, 2} for: { 1, 2 ok {test-number} - true # Commas in various macros are allowed ok {test-number} - std::vector{1, 2} == std::vector{1, 2} for: { 1, 2 } == { 1, 2 } +# Comparing (and stringifying) volatile pointers works +ok {test-number} - !(ptr) for: !0 +# Comparing (and stringifying) volatile pointers works +ok {test-number} - ptr == ptr for: 0 == 0 +# Comparing (and stringifying) volatile pointers works +ok {test-number} - !(ptr != ptr) for: !(0 != 0) +# Comparing (and stringifying) volatile pointers works +ok {test-number} - !(ptr < ptr) for: !(0 < 0) +# Comparing (and stringifying) volatile pointers works +ok {test-number} - ptr <= ptr for: 0 <= 0 +# Comparing (and stringifying) volatile pointers works +ok {test-number} - !(ptr > ptr) for: !(0 > 0) +# Comparing (and stringifying) volatile pointers works +ok {test-number} - ptr >= ptr for: 0 >= 0 # Comparing function pointers ok {test-number} - a for: 0x # Comparing function pointers @@ -1110,6 +1144,8 @@ ok {test-number} - thisThrows(), EndsWith( "exception" ) for: "expected exceptio ok {test-number} - thisThrows(), ContainsSubstring( "except" ) for: "expected exception" contains: "except" # Exception messages can be tested for ok {test-number} - thisThrows(), ContainsSubstring( "exCept", Catch::CaseSensitive::No ) for: "expected exception" contains: "except" (case insensitive) +# Exception thrown inside stringify does not fail the test +ok {test-number} - tos == tos for: { stringification failed with an exception: "Invalid" } == { stringification failed with an exception: "Invalid" } # Exceptions matchers ok {test-number} - throwsDerivedException(), DerivedException, Message( "DerivedException::what" ) for: DerivedException::what exception message matches "DerivedException::what" # Exceptions matchers @@ -1126,6 +1162,10 @@ not ok {test-number} - expected exception, got none; expression was: thisDoesntT not ok {test-number} - unexpected exception with message: 'expected exception'; expression was: thisThrows() # FAIL aborts the test not ok {test-number} - explicitly with 1 message: 'This is a failure' +# FAIL can be nested in assertion +not ok {test-number} - explicitly with 1 message: 'Throw a Catch::TestFailureException' +# FAIL can be nested in assertion +not ok {test-number} - unexpected exception with message: '{ nested assertion failed }'; expression was: do_fail() # FAIL does not require an argument not ok {test-number} - explicitly # FAIL_CHECK does not abort the test @@ -1465,6 +1505,14 @@ ok {test-number} - gen.get() == 1 for: 1 == 1 # Generators internals ok {test-number} - gen.next() for: true # Generators internals +ok {test-number} - gen.get() == 3 for: 3 == 3 +# Generators internals +ok {test-number} - !(gen.next()) for: !false +# Generators internals +ok {test-number} - gen.get() == 1 for: 1 == 1 +# Generators internals +ok {test-number} - gen.next() for: true +# Generators internals ok {test-number} - gen.get() == 2 for: 2 == 2 # Generators internals ok {test-number} - !(gen.next()) for: !false @@ -1904,23 +1952,23 @@ ok {test-number} - stream.str() == "{\n}" for: "{ }" == "{ }" ok {test-number} - stream.str() == "[\n]" for: "[ ]" == "[ ]" # JsonWriter ok {test-number} - stream.str() == "\"custom\"" for: ""custom"" == ""custom"" -# JsonWriter escapes charaters in strings properly +# JsonWriter escapes characters in strings properly ok {test-number} - sstream.str() == "\"\\\"\"" for: ""\""" == ""\""" -# JsonWriter escapes charaters in strings properly +# JsonWriter escapes characters in strings properly ok {test-number} - sstream.str() == "\"\\\\\"" for: ""\\"" == ""\\"" -# JsonWriter escapes charaters in strings properly +# JsonWriter escapes characters in strings properly ok {test-number} - sstream.str() == "\"/\"" for: ""/"" == ""/"" -# JsonWriter escapes charaters in strings properly +# JsonWriter escapes characters in strings properly ok {test-number} - sstream.str() == "\"\\b\"" for: ""\b"" == ""\b"" -# JsonWriter escapes charaters in strings properly +# JsonWriter escapes characters in strings properly ok {test-number} - sstream.str() == "\"\\f\"" for: ""\f"" == ""\f"" -# JsonWriter escapes charaters in strings properly +# JsonWriter escapes characters in strings properly ok {test-number} - sstream.str() == "\"\\n\"" for: ""\n"" == ""\n"" -# JsonWriter escapes charaters in strings properly +# JsonWriter escapes characters in strings properly ok {test-number} - sstream.str() == "\"\\r\"" for: ""\r"" == ""\r"" -# JsonWriter escapes charaters in strings properly +# JsonWriter escapes characters in strings properly ok {test-number} - sstream.str() == "\"\\t\"" for: ""\t"" == ""\t"" -# JsonWriter escapes charaters in strings properly +# JsonWriter escapes characters in strings properly ok {test-number} - sstream.str() == "\"\\\\/\\t\\r\\n\"" for: ""\\/\t\r\n"" == ""\\/\t\r\n"" # Lambdas in assertions ok {test-number} - []() { return true; }() for: true @@ -2616,6 +2664,16 @@ ok {test-number} - v.size() == 0 for: 0 == 0 ok {test-number} - v.capacity() >= 10 for: 10 >= 10 # Scenario: Vector resizing affects size and capacity ok {test-number} - v.size() == 0 for: 0 == 0 +# Scoped message applies to all assertions in scope +not ok {test-number} - false with 1 message: 'This will be reported multiple times' +# Scoped message applies to all assertions in scope +not ok {test-number} - false with 1 message: 'This will be reported multiple times' +# Scoped messages do not leave block with an exception +not ok {test-number} - false with 1 message: 'Should be in scope at the end' +# Scoped messages outlive section end +ok {test-number} - true with 1 message: 'Should survive a section end' +# Scoped messages outlive section end +not ok {test-number} - false with 1 message: 'Should survive a section end' A string sent directly to stdout A string sent directly to stderr A string sent to stderr via clog @@ -3772,7 +3830,7 @@ not ok {test-number} - unexpected exception with message: 'expected exception'; # When unchecked exceptions are thrown from functions they are always failures not ok {test-number} - unexpected exception with message: 'expected exception'; expression was: thisThrows() == 0 # When unchecked exceptions are thrown from sections they are always failures -not ok {test-number} - unexpected exception with message: 'unexpected exception' +not ok {test-number} - unexpected exception with message: 'unexpected exception'; expression was: {Unknown expression after the reported line} # X/level/0/a ok {test-number} - # X/level/0/b @@ -4019,29 +4077,29 @@ ok {test-number} - # SKIP not ok {test-number} - explicitly loose text artifact # is_unary_function -ok {test-number} - with 1 message: 'Catch::Clara::Detail::is_unary_function::value' +ok {test-number} - with 1 message: 'Catch::Clara::Detail::is_unary_function_v' # is_unary_function -ok {test-number} - with 1 message: 'Catch::Clara::Detail::is_unary_function::value' +ok {test-number} - with 1 message: 'Catch::Clara::Detail::is_unary_function_v' # is_unary_function -ok {test-number} - with 1 message: 'Catch::Clara::Detail::is_unary_function::value' +ok {test-number} - with 1 message: 'Catch::Clara::Detail::is_unary_function_v' # is_unary_function -ok {test-number} - with 1 message: 'Catch::Clara::Detail::is_unary_function::value' +ok {test-number} - with 1 message: 'Catch::Clara::Detail::is_unary_function_v' # is_unary_function -ok {test-number} - with 1 message: 'Catch::Clara::Detail::is_unary_function::value' +ok {test-number} - with 1 message: 'Catch::Clara::Detail::is_unary_function_v' # is_unary_function -ok {test-number} - with 1 message: 'Catch::Clara::Detail::is_unary_function::value' +ok {test-number} - with 1 message: 'Catch::Clara::Detail::is_unary_function_v' # is_unary_function -ok {test-number} - with 1 message: '!(Catch::Clara::Detail::is_unary_function::value)' +ok {test-number} - with 1 message: '!(Catch::Clara::Detail::is_unary_function_v)' # is_unary_function -ok {test-number} - with 1 message: '!(Catch::Clara::Detail::is_unary_function::value)' +ok {test-number} - with 1 message: '!(Catch::Clara::Detail::is_unary_function_v)' # is_unary_function -ok {test-number} - with 1 message: '!(Catch::Clara::Detail::is_unary_function::value)' +ok {test-number} - with 1 message: '!(Catch::Clara::Detail::is_unary_function_v)' # is_unary_function -ok {test-number} - with 1 message: '!(Catch::Clara::Detail::is_unary_function::value)' +ok {test-number} - with 1 message: '!(Catch::Clara::Detail::is_unary_function_v)' # is_unary_function -ok {test-number} - with 1 message: '!(Catch::Clara::Detail::is_unary_function::value)' +ok {test-number} - with 1 message: '!(Catch::Clara::Detail::is_unary_function_v)' # is_unary_function -ok {test-number} - with 1 message: '!(Catch::Clara::Detail::is_unary_function::value)' +ok {test-number} - with 1 message: '!(Catch::Clara::Detail::is_unary_function_v)' # just failure not ok {test-number} - explicitly with 1 message: 'Previous info should not be seen' # just failure after unscoped info @@ -4377,6 +4435,8 @@ ok {test-number} - data.str.size() == data.len for: 3 == 3 ok {test-number} - data.str.size() == data.len for: 5 == 5 # strlen3 ok {test-number} - data.str.size() == data.len for: 4 == 4 +# system_clock timepoint with non-default duration +ok {test-number} - tp1 == tp2 for: {iso8601-timestamp} == {iso8601-timestamp} # tables ok {test-number} - strlen(std::get<0>(data)) == static_cast(std::get<1>(data)) for: 5 == 5 # tables @@ -4567,5 +4627,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0 ok {test-number} - # xmlentitycheck ok {test-number} - -1..2281 +1..2315 diff --git a/catch2/tests/SelfTest/Baselines/tap.sw.multi.approved.txt b/catch2/tests/SelfTest/Baselines/tap.sw.multi.approved.txt index 7f281f6..0fdb266 100644 --- a/catch2/tests/SelfTest/Baselines/tap.sw.multi.approved.txt +++ b/catch2/tests/SelfTest/Baselines/tap.sw.multi.approved.txt @@ -163,9 +163,13 @@ ok {test-number} - smallest_non_zero, WithinULP( -smallest_non_zero, 2 ) for: 0. # #2152 - ULP checks between differently signed values were wrong - float ok {test-number} - smallest_non_zero, !WithinULP( -smallest_non_zero, 1 ) for: 0.0f not is within 1 ULPs of -1.40129846e-45f ([-2.80259693e-45, -0.00000000e+00]) # #2615 - Throwing in constructor generator fails test case but does not abort -not ok {test-number} - unexpected exception with message: 'failure to init' +not ok {test-number} - unexpected exception with message: 'failure to init'; expression was: {Unknown expression after the reported line} +# #3001: Enum-based bitfields can be captured +ok {test-number} - bf.e == 1 for: 1 == 1 +# #3001: Enum-based bitfields can be captured +ok {test-number} - 1 == bf.e for: 1 == 1 # #748 - captures with unexpected exceptions -not ok {test-number} - unexpected exception with message: 'answer := 42' with 1 message: 'expected exception' +not ok {test-number} - unexpected exception with message: 'expected exception'; expression was: {Unknown expression after the reported line} # #748 - captures with unexpected exceptions not ok {test-number} - unexpected exception with message: 'answer := 42'; expression was: thisThrows() with 1 message: 'expected exception' # #748 - captures with unexpected exceptions @@ -610,6 +614,16 @@ ok {test-number} - HasBitOperators{ 1 } & HasBitOperators{ 1 } for: Val: 1 & Val ok {test-number} - lhs ^ rhs for: Val: 1 ^ Val: 2 # Assertion macros support bit operators and bool conversions ok {test-number} - !(lhs ^ lhs) for: !(Val: 1 ^ Val: 1) +# Assertions can be nested - CHECK +not ok {test-number} - i > 10 for: 2 > 10 +# Assertions can be nested - CHECK +not ok {test-number} - unexpected exception with message: '{ nested assertion failed }'; expression was: foo( 2 ) == 2 +# Assertions can be nested - CHECK +ok {test-number} - true +# Assertions can be nested - REQUIRE +not ok {test-number} - i > 10 for: 2 > 10 +# Assertions can be nested - REQUIRE +not ok {test-number} - unexpected exception with message: '{ nested assertion failed }'; expression was: foo( 2 ) == 2 # Assertions then sections ok {test-number} - true # Assertions then sections @@ -672,6 +686,12 @@ ok {test-number} - with 11 messages: '("comma, in string", "escaped, \", ") := " ok {test-number} - true with 1 message: 'i := 2' # Capture and info messages ok {test-number} - true with 1 message: '3' +# Captures do not leave block with an exception +not ok {test-number} - false with 1 message: 'a := 1' +# Captures outlive section end +ok {test-number} - true with 1 message: 'a := 1' +# Captures outlive section end +not ok {test-number} - false with 1 message: 'a := 1' # CaseInsensitiveEqualsTo is case insensitive ok {test-number} - eq( "", "" ) for: true # CaseInsensitiveEqualsTo is case insensitive @@ -844,6 +864,20 @@ ok {test-number} - std::vector{1, 2} == std::vector{1, 2} for: { 1, 2 ok {test-number} - true # Commas in various macros are allowed ok {test-number} - std::vector{1, 2} == std::vector{1, 2} for: { 1, 2 } == { 1, 2 } +# Comparing (and stringifying) volatile pointers works +ok {test-number} - !(ptr) for: !0 +# Comparing (and stringifying) volatile pointers works +ok {test-number} - ptr == ptr for: 0 == 0 +# Comparing (and stringifying) volatile pointers works +ok {test-number} - !(ptr != ptr) for: !(0 != 0) +# Comparing (and stringifying) volatile pointers works +ok {test-number} - !(ptr < ptr) for: !(0 < 0) +# Comparing (and stringifying) volatile pointers works +ok {test-number} - ptr <= ptr for: 0 <= 0 +# Comparing (and stringifying) volatile pointers works +ok {test-number} - !(ptr > ptr) for: !(0 > 0) +# Comparing (and stringifying) volatile pointers works +ok {test-number} - ptr >= ptr for: 0 >= 0 # Comparing function pointers ok {test-number} - a for: 0x # Comparing function pointers @@ -1108,6 +1142,8 @@ ok {test-number} - thisThrows(), EndsWith( "exception" ) for: "expected exceptio ok {test-number} - thisThrows(), ContainsSubstring( "except" ) for: "expected exception" contains: "except" # Exception messages can be tested for ok {test-number} - thisThrows(), ContainsSubstring( "exCept", Catch::CaseSensitive::No ) for: "expected exception" contains: "except" (case insensitive) +# Exception thrown inside stringify does not fail the test +ok {test-number} - tos == tos for: { stringification failed with an exception: "Invalid" } == { stringification failed with an exception: "Invalid" } # Exceptions matchers ok {test-number} - throwsDerivedException(), DerivedException, Message( "DerivedException::what" ) for: DerivedException::what exception message matches "DerivedException::what" # Exceptions matchers @@ -1124,6 +1160,10 @@ not ok {test-number} - expected exception, got none; expression was: thisDoesntT not ok {test-number} - unexpected exception with message: 'expected exception'; expression was: thisThrows() # FAIL aborts the test not ok {test-number} - explicitly with 1 message: 'This is a failure' +# FAIL can be nested in assertion +not ok {test-number} - explicitly with 1 message: 'Throw a Catch::TestFailureException' +# FAIL can be nested in assertion +not ok {test-number} - unexpected exception with message: '{ nested assertion failed }'; expression was: do_fail() # FAIL does not require an argument not ok {test-number} - explicitly # FAIL_CHECK does not abort the test @@ -1463,6 +1503,14 @@ ok {test-number} - gen.get() == 1 for: 1 == 1 # Generators internals ok {test-number} - gen.next() for: true # Generators internals +ok {test-number} - gen.get() == 3 for: 3 == 3 +# Generators internals +ok {test-number} - !(gen.next()) for: !false +# Generators internals +ok {test-number} - gen.get() == 1 for: 1 == 1 +# Generators internals +ok {test-number} - gen.next() for: true +# Generators internals ok {test-number} - gen.get() == 2 for: 2 == 2 # Generators internals ok {test-number} - !(gen.next()) for: !false @@ -1902,23 +1950,23 @@ ok {test-number} - stream.str() == "{\n}" for: "{ }" == "{ }" ok {test-number} - stream.str() == "[\n]" for: "[ ]" == "[ ]" # JsonWriter ok {test-number} - stream.str() == "\"custom\"" for: ""custom"" == ""custom"" -# JsonWriter escapes charaters in strings properly +# JsonWriter escapes characters in strings properly ok {test-number} - sstream.str() == "\"\\\"\"" for: ""\""" == ""\""" -# JsonWriter escapes charaters in strings properly +# JsonWriter escapes characters in strings properly ok {test-number} - sstream.str() == "\"\\\\\"" for: ""\\"" == ""\\"" -# JsonWriter escapes charaters in strings properly +# JsonWriter escapes characters in strings properly ok {test-number} - sstream.str() == "\"/\"" for: ""/"" == ""/"" -# JsonWriter escapes charaters in strings properly +# JsonWriter escapes characters in strings properly ok {test-number} - sstream.str() == "\"\\b\"" for: ""\b"" == ""\b"" -# JsonWriter escapes charaters in strings properly +# JsonWriter escapes characters in strings properly ok {test-number} - sstream.str() == "\"\\f\"" for: ""\f"" == ""\f"" -# JsonWriter escapes charaters in strings properly +# JsonWriter escapes characters in strings properly ok {test-number} - sstream.str() == "\"\\n\"" for: ""\n"" == ""\n"" -# JsonWriter escapes charaters in strings properly +# JsonWriter escapes characters in strings properly ok {test-number} - sstream.str() == "\"\\r\"" for: ""\r"" == ""\r"" -# JsonWriter escapes charaters in strings properly +# JsonWriter escapes characters in strings properly ok {test-number} - sstream.str() == "\"\\t\"" for: ""\t"" == ""\t"" -# JsonWriter escapes charaters in strings properly +# JsonWriter escapes characters in strings properly ok {test-number} - sstream.str() == "\"\\\\/\\t\\r\\n\"" for: ""\\/\t\r\n"" == ""\\/\t\r\n"" # Lambdas in assertions ok {test-number} - []() { return true; }() for: true @@ -2614,6 +2662,16 @@ ok {test-number} - v.size() == 0 for: 0 == 0 ok {test-number} - v.capacity() >= 10 for: 10 >= 10 # Scenario: Vector resizing affects size and capacity ok {test-number} - v.size() == 0 for: 0 == 0 +# Scoped message applies to all assertions in scope +not ok {test-number} - false with 1 message: 'This will be reported multiple times' +# Scoped message applies to all assertions in scope +not ok {test-number} - false with 1 message: 'This will be reported multiple times' +# Scoped messages do not leave block with an exception +not ok {test-number} - false with 1 message: 'Should be in scope at the end' +# Scoped messages outlive section end +ok {test-number} - true with 1 message: 'Should survive a section end' +# Scoped messages outlive section end +not ok {test-number} - false with 1 message: 'Should survive a section end' # Some simple comparisons between doubles ok {test-number} - d == Approx( 1.23 ) for: 1.22999999999999998 == Approx( 1.22999999999999998 ) # Some simple comparisons between doubles @@ -3765,7 +3823,7 @@ not ok {test-number} - unexpected exception with message: 'expected exception'; # When unchecked exceptions are thrown from functions they are always failures not ok {test-number} - unexpected exception with message: 'expected exception'; expression was: thisThrows() == 0 # When unchecked exceptions are thrown from sections they are always failures -not ok {test-number} - unexpected exception with message: 'unexpected exception' +not ok {test-number} - unexpected exception with message: 'unexpected exception'; expression was: {Unknown expression after the reported line} # X/level/0/a ok {test-number} - # X/level/0/b @@ -4011,29 +4069,29 @@ ok {test-number} - # SKIP # failing in some unskipped sections causes entire test case to fail not ok {test-number} - explicitly # is_unary_function -ok {test-number} - with 1 message: 'Catch::Clara::Detail::is_unary_function::value' +ok {test-number} - with 1 message: 'Catch::Clara::Detail::is_unary_function_v' # is_unary_function -ok {test-number} - with 1 message: 'Catch::Clara::Detail::is_unary_function::value' +ok {test-number} - with 1 message: 'Catch::Clara::Detail::is_unary_function_v' # is_unary_function -ok {test-number} - with 1 message: 'Catch::Clara::Detail::is_unary_function::value' +ok {test-number} - with 1 message: 'Catch::Clara::Detail::is_unary_function_v' # is_unary_function -ok {test-number} - with 1 message: 'Catch::Clara::Detail::is_unary_function::value' +ok {test-number} - with 1 message: 'Catch::Clara::Detail::is_unary_function_v' # is_unary_function -ok {test-number} - with 1 message: 'Catch::Clara::Detail::is_unary_function::value' +ok {test-number} - with 1 message: 'Catch::Clara::Detail::is_unary_function_v' # is_unary_function -ok {test-number} - with 1 message: 'Catch::Clara::Detail::is_unary_function::value' +ok {test-number} - with 1 message: 'Catch::Clara::Detail::is_unary_function_v' # is_unary_function -ok {test-number} - with 1 message: '!(Catch::Clara::Detail::is_unary_function::value)' +ok {test-number} - with 1 message: '!(Catch::Clara::Detail::is_unary_function_v)' # is_unary_function -ok {test-number} - with 1 message: '!(Catch::Clara::Detail::is_unary_function::value)' +ok {test-number} - with 1 message: '!(Catch::Clara::Detail::is_unary_function_v)' # is_unary_function -ok {test-number} - with 1 message: '!(Catch::Clara::Detail::is_unary_function::value)' +ok {test-number} - with 1 message: '!(Catch::Clara::Detail::is_unary_function_v)' # is_unary_function -ok {test-number} - with 1 message: '!(Catch::Clara::Detail::is_unary_function::value)' +ok {test-number} - with 1 message: '!(Catch::Clara::Detail::is_unary_function_v)' # is_unary_function -ok {test-number} - with 1 message: '!(Catch::Clara::Detail::is_unary_function::value)' +ok {test-number} - with 1 message: '!(Catch::Clara::Detail::is_unary_function_v)' # is_unary_function -ok {test-number} - with 1 message: '!(Catch::Clara::Detail::is_unary_function::value)' +ok {test-number} - with 1 message: '!(Catch::Clara::Detail::is_unary_function_v)' # just failure not ok {test-number} - explicitly with 1 message: 'Previous info should not be seen' # just failure after unscoped info @@ -4366,6 +4424,8 @@ ok {test-number} - data.str.size() == data.len for: 3 == 3 ok {test-number} - data.str.size() == data.len for: 5 == 5 # strlen3 ok {test-number} - data.str.size() == data.len for: 4 == 4 +# system_clock timepoint with non-default duration +ok {test-number} - tp1 == tp2 for: {iso8601-timestamp} == {iso8601-timestamp} # tables ok {test-number} - strlen(std::get<0>(data)) == static_cast(std::get<1>(data)) for: 5 == 5 # tables @@ -4556,5 +4616,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0 ok {test-number} - # xmlentitycheck ok {test-number} - -1..2281 +1..2315 diff --git a/catch2/tests/SelfTest/Baselines/teamcity.sw.approved.txt b/catch2/tests/SelfTest/Baselines/teamcity.sw.approved.txt index db48552..853f3d8 100644 --- a/catch2/tests/SelfTest/Baselines/teamcity.sw.approved.txt +++ b/catch2/tests/SelfTest/Baselines/teamcity.sw.approved.txt @@ -53,10 +53,12 @@ ##teamcity[testStarted name='#2152 - ULP checks between differently signed values were wrong - float'] ##teamcity[testFinished name='#2152 - ULP checks between differently signed values were wrong - float' duration="{duration}"] ##teamcity[testStarted name='#2615 - Throwing in constructor generator fails test case but does not abort'] -##teamcity[testIgnored name='#2615 - Throwing in constructor generator fails test case but does not abort' message='Generators.tests.cpp:|n...............................................................................|n|nGenerators.tests.cpp:|nunexpected exception with message:|n "failure to init"- failure ignore as test marked as |'ok to fail|'|n'] +##teamcity[testIgnored name='#2615 - Throwing in constructor generator fails test case but does not abort' message='Generators.tests.cpp:|n...............................................................................|n|nGenerators.tests.cpp:|nunexpected exception with message:|n "failure to init"|n {Unknown expression after the reported line}|nwith expansion:|n {Unknown expression after the reported line}|n- failure ignore as test marked as |'ok to fail|'|n'] ##teamcity[testFinished name='#2615 - Throwing in constructor generator fails test case but does not abort' duration="{duration}"] +##teamcity[testStarted name='#3001: Enum-based bitfields can be captured'] +##teamcity[testFinished name='#3001: Enum-based bitfields can be captured' duration="{duration}"] ##teamcity[testStarted name='#748 - captures with unexpected exceptions'] -##teamcity[testIgnored name='#748 - captures with unexpected exceptions' message='-------------------------------------------------------------------------------|noutside assertions|n-------------------------------------------------------------------------------|nException.tests.cpp:|n...............................................................................|n|nException.tests.cpp:|nunexpected exception with messages:|n "answer := 42"|n "expected exception"- failure ignore as test marked as |'ok to fail|'|n'] +##teamcity[testIgnored name='#748 - captures with unexpected exceptions' message='-------------------------------------------------------------------------------|noutside assertions|n-------------------------------------------------------------------------------|nException.tests.cpp:|n...............................................................................|n|nException.tests.cpp:|nunexpected exception with message:|n "expected exception"|n {Unknown expression after the reported line}|nwith expansion:|n {Unknown expression after the reported line}|n- failure ignore as test marked as |'ok to fail|'|n'] ##teamcity[testIgnored name='#748 - captures with unexpected exceptions' message='-------------------------------------------------------------------------------|ninside REQUIRE_NOTHROW|n-------------------------------------------------------------------------------|nException.tests.cpp:|n...............................................................................|n|nException.tests.cpp:|nunexpected exception with messages:|n "answer := 42"|n "expected exception"|n REQUIRE_NOTHROW( thisThrows() )|nwith expansion:|n thisThrows()|n- failure ignore as test marked as |'ok to fail|'|n'] ##teamcity[testFinished name='#748 - captures with unexpected exceptions' duration="{duration}"] ##teamcity[testStarted name='#809'] @@ -225,6 +227,14 @@ ##teamcity[testFinished name='Arbitrary predicate matcher' duration="{duration}"] ##teamcity[testStarted name='Assertion macros support bit operators and bool conversions'] ##teamcity[testFinished name='Assertion macros support bit operators and bool conversions' duration="{duration}"] +##teamcity[testStarted name='Assertions can be nested - CHECK'] +##teamcity[testIgnored name='Assertions can be nested - CHECK' message='AssertionHandler.tests.cpp:|n...............................................................................|n|nAssertionHandler.tests.cpp:|nexpression failed|n REQUIRE( i > 10 )|nwith expansion:|n 2 > 10|n- failure ignore as test marked as |'ok to fail|'|n'] +##teamcity[testIgnored name='Assertions can be nested - CHECK' message='AssertionHandler.tests.cpp:|nunexpected exception with message:|n "{ nested assertion failed }"|n CHECK( foo( 2 ) == 2 )|nwith expansion:|n foo( 2 ) == 2|n- failure ignore as test marked as |'ok to fail|'|n'] +##teamcity[testFinished name='Assertions can be nested - CHECK' duration="{duration}"] +##teamcity[testStarted name='Assertions can be nested - REQUIRE'] +##teamcity[testIgnored name='Assertions can be nested - REQUIRE' message='AssertionHandler.tests.cpp:|n...............................................................................|n|nAssertionHandler.tests.cpp:|nexpression failed|n REQUIRE( i > 10 )|nwith expansion:|n 2 > 10|n- failure ignore as test marked as |'ok to fail|'|n'] +##teamcity[testIgnored name='Assertions can be nested - REQUIRE' message='AssertionHandler.tests.cpp:|nunexpected exception with message:|n "{ nested assertion failed }"|n REQUIRE( foo( 2 ) == 2 )|nwith expansion:|n foo( 2 ) == 2|n- failure ignore as test marked as |'ok to fail|'|n'] +##teamcity[testFinished name='Assertions can be nested - REQUIRE' duration="{duration}"] ##teamcity[testStarted name='Assertions then sections'] ##teamcity[testFinished name='Assertions then sections' duration="{duration}"] ##teamcity[testStarted name='Basic use of the Contains range matcher'] @@ -239,6 +249,12 @@ ##teamcity[testFinished name='CAPTURE parses string and character constants' duration="{duration}"] ##teamcity[testStarted name='Capture and info messages'] ##teamcity[testFinished name='Capture and info messages' duration="{duration}"] +##teamcity[testStarted name='Captures do not leave block with an exception'] +##teamcity[testFailed name='Captures do not leave block with an exception' message='Message.tests.cpp:|n...............................................................................|n|nMessage.tests.cpp:|nexpression failed with message:|n "a := 1"|n REQUIRE( false )|nwith expansion:|n false|n'] +##teamcity[testFinished name='Captures do not leave block with an exception' duration="{duration}"] +##teamcity[testStarted name='Captures outlive section end'] +##teamcity[testFailed name='Captures outlive section end' message='Message.tests.cpp:|n...............................................................................|n|nMessage.tests.cpp:|nexpression failed with message:|n "a := 1"|n REQUIRE( false )|nwith expansion:|n false|n'] +##teamcity[testFinished name='Captures outlive section end' duration="{duration}"] ##teamcity[testStarted name='CaseInsensitiveEqualsTo is case insensitive'] ##teamcity[testFinished name='CaseInsensitiveEqualsTo is case insensitive' duration="{duration}"] ##teamcity[testStarted name='CaseInsensitiveLess is case insensitive'] @@ -269,6 +285,8 @@ ##teamcity[testFinished name='Combining templated matchers' duration="{duration}"] ##teamcity[testStarted name='Commas in various macros are allowed'] ##teamcity[testFinished name='Commas in various macros are allowed' duration="{duration}"] +##teamcity[testStarted name='Comparing (and stringifying) volatile pointers works'] +##teamcity[testFinished name='Comparing (and stringifying) volatile pointers works' duration="{duration}"] ##teamcity[testStarted name='Comparing function pointers'] ##teamcity[testFinished name='Comparing function pointers' duration="{duration}"] ##teamcity[testStarted name='Comparison ops'] @@ -360,6 +378,8 @@ ##teamcity[testFinished name='Exception message can be matched' duration="{duration}"] ##teamcity[testStarted name='Exception messages can be tested for'] ##teamcity[testFinished name='Exception messages can be tested for' duration="{duration}"] +##teamcity[testStarted name='Exception thrown inside stringify does not fail the test'] +##teamcity[testFinished name='Exception thrown inside stringify does not fail the test' duration="{duration}"] ##teamcity[testStarted name='Exceptions matchers'] ##teamcity[testFinished name='Exceptions matchers' duration="{duration}"] ##teamcity[testStarted name='Expected exceptions that don|'t throw or unexpected exceptions fail the test'] @@ -370,6 +390,10 @@ ##teamcity[testStarted name='FAIL aborts the test'] ##teamcity[testFailed name='FAIL aborts the test' message='Message.tests.cpp:|n...............................................................................|n|nMessage.tests.cpp:|nexplicit failure with message:|n "This is a failure"'] ##teamcity[testFinished name='FAIL aborts the test' duration="{duration}"] +##teamcity[testStarted name='FAIL can be nested in assertion'] +##teamcity[testIgnored name='FAIL can be nested in assertion' message='AssertionHandler.tests.cpp:|n...............................................................................|n|nAssertionHandler.tests.cpp:|nexplicit failure with message:|n "Throw a Catch::TestFailureException"- failure ignore as test marked as |'ok to fail|'|n'] +##teamcity[testIgnored name='FAIL can be nested in assertion' message='AssertionHandler.tests.cpp:|nunexpected exception with message:|n "{ nested assertion failed }"|n CHECK_NOTHROW( do_fail() )|nwith expansion:|n do_fail()|n- failure ignore as test marked as |'ok to fail|'|n'] +##teamcity[testFinished name='FAIL can be nested in assertion' duration="{duration}"] ##teamcity[testStarted name='FAIL does not require an argument'] ##teamcity[testFailed name='FAIL does not require an argument' message='Message.tests.cpp:|n...............................................................................|n|nMessage.tests.cpp:|nexplicit failure'] ##teamcity[testFinished name='FAIL does not require an argument' duration="{duration}"] @@ -431,8 +455,8 @@ ##teamcity[testFinished name='Inequality checks that should succeed' duration="{duration}"] ##teamcity[testStarted name='JsonWriter'] ##teamcity[testFinished name='JsonWriter' duration="{duration}"] -##teamcity[testStarted name='JsonWriter escapes charaters in strings properly'] -##teamcity[testFinished name='JsonWriter escapes charaters in strings properly' duration="{duration}"] +##teamcity[testStarted name='JsonWriter escapes characters in strings properly'] +##teamcity[testFinished name='JsonWriter escapes characters in strings properly' duration="{duration}"] ##teamcity[testStarted name='Lambdas in assertions'] ##teamcity[testFinished name='Lambdas in assertions' duration="{duration}"] ##teamcity[testStarted name='Less-than inequalities with different epsilons'] @@ -566,6 +590,16 @@ ##teamcity[testFinished name='Scenario: This is a really long scenario name to see how the list command deals with wrapping' duration="{duration}"] ##teamcity[testStarted name='Scenario: Vector resizing affects size and capacity'] ##teamcity[testFinished name='Scenario: Vector resizing affects size and capacity' duration="{duration}"] +##teamcity[testStarted name='Scoped message applies to all assertions in scope'] +##teamcity[testFailed name='Scoped message applies to all assertions in scope' message='Message.tests.cpp:|n...............................................................................|n|nMessage.tests.cpp:|nexpression failed with message:|n "This will be reported multiple times"|n CHECK( false )|nwith expansion:|n false|n'] +##teamcity[testFailed name='Scoped message applies to all assertions in scope' message='Message.tests.cpp:|nexpression failed with message:|n "This will be reported multiple times"|n CHECK( false )|nwith expansion:|n false|n'] +##teamcity[testFinished name='Scoped message applies to all assertions in scope' duration="{duration}"] +##teamcity[testStarted name='Scoped messages do not leave block with an exception'] +##teamcity[testFailed name='Scoped messages do not leave block with an exception' message='Message.tests.cpp:|n...............................................................................|n|nMessage.tests.cpp:|nexpression failed with message:|n "Should be in scope at the end"|n REQUIRE( false )|nwith expansion:|n false|n'] +##teamcity[testFinished name='Scoped messages do not leave block with an exception' duration="{duration}"] +##teamcity[testStarted name='Scoped messages outlive section end'] +##teamcity[testFailed name='Scoped messages outlive section end' message='Message.tests.cpp:|n...............................................................................|n|nMessage.tests.cpp:|nexpression failed with message:|n "Should survive a section end"|n REQUIRE( false )|nwith expansion:|n false|n'] +##teamcity[testFinished name='Scoped messages outlive section end' duration="{duration}"] ##teamcity[testStarted name='Sends stuff to stdout and stderr'] ##teamcity[testStdOut name='Sends stuff to stdout and stderr' out='A string sent directly to stdout|n'] ##teamcity[testStdErr name='Sends stuff to stdout and stderr' out='A string sent directly to stderr|nA string sent to stderr via clog|n'] @@ -634,6 +668,14 @@ ##teamcity[testFinished name='TemplateTest: vectors can be sized and resized - std::string' duration="{duration}"] ##teamcity[testStarted name='TemplateTest: vectors can be sized and resized - std::tuple'] ##teamcity[testFinished name='TemplateTest: vectors can be sized and resized - std::tuple' duration="{duration}"] +##teamcity[testStarted name='TemplateTestSig: compiles with a single int parameter - 1'] +##teamcity[testFinished name='TemplateTestSig: compiles with a single int parameter - 1' duration="{duration}"] +##teamcity[testStarted name='TemplateTestSig: compiles with a single int parameter - 3'] +##teamcity[testFinished name='TemplateTestSig: compiles with a single int parameter - 3' duration="{duration}"] +##teamcity[testStarted name='TemplateTestSig: compiles with a single int parameter - 6'] +##teamcity[testFinished name='TemplateTestSig: compiles with a single int parameter - 6' duration="{duration}"] +##teamcity[testStarted name='TemplateTestSig: compiles with two type parameters - int,int'] +##teamcity[testFinished name='TemplateTestSig: compiles with two type parameters - int,int' duration="{duration}"] ##teamcity[testStarted name='TemplateTestSig: vectors can be sized and resized - (std::tuple), 6'] ##teamcity[testFinished name='TemplateTestSig: vectors can be sized and resized - (std::tuple), 6' duration="{duration}"] ##teamcity[testStarted name='TemplateTestSig: vectors can be sized and resized - float,4'] @@ -743,7 +785,7 @@ ##teamcity[testFailed name='When unchecked exceptions are thrown from functions they are always failures' message='Exception.tests.cpp:|n...............................................................................|n|nException.tests.cpp:|nunexpected exception with message:|n "expected exception"|n CHECK( thisThrows() == 0 )|nwith expansion:|n thisThrows() == 0|n'] ##teamcity[testFinished name='When unchecked exceptions are thrown from functions they are always failures' duration="{duration}"] ##teamcity[testStarted name='When unchecked exceptions are thrown from sections they are always failures'] -##teamcity[testFailed name='When unchecked exceptions are thrown from sections they are always failures' message='-------------------------------------------------------------------------------|nsection name|n-------------------------------------------------------------------------------|nException.tests.cpp:|n...............................................................................|n|nException.tests.cpp:|nunexpected exception with message:|n "unexpected exception"'] +##teamcity[testFailed name='When unchecked exceptions are thrown from sections they are always failures' message='-------------------------------------------------------------------------------|nsection name|n-------------------------------------------------------------------------------|nException.tests.cpp:|n...............................................................................|n|nException.tests.cpp:|nunexpected exception with message:|n "unexpected exception"|n {Unknown expression after the reported line}|nwith expansion:|n {Unknown expression after the reported line}|n'] ##teamcity[testFinished name='When unchecked exceptions are thrown from sections they are always failures' duration="{duration}"] ##teamcity[testStarted name='When unchecked exceptions are thrown, but caught, they do not affect the test'] ##teamcity[testFinished name='When unchecked exceptions are thrown, but caught, they do not affect the test' duration="{duration}"] @@ -961,6 +1003,8 @@ loose text artifact ##teamcity[testFinished name='stringify( vectors )' duration="{duration}"] ##teamcity[testStarted name='strlen3'] ##teamcity[testFinished name='strlen3' duration="{duration}"] +##teamcity[testStarted name='system_clock timepoint with non-default duration'] +##teamcity[testFinished name='system_clock timepoint with non-default duration' duration="{duration}"] ##teamcity[testStarted name='tables'] ##teamcity[testFinished name='tables' duration="{duration}"] ##teamcity[testStarted name='tags with dots in later positions are not parsed as hidden'] diff --git a/catch2/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt b/catch2/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt index dde8a68..10e318d 100644 --- a/catch2/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt +++ b/catch2/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt @@ -53,10 +53,12 @@ ##teamcity[testStarted name='#2152 - ULP checks between differently signed values were wrong - float'] ##teamcity[testFinished name='#2152 - ULP checks between differently signed values were wrong - float' duration="{duration}"] ##teamcity[testStarted name='#2615 - Throwing in constructor generator fails test case but does not abort'] -##teamcity[testIgnored name='#2615 - Throwing in constructor generator fails test case but does not abort' message='Generators.tests.cpp:|n...............................................................................|n|nGenerators.tests.cpp:|nunexpected exception with message:|n "failure to init"- failure ignore as test marked as |'ok to fail|'|n'] +##teamcity[testIgnored name='#2615 - Throwing in constructor generator fails test case but does not abort' message='Generators.tests.cpp:|n...............................................................................|n|nGenerators.tests.cpp:|nunexpected exception with message:|n "failure to init"|n {Unknown expression after the reported line}|nwith expansion:|n {Unknown expression after the reported line}|n- failure ignore as test marked as |'ok to fail|'|n'] ##teamcity[testFinished name='#2615 - Throwing in constructor generator fails test case but does not abort' duration="{duration}"] +##teamcity[testStarted name='#3001: Enum-based bitfields can be captured'] +##teamcity[testFinished name='#3001: Enum-based bitfields can be captured' duration="{duration}"] ##teamcity[testStarted name='#748 - captures with unexpected exceptions'] -##teamcity[testIgnored name='#748 - captures with unexpected exceptions' message='-------------------------------------------------------------------------------|noutside assertions|n-------------------------------------------------------------------------------|nException.tests.cpp:|n...............................................................................|n|nException.tests.cpp:|nunexpected exception with messages:|n "answer := 42"|n "expected exception"- failure ignore as test marked as |'ok to fail|'|n'] +##teamcity[testIgnored name='#748 - captures with unexpected exceptions' message='-------------------------------------------------------------------------------|noutside assertions|n-------------------------------------------------------------------------------|nException.tests.cpp:|n...............................................................................|n|nException.tests.cpp:|nunexpected exception with message:|n "expected exception"|n {Unknown expression after the reported line}|nwith expansion:|n {Unknown expression after the reported line}|n- failure ignore as test marked as |'ok to fail|'|n'] ##teamcity[testIgnored name='#748 - captures with unexpected exceptions' message='-------------------------------------------------------------------------------|ninside REQUIRE_NOTHROW|n-------------------------------------------------------------------------------|nException.tests.cpp:|n...............................................................................|n|nException.tests.cpp:|nunexpected exception with messages:|n "answer := 42"|n "expected exception"|n REQUIRE_NOTHROW( thisThrows() )|nwith expansion:|n thisThrows()|n- failure ignore as test marked as |'ok to fail|'|n'] ##teamcity[testFinished name='#748 - captures with unexpected exceptions' duration="{duration}"] ##teamcity[testStarted name='#809'] @@ -225,6 +227,14 @@ ##teamcity[testFinished name='Arbitrary predicate matcher' duration="{duration}"] ##teamcity[testStarted name='Assertion macros support bit operators and bool conversions'] ##teamcity[testFinished name='Assertion macros support bit operators and bool conversions' duration="{duration}"] +##teamcity[testStarted name='Assertions can be nested - CHECK'] +##teamcity[testIgnored name='Assertions can be nested - CHECK' message='AssertionHandler.tests.cpp:|n...............................................................................|n|nAssertionHandler.tests.cpp:|nexpression failed|n REQUIRE( i > 10 )|nwith expansion:|n 2 > 10|n- failure ignore as test marked as |'ok to fail|'|n'] +##teamcity[testIgnored name='Assertions can be nested - CHECK' message='AssertionHandler.tests.cpp:|nunexpected exception with message:|n "{ nested assertion failed }"|n CHECK( foo( 2 ) == 2 )|nwith expansion:|n foo( 2 ) == 2|n- failure ignore as test marked as |'ok to fail|'|n'] +##teamcity[testFinished name='Assertions can be nested - CHECK' duration="{duration}"] +##teamcity[testStarted name='Assertions can be nested - REQUIRE'] +##teamcity[testIgnored name='Assertions can be nested - REQUIRE' message='AssertionHandler.tests.cpp:|n...............................................................................|n|nAssertionHandler.tests.cpp:|nexpression failed|n REQUIRE( i > 10 )|nwith expansion:|n 2 > 10|n- failure ignore as test marked as |'ok to fail|'|n'] +##teamcity[testIgnored name='Assertions can be nested - REQUIRE' message='AssertionHandler.tests.cpp:|nunexpected exception with message:|n "{ nested assertion failed }"|n REQUIRE( foo( 2 ) == 2 )|nwith expansion:|n foo( 2 ) == 2|n- failure ignore as test marked as |'ok to fail|'|n'] +##teamcity[testFinished name='Assertions can be nested - REQUIRE' duration="{duration}"] ##teamcity[testStarted name='Assertions then sections'] ##teamcity[testFinished name='Assertions then sections' duration="{duration}"] ##teamcity[testStarted name='Basic use of the Contains range matcher'] @@ -239,6 +249,12 @@ ##teamcity[testFinished name='CAPTURE parses string and character constants' duration="{duration}"] ##teamcity[testStarted name='Capture and info messages'] ##teamcity[testFinished name='Capture and info messages' duration="{duration}"] +##teamcity[testStarted name='Captures do not leave block with an exception'] +##teamcity[testFailed name='Captures do not leave block with an exception' message='Message.tests.cpp:|n...............................................................................|n|nMessage.tests.cpp:|nexpression failed with message:|n "a := 1"|n REQUIRE( false )|nwith expansion:|n false|n'] +##teamcity[testFinished name='Captures do not leave block with an exception' duration="{duration}"] +##teamcity[testStarted name='Captures outlive section end'] +##teamcity[testFailed name='Captures outlive section end' message='Message.tests.cpp:|n...............................................................................|n|nMessage.tests.cpp:|nexpression failed with message:|n "a := 1"|n REQUIRE( false )|nwith expansion:|n false|n'] +##teamcity[testFinished name='Captures outlive section end' duration="{duration}"] ##teamcity[testStarted name='CaseInsensitiveEqualsTo is case insensitive'] ##teamcity[testFinished name='CaseInsensitiveEqualsTo is case insensitive' duration="{duration}"] ##teamcity[testStarted name='CaseInsensitiveLess is case insensitive'] @@ -269,6 +285,8 @@ ##teamcity[testFinished name='Combining templated matchers' duration="{duration}"] ##teamcity[testStarted name='Commas in various macros are allowed'] ##teamcity[testFinished name='Commas in various macros are allowed' duration="{duration}"] +##teamcity[testStarted name='Comparing (and stringifying) volatile pointers works'] +##teamcity[testFinished name='Comparing (and stringifying) volatile pointers works' duration="{duration}"] ##teamcity[testStarted name='Comparing function pointers'] ##teamcity[testFinished name='Comparing function pointers' duration="{duration}"] ##teamcity[testStarted name='Comparison ops'] @@ -360,6 +378,8 @@ ##teamcity[testFinished name='Exception message can be matched' duration="{duration}"] ##teamcity[testStarted name='Exception messages can be tested for'] ##teamcity[testFinished name='Exception messages can be tested for' duration="{duration}"] +##teamcity[testStarted name='Exception thrown inside stringify does not fail the test'] +##teamcity[testFinished name='Exception thrown inside stringify does not fail the test' duration="{duration}"] ##teamcity[testStarted name='Exceptions matchers'] ##teamcity[testFinished name='Exceptions matchers' duration="{duration}"] ##teamcity[testStarted name='Expected exceptions that don|'t throw or unexpected exceptions fail the test'] @@ -370,6 +390,10 @@ ##teamcity[testStarted name='FAIL aborts the test'] ##teamcity[testFailed name='FAIL aborts the test' message='Message.tests.cpp:|n...............................................................................|n|nMessage.tests.cpp:|nexplicit failure with message:|n "This is a failure"'] ##teamcity[testFinished name='FAIL aborts the test' duration="{duration}"] +##teamcity[testStarted name='FAIL can be nested in assertion'] +##teamcity[testIgnored name='FAIL can be nested in assertion' message='AssertionHandler.tests.cpp:|n...............................................................................|n|nAssertionHandler.tests.cpp:|nexplicit failure with message:|n "Throw a Catch::TestFailureException"- failure ignore as test marked as |'ok to fail|'|n'] +##teamcity[testIgnored name='FAIL can be nested in assertion' message='AssertionHandler.tests.cpp:|nunexpected exception with message:|n "{ nested assertion failed }"|n CHECK_NOTHROW( do_fail() )|nwith expansion:|n do_fail()|n- failure ignore as test marked as |'ok to fail|'|n'] +##teamcity[testFinished name='FAIL can be nested in assertion' duration="{duration}"] ##teamcity[testStarted name='FAIL does not require an argument'] ##teamcity[testFailed name='FAIL does not require an argument' message='Message.tests.cpp:|n...............................................................................|n|nMessage.tests.cpp:|nexplicit failure'] ##teamcity[testFinished name='FAIL does not require an argument' duration="{duration}"] @@ -431,8 +455,8 @@ ##teamcity[testFinished name='Inequality checks that should succeed' duration="{duration}"] ##teamcity[testStarted name='JsonWriter'] ##teamcity[testFinished name='JsonWriter' duration="{duration}"] -##teamcity[testStarted name='JsonWriter escapes charaters in strings properly'] -##teamcity[testFinished name='JsonWriter escapes charaters in strings properly' duration="{duration}"] +##teamcity[testStarted name='JsonWriter escapes characters in strings properly'] +##teamcity[testFinished name='JsonWriter escapes characters in strings properly' duration="{duration}"] ##teamcity[testStarted name='Lambdas in assertions'] ##teamcity[testFinished name='Lambdas in assertions' duration="{duration}"] ##teamcity[testStarted name='Less-than inequalities with different epsilons'] @@ -566,6 +590,16 @@ ##teamcity[testFinished name='Scenario: This is a really long scenario name to see how the list command deals with wrapping' duration="{duration}"] ##teamcity[testStarted name='Scenario: Vector resizing affects size and capacity'] ##teamcity[testFinished name='Scenario: Vector resizing affects size and capacity' duration="{duration}"] +##teamcity[testStarted name='Scoped message applies to all assertions in scope'] +##teamcity[testFailed name='Scoped message applies to all assertions in scope' message='Message.tests.cpp:|n...............................................................................|n|nMessage.tests.cpp:|nexpression failed with message:|n "This will be reported multiple times"|n CHECK( false )|nwith expansion:|n false|n'] +##teamcity[testFailed name='Scoped message applies to all assertions in scope' message='Message.tests.cpp:|nexpression failed with message:|n "This will be reported multiple times"|n CHECK( false )|nwith expansion:|n false|n'] +##teamcity[testFinished name='Scoped message applies to all assertions in scope' duration="{duration}"] +##teamcity[testStarted name='Scoped messages do not leave block with an exception'] +##teamcity[testFailed name='Scoped messages do not leave block with an exception' message='Message.tests.cpp:|n...............................................................................|n|nMessage.tests.cpp:|nexpression failed with message:|n "Should be in scope at the end"|n REQUIRE( false )|nwith expansion:|n false|n'] +##teamcity[testFinished name='Scoped messages do not leave block with an exception' duration="{duration}"] +##teamcity[testStarted name='Scoped messages outlive section end'] +##teamcity[testFailed name='Scoped messages outlive section end' message='Message.tests.cpp:|n...............................................................................|n|nMessage.tests.cpp:|nexpression failed with message:|n "Should survive a section end"|n REQUIRE( false )|nwith expansion:|n false|n'] +##teamcity[testFinished name='Scoped messages outlive section end' duration="{duration}"] ##teamcity[testStarted name='Sends stuff to stdout and stderr'] ##teamcity[testStdOut name='Sends stuff to stdout and stderr' out='A string sent directly to stdout|n'] ##teamcity[testStdErr name='Sends stuff to stdout and stderr' out='A string sent directly to stderr|nA string sent to stderr via clog|n'] @@ -634,6 +668,14 @@ ##teamcity[testFinished name='TemplateTest: vectors can be sized and resized - std::string' duration="{duration}"] ##teamcity[testStarted name='TemplateTest: vectors can be sized and resized - std::tuple'] ##teamcity[testFinished name='TemplateTest: vectors can be sized and resized - std::tuple' duration="{duration}"] +##teamcity[testStarted name='TemplateTestSig: compiles with a single int parameter - 1'] +##teamcity[testFinished name='TemplateTestSig: compiles with a single int parameter - 1' duration="{duration}"] +##teamcity[testStarted name='TemplateTestSig: compiles with a single int parameter - 3'] +##teamcity[testFinished name='TemplateTestSig: compiles with a single int parameter - 3' duration="{duration}"] +##teamcity[testStarted name='TemplateTestSig: compiles with a single int parameter - 6'] +##teamcity[testFinished name='TemplateTestSig: compiles with a single int parameter - 6' duration="{duration}"] +##teamcity[testStarted name='TemplateTestSig: compiles with two type parameters - int,int'] +##teamcity[testFinished name='TemplateTestSig: compiles with two type parameters - int,int' duration="{duration}"] ##teamcity[testStarted name='TemplateTestSig: vectors can be sized and resized - (std::tuple), 6'] ##teamcity[testFinished name='TemplateTestSig: vectors can be sized and resized - (std::tuple), 6' duration="{duration}"] ##teamcity[testStarted name='TemplateTestSig: vectors can be sized and resized - float,4'] @@ -743,7 +785,7 @@ ##teamcity[testFailed name='When unchecked exceptions are thrown from functions they are always failures' message='Exception.tests.cpp:|n...............................................................................|n|nException.tests.cpp:|nunexpected exception with message:|n "expected exception"|n CHECK( thisThrows() == 0 )|nwith expansion:|n thisThrows() == 0|n'] ##teamcity[testFinished name='When unchecked exceptions are thrown from functions they are always failures' duration="{duration}"] ##teamcity[testStarted name='When unchecked exceptions are thrown from sections they are always failures'] -##teamcity[testFailed name='When unchecked exceptions are thrown from sections they are always failures' message='-------------------------------------------------------------------------------|nsection name|n-------------------------------------------------------------------------------|nException.tests.cpp:|n...............................................................................|n|nException.tests.cpp:|nunexpected exception with message:|n "unexpected exception"'] +##teamcity[testFailed name='When unchecked exceptions are thrown from sections they are always failures' message='-------------------------------------------------------------------------------|nsection name|n-------------------------------------------------------------------------------|nException.tests.cpp:|n...............................................................................|n|nException.tests.cpp:|nunexpected exception with message:|n "unexpected exception"|n {Unknown expression after the reported line}|nwith expansion:|n {Unknown expression after the reported line}|n'] ##teamcity[testFinished name='When unchecked exceptions are thrown from sections they are always failures' duration="{duration}"] ##teamcity[testStarted name='When unchecked exceptions are thrown, but caught, they do not affect the test'] ##teamcity[testFinished name='When unchecked exceptions are thrown, but caught, they do not affect the test' duration="{duration}"] @@ -960,6 +1002,8 @@ ##teamcity[testFinished name='stringify( vectors )' duration="{duration}"] ##teamcity[testStarted name='strlen3'] ##teamcity[testFinished name='strlen3' duration="{duration}"] +##teamcity[testStarted name='system_clock timepoint with non-default duration'] +##teamcity[testFinished name='system_clock timepoint with non-default duration' duration="{duration}"] ##teamcity[testStarted name='tables'] ##teamcity[testFinished name='tables' duration="{duration}"] ##teamcity[testStarted name='tags with dots in later positions are not parsed as hidden'] diff --git a/catch2/tests/SelfTest/Baselines/xml.sw.approved.txt b/catch2/tests/SelfTest/Baselines/xml.sw.approved.txt index aa6bd6a..142d662 100644 --- a/catch2/tests/SelfTest/Baselines/xml.sw.approved.txt +++ b/catch2/tests/SelfTest/Baselines/xml.sw.approved.txt @@ -668,19 +668,51 @@ Nor would this - - failure to init - + + + {Unknown expression after the reported line} + + + {Unknown expression after the reported line} + + + failure to init + + + + + + + + bf.e == 1 + + + 1 == 1 + + + + + 1 == bf.e + + + 1 == 1 + +
- - answer := 42 - - - expected exception - + + + {Unknown expression after the reported line} + + + {Unknown expression after the reported line} + + + expected exception + +
@@ -2703,6 +2735,58 @@ Approx( 1.23399996757507324 ) + + + + i > 10 + + + 2 > 10 + + + + + foo( 2 ) == 2 + + + foo( 2 ) == 2 + + + { nested assertion failed } + + + + + true + + + true + + + + + + + + i > 10 + + + 2 > 10 + + + + + foo( 2 ) == 2 + + + foo( 2 ) == 2 + + + { nested assertion failed } + + + + @@ -3074,6 +3158,48 @@ Approx( 1.23399996757507324 )
+ + + a := 1 + + + + false + + + false + + + + + +
+ + a := 1 + + + + true + + + true + + + +
+ + a := 1 + + + + false + + + false + + + +
@@ -3755,6 +3881,65 @@ C + + + + !(ptr) + + + !0 + + + + + ptr == ptr + + + 0 == 0 + + + + + !(ptr != ptr) + + + !(0 != 0) + + + + + !(ptr < ptr) + + + !(0 < 0) + + + + + ptr <= ptr + + + 0 <= 0 + + + + + !(ptr > ptr) + + + !(0 > 0) + + + + + ptr >= ptr + + + 0 >= 0 + + + + @@ -4995,6 +5180,19 @@ Approx( 1.30000000000000004 )
+ + + + tos == tos + + + { stringification failed with an exception: "Invalid" } +== +{ stringification failed with an exception: "Invalid" } + + + + @@ -5069,6 +5267,23 @@ Approx( 1.30000000000000004 )
+ + + Throw a Catch::TestFailureException + + + + do_fail() + + + do_fail() + + + { nested assertion failed } + + + + @@ -6701,6 +6916,44 @@ Approx( 1.30000000000000004 ) +
+
+ + + gen.get() == 1 + + + 1 == 1 + + + + + gen.next() + + + true + + + + + gen.get() == 3 + + + 3 == 3 + + + + + !(gen.next()) + + + !false + + + +
+ +
@@ -9158,7 +9411,7 @@ Approx( 3.14150000000000018 )
- +
@@ -12877,6 +13130,73 @@ All available test cases:
+ + + This will be reported multiple times + + + + false + + + false + + + + This will be reported multiple times + + + + false + + + false + + + + + + + Should be in scope at the end + + + + false + + + false + + + + + +
+ + Should survive a section end + + + + true + + + true + + + +
+ + Should survive a section end + + + + false + + + false + + + +
@@ -14483,6 +14803,18 @@ Message from section two
+ + + + + + + + + + + + @@ -18337,9 +18669,17 @@ Approx( 1.23999999999999999 )
- - unexpected exception - + + + {Unknown expression after the reported line} + + + {Unknown expression after the reported line} + + + unexpected exception + +
@@ -21094,6 +21434,19 @@ Approx( -1.95996398454005449 )
+ + + + tp1 == tp2 + + + {iso8601-timestamp} +== +{iso8601-timestamp} + + + + @@ -21971,6 +22324,6 @@ Approx( -1.95996398454005449 ) - - + + diff --git a/catch2/tests/SelfTest/Baselines/xml.sw.multi.approved.txt b/catch2/tests/SelfTest/Baselines/xml.sw.multi.approved.txt index 7f3b498..6256233 100644 --- a/catch2/tests/SelfTest/Baselines/xml.sw.multi.approved.txt +++ b/catch2/tests/SelfTest/Baselines/xml.sw.multi.approved.txt @@ -668,19 +668,51 @@ Nor would this
- - failure to init - + + + {Unknown expression after the reported line} + + + {Unknown expression after the reported line} + + + failure to init + + + + + + + + bf.e == 1 + + + 1 == 1 + + + + + 1 == bf.e + + + 1 == 1 + +
- - answer := 42 - - - expected exception - + + + {Unknown expression after the reported line} + + + {Unknown expression after the reported line} + + + expected exception + +
@@ -2703,6 +2735,58 @@ Approx( 1.23399996757507324 ) + + + + i > 10 + + + 2 > 10 + + + + + foo( 2 ) == 2 + + + foo( 2 ) == 2 + + + { nested assertion failed } + + + + + true + + + true + + + + + + + + i > 10 + + + 2 > 10 + + + + + foo( 2 ) == 2 + + + foo( 2 ) == 2 + + + { nested assertion failed } + + + + @@ -3074,6 +3158,48 @@ Approx( 1.23399996757507324 )
+ + + a := 1 + + + + false + + + false + + + + + +
+ + a := 1 + + + + true + + + true + + + +
+ + a := 1 + + + + false + + + false + + + +
@@ -3755,6 +3881,65 @@ C + + + + !(ptr) + + + !0 + + + + + ptr == ptr + + + 0 == 0 + + + + + !(ptr != ptr) + + + !(0 != 0) + + + + + !(ptr < ptr) + + + !(0 < 0) + + + + + ptr <= ptr + + + 0 <= 0 + + + + + !(ptr > ptr) + + + !(0 > 0) + + + + + ptr >= ptr + + + 0 >= 0 + + + + @@ -4995,6 +5180,19 @@ Approx( 1.30000000000000004 )
+ + + + tos == tos + + + { stringification failed with an exception: "Invalid" } +== +{ stringification failed with an exception: "Invalid" } + + + + @@ -5069,6 +5267,23 @@ Approx( 1.30000000000000004 ) + + + Throw a Catch::TestFailureException + + + + do_fail() + + + do_fail() + + + { nested assertion failed } + + + + @@ -6701,6 +6916,44 @@ Approx( 1.30000000000000004 ) +
+
+ + + gen.get() == 1 + + + 1 == 1 + + + + + gen.next() + + + true + + + + + gen.get() == 3 + + + 3 == 3 + + + + + !(gen.next()) + + + !false + + + +
+ +
@@ -9158,7 +9411,7 @@ Approx( 3.14150000000000018 )
- +
@@ -12877,6 +13130,73 @@ All available test cases:
+ + + This will be reported multiple times + + + + false + + + false + + + + This will be reported multiple times + + + + false + + + false + + + + + + + Should be in scope at the end + + + + false + + + false + + + + + +
+ + Should survive a section end + + + + true + + + true + + + +
+ + Should survive a section end + + + + false + + + false + + + +
@@ -14483,6 +14803,18 @@ Message from section two
+ + + + + + + + + + + + @@ -18337,9 +18669,17 @@ Approx( 1.23999999999999999 )
- - unexpected exception - + + + {Unknown expression after the reported line} + + + {Unknown expression after the reported line} + + + unexpected exception + +
@@ -21093,6 +21433,19 @@ Approx( -1.95996398454005449 )
+ + + + tp1 == tp2 + + + {iso8601-timestamp} +== +{iso8601-timestamp} + + + + @@ -21970,6 +22323,6 @@ Approx( -1.95996398454005449 ) - - + + diff --git a/catch2/tests/SelfTest/IntrospectiveTests/AssertionHandler.tests.cpp b/catch2/tests/SelfTest/IntrospectiveTests/AssertionHandler.tests.cpp index ab09607..15966a0 100644 --- a/catch2/tests/SelfTest/IntrospectiveTests/AssertionHandler.tests.cpp +++ b/catch2/tests/SelfTest/IntrospectiveTests/AssertionHandler.tests.cpp @@ -15,3 +15,28 @@ TEST_CASE( "Incomplete AssertionHandler", "[assertion-handler][!shouldfail]" ) { "Dummy", Catch::ResultDisposition::Normal ); } + + +static int foo( int i ) { + REQUIRE( i > 10 ); + return 42; +} + +TEST_CASE( "Assertions can be nested - CHECK", "[assertions][!shouldfail]" ) { + CHECK( foo( 2 ) == 2 ); + // We should hit this, because CHECK continues on failure + CHECK( true ); +} + +TEST_CASE( "Assertions can be nested - REQUIRE", "[assertions][!shouldfail]" ) { + REQUIRE( foo( 2 ) == 2 ); + // We should not hit this, because REQUIRE does not continue on failure + CHECK( true ); +} + +static void do_fail() { FAIL( "Throw a Catch::TestFailureException" ); } + +TEST_CASE( "FAIL can be nested in assertion", "[assertions][!shouldfail]" ) { + // Fails, but the error message makes sense. + CHECK_NOTHROW( do_fail() ); +} diff --git a/catch2/tests/SelfTest/IntrospectiveTests/Clara.tests.cpp b/catch2/tests/SelfTest/IntrospectiveTests/Clara.tests.cpp index 53023b5..0fadad6 100644 --- a/catch2/tests/SelfTest/IntrospectiveTests/Clara.tests.cpp +++ b/catch2/tests/SelfTest/IntrospectiveTests/Clara.tests.cpp @@ -25,19 +25,19 @@ TEST_CASE("is_unary_function", "[clara][compilation]") { auto nullary1 = []() {}; auto nullary2 = []() {return 42;}; - STATIC_REQUIRE(Catch::Clara::Detail::is_unary_function::value); - STATIC_REQUIRE(Catch::Clara::Detail::is_unary_function::value); - STATIC_REQUIRE(Catch::Clara::Detail::is_unary_function::value); - STATIC_REQUIRE(Catch::Clara::Detail::is_unary_function::value); - STATIC_REQUIRE(Catch::Clara::Detail::is_unary_function::value); - STATIC_REQUIRE(Catch::Clara::Detail::is_unary_function::value); - - STATIC_REQUIRE_FALSE(Catch::Clara::Detail::is_unary_function::value); - STATIC_REQUIRE_FALSE(Catch::Clara::Detail::is_unary_function::value); - STATIC_REQUIRE_FALSE(Catch::Clara::Detail::is_unary_function::value); - STATIC_REQUIRE_FALSE(Catch::Clara::Detail::is_unary_function::value); - STATIC_REQUIRE_FALSE(Catch::Clara::Detail::is_unary_function::value); - STATIC_REQUIRE_FALSE(Catch::Clara::Detail::is_unary_function::value); + STATIC_REQUIRE(Catch::Clara::Detail::is_unary_function_v); + STATIC_REQUIRE(Catch::Clara::Detail::is_unary_function_v); + STATIC_REQUIRE(Catch::Clara::Detail::is_unary_function_v); + STATIC_REQUIRE(Catch::Clara::Detail::is_unary_function_v); + STATIC_REQUIRE(Catch::Clara::Detail::is_unary_function_v); + STATIC_REQUIRE(Catch::Clara::Detail::is_unary_function_v); + + STATIC_REQUIRE_FALSE(Catch::Clara::Detail::is_unary_function_v); + STATIC_REQUIRE_FALSE(Catch::Clara::Detail::is_unary_function_v); + STATIC_REQUIRE_FALSE(Catch::Clara::Detail::is_unary_function_v); + STATIC_REQUIRE_FALSE(Catch::Clara::Detail::is_unary_function_v); + STATIC_REQUIRE_FALSE(Catch::Clara::Detail::is_unary_function_v); + STATIC_REQUIRE_FALSE(Catch::Clara::Detail::is_unary_function_v); } diff --git a/catch2/tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp b/catch2/tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp index 14c9011..c044547 100644 --- a/catch2/tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp +++ b/catch2/tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp @@ -85,6 +85,19 @@ TEST_CASE("Generators internals", "[generators][internals]") { filter([](int) { return false; }, values({ 1, 2, 3 })), Catch::GeneratorException); } + + // Non-trivial usage + SECTION("Out-of-line predicates are copied into the generator") { + auto evilNumber = Catch::Detail::make_unique(2); + auto gen = [&]{ + const auto predicate = [&](int i) { return i != *evilNumber; }; + return filter(predicate, values({ 2, 1, 2, 3, 2, 2 })); + }(); + REQUIRE(gen.get() == 1); + REQUIRE(gen.next()); + REQUIRE(gen.get() == 3); + REQUIRE_FALSE(gen.next()); + } } SECTION("Take generator") { SECTION("Take less") { diff --git a/catch2/tests/SelfTest/IntrospectiveTests/Integer.tests.cpp b/catch2/tests/SelfTest/IntrospectiveTests/Integer.tests.cpp index 8955f40..4ce2ae6 100644 --- a/catch2/tests/SelfTest/IntrospectiveTests/Integer.tests.cpp +++ b/catch2/tests/SelfTest/IntrospectiveTests/Integer.tests.cpp @@ -22,7 +22,7 @@ namespace { ExtendedMultResult{ upper_result, lower_result } ); } - // Simple (and slow) implmentation of extended multiplication for tests + // Simple (and slow) implementation of extended multiplication for tests constexpr Catch::Detail::ExtendedMultResult extendedMultNaive( std::uint64_t lhs, std::uint64_t rhs ) { // This is a simple long multiplication, where we split lhs and rhs diff --git a/catch2/tests/SelfTest/IntrospectiveTests/Json.tests.cpp b/catch2/tests/SelfTest/IntrospectiveTests/Json.tests.cpp index 8204e3c..fae1c84 100644 --- a/catch2/tests/SelfTest/IntrospectiveTests/Json.tests.cpp +++ b/catch2/tests/SelfTest/IntrospectiveTests/Json.tests.cpp @@ -7,6 +7,8 @@ // SPDX-License-Identifier: BSL-1.0 #include +#include +#include #include #include @@ -17,7 +19,6 @@ namespace { static std::ostream& operator<<( std::ostream& os, Custom const& ) { return os << "custom"; } -} // namespace TEST_CASE( "JsonWriter", "[JSON][JsonWriter]" ) { @@ -111,7 +112,7 @@ TEST_CASE( "JsonWriter", "[JSON][JsonWriter]" ) { } } -TEST_CASE( "JsonWriter escapes charaters in strings properly", "[JsonWriter]" ) { +TEST_CASE( "JsonWriter escapes characters in strings properly", "[JsonWriter]" ) { std::stringstream sstream; SECTION( "Quote in a string is escaped" ) { Catch::JsonValueWriter{ sstream }.write( "\"" ); @@ -150,3 +151,28 @@ TEST_CASE( "JsonWriter escapes charaters in strings properly", "[JsonWriter]" ) REQUIRE( sstream.str() == "\"\\\\/\\t\\r\\n\"" ); } } + +TEST_CASE( "JsonWriter benchmarks", "[JsonWriter][!benchmark]" ) { + const auto input_length = GENERATE( as{}, 10, 100, 10'000 ); + std::string test_input( input_length, 'a' ); + BENCHMARK_ADVANCED( "write string, no-escaping, len=" + + std::to_string( input_length ) )( + Catch::Benchmark::Chronometer meter ) { + std::stringstream sstream; + meter.measure( [&]( int ) { + Catch::JsonValueWriter( sstream ).write( test_input ); + } ); + }; + + std::string escape_input( input_length, '\b' ); + BENCHMARK_ADVANCED( "write string, all-escaped, len=" + + std::to_string( input_length ) )( + Catch::Benchmark::Chronometer meter ) { + std::stringstream sstream; + meter.measure( [&]( int ) { + Catch::JsonValueWriter( sstream ).write( escape_input ); + } ); + }; +} + +} // namespace diff --git a/catch2/tests/SelfTest/IntrospectiveTests/RandomNumberGeneration.tests.cpp b/catch2/tests/SelfTest/IntrospectiveTests/RandomNumberGeneration.tests.cpp index 8932321..5166070 100644 --- a/catch2/tests/SelfTest/IntrospectiveTests/RandomNumberGeneration.tests.cpp +++ b/catch2/tests/SelfTest/IntrospectiveTests/RandomNumberGeneration.tests.cpp @@ -151,7 +151,7 @@ TEMPLATE_TEST_CASE( "uniform_integer_distribution can handle unit ranges", Catch::SimplePcg32 pcg( seed ); // We check unitary ranges of 3 different values, min for type, max for type, - // some value inbetween just to make sure + // some value in between just to make sure SECTION("lowest value") { constexpr auto lowest = std::numeric_limits::min(); Catch::uniform_integer_distribution dist( lowest, lowest ); @@ -180,7 +180,7 @@ TEST_CASE( "uniform_integer_distribution can handle boolean unit ranges", Catch::SimplePcg32 pcg( seed ); // We check unitary ranges of 3 different values, min for type, max for - // type, some value inbetween just to make sure + // type, some value in between just to make sure SECTION( "lowest value" ) { Catch::uniform_integer_distribution dist( false, false ); CheckReturnValue( dist, pcg, false ); diff --git a/catch2/tests/SelfTest/IntrospectiveTests/ToString.tests.cpp b/catch2/tests/SelfTest/IntrospectiveTests/ToString.tests.cpp index e190460..01d989a 100644 --- a/catch2/tests/SelfTest/IntrospectiveTests/ToString.tests.cpp +++ b/catch2/tests/SelfTest/IntrospectiveTests/ToString.tests.cpp @@ -6,11 +6,13 @@ // SPDX-License-Identifier: BSL-1.0 +#include +#include +#include +#include #include #include #include -#include -#include #include @@ -103,18 +105,62 @@ TEST_CASE( "#2944 - Stringifying dates before 1970 should not crash", "[.approva using Catch::Matchers::Equals; using Days = std::chrono::duration>; using SysDays = std::chrono::time_point; - Catch::StringMaker sm; + using SM = Catch::StringMaker; // Check simple date first const SysDays post1970{ Days{ 1 } }; - auto converted_post = sm.convert( post1970 ); + auto converted_post = SM::convert( post1970 ); REQUIRE( converted_post == "1970-01-02T00:00:00Z" ); const SysDays pre1970{ Days{ -1 } }; - auto converted_pre = sm.convert( pre1970 ); + auto converted_pre = SM::convert( pre1970 ); REQUIRE_THAT( converted_pre, Equals( "1969-12-31T00:00:00Z" ) || Equals( "gmtime from provided timepoint has failed. This " "happens e.g. with pre-1970 dates using Microsoft libc" ) ); } + +namespace { + struct ThrowsOnStringification { + friend bool operator==( ThrowsOnStringification, + ThrowsOnStringification ) { + return true; + } + }; +} + +template <> +struct Catch::StringMaker { + static std::string convert(ThrowsOnStringification) { + throw std::runtime_error( "Invalid" ); + } +}; + +TEST_CASE( "Exception thrown inside stringify does not fail the test", "[toString]" ) { + ThrowsOnStringification tos; + CHECK( tos == tos ); +} + +TEST_CASE( "string escaping benchmark", "[toString][!benchmark]" ) { + const auto input_length = GENERATE( as{}, 10, 100, 10'000, 100'000 ); + std::string test_input( input_length, 'a' ); + BENCHMARK( "no-escape string, no-escaping, len=" + + std::to_string( input_length ) ) { + return Catch::Detail::convertIntoString( test_input, false ); + }; + BENCHMARK( "no-escape string, escaping, len=" + + std::to_string( input_length ) ) { + return Catch::Detail::convertIntoString( test_input, true ); + }; + + std::string escape_input( input_length, '\r' ); + BENCHMARK( "full escape string, no-escaping, len=" + + std::to_string( input_length ) ) { + return Catch::Detail::convertIntoString( escape_input, false ); + }; + BENCHMARK( "full escape string, escaping, len=" + + std::to_string( input_length ) ) { + return Catch::Detail::convertIntoString( escape_input, true ); + }; +} diff --git a/catch2/tests/SelfTest/IntrospectiveTests/Xml.tests.cpp b/catch2/tests/SelfTest/IntrospectiveTests/Xml.tests.cpp index b5982b8..a53bae3 100644 --- a/catch2/tests/SelfTest/IntrospectiveTests/Xml.tests.cpp +++ b/catch2/tests/SelfTest/IntrospectiveTests/Xml.tests.cpp @@ -7,13 +7,16 @@ // SPDX-License-Identifier: BSL-1.0 #include -#include - +#include +#include #include +#include #include #include +namespace { + static std::string encode( std::string const& str, Catch::XmlEncode::ForWhat forWhat = Catch::XmlEncode::ForTextNodes ) { Catch::ReusableStringStream oss; oss << Catch::XmlEncode( str, forWhat ); @@ -181,3 +184,20 @@ TEST_CASE("XmlWriter escapes attributes properly", "[XML][XmlWriter][approvals]" REQUIRE_THAT(stream.str(), ContainsSubstring(R"(some-attribute="Special chars need escaping: < > ' " &")")); } + +TEST_CASE( "XmlWriter benchmarks", "[XML][XmlWriter][!benchmark]" ) { + const auto input_length = GENERATE( as{}, 10, 100, 10'000 ); + std::string test_input( input_length, 'a' ); + BENCHMARK_ADVANCED( "write string, no-escaping, len=" + + std::to_string( input_length ) ) { + return encode( test_input ); + }; + + std::string escape_input( input_length, '\b' ); + BENCHMARK_ADVANCED( "write string, all-escaped, len=" + + std::to_string( input_length ) ) { + return encode( escape_input ); + }; +} + +} // namespace diff --git a/catch2/tests/SelfTest/TestRegistrations.cpp b/catch2/tests/SelfTest/TestRegistrations.cpp index d7a6966..1a7be39 100644 --- a/catch2/tests/SelfTest/TestRegistrations.cpp +++ b/catch2/tests/SelfTest/TestRegistrations.cpp @@ -54,6 +54,7 @@ class ValidatingTestListener : public Catch::EventListenerBase { ValidatingTestListener(Catch::IConfig const* config) : EventListenerBase(config) { m_preferences.shouldReportAllAssertions = true; + m_preferences.shouldReportAllAssertionStarts = true; } void testRunStarting( Catch::TestRunInfo const& ) override { diff --git a/catch2/tests/SelfTest/UsageTests/Compilation.tests.cpp b/catch2/tests/SelfTest/UsageTests/Compilation.tests.cpp index 7a6a1f2..d881335 100644 --- a/catch2/tests/SelfTest/UsageTests/Compilation.tests.cpp +++ b/catch2/tests/SelfTest/UsageTests/Compilation.tests.cpp @@ -144,6 +144,23 @@ TEST_CASE("#1027: Bitfields can be captured") { REQUIRE(0 == y.v); } +TEST_CASE( "#3001: Enum-based bitfields can be captured" ) { + enum E { + ZERO = 0, + ONE = 1, + TWO = 2, + }; + + struct BF { + E e : 2; + }; + + BF bf{}; + bf.e = ONE; + REQUIRE( bf.e == 1 ); + REQUIRE( 1 == bf.e ); +} + // Comparison operators can return non-booleans. // This is unusual, but should be supported. TEST_CASE("#1147") { diff --git a/catch2/tests/SelfTest/UsageTests/Message.tests.cpp b/catch2/tests/SelfTest/UsageTests/Message.tests.cpp index 7626e00..07d3ee7 100644 --- a/catch2/tests/SelfTest/UsageTests/Message.tests.cpp +++ b/catch2/tests/SelfTest/UsageTests/Message.tests.cpp @@ -310,3 +310,53 @@ TEST_CASE( "INFO and UNSCOPED_INFO can stream multiple arguments", << " parts." ); FAIL( "Show infos!" ); } + +TEST_CASE( "Scoped messages do not leave block with an exception", "[messages][info][.failing]" ) { + INFO( "Should be in scope at the end" ); + { INFO( "This should go out of scope immediately" ); } + + try { + INFO( "Should not be in scope at the end" ); + throw std::runtime_error( "ex" ); + } catch (std::exception const&) {} + + REQUIRE( false ); +} + +TEST_CASE( "Captures do not leave block with an exception", + "[messages][capture][.failing]" ) { + int a = 1, b = 2, c = 3; + + CAPTURE( a ); + { CAPTURE( b ); } + + try { + CAPTURE( c ); + throw std::runtime_error( "ex" ); + } catch ( std::exception const& ) {} + + REQUIRE( false ); +} + +TEST_CASE( "Scoped messages outlive section end", + "[messages][info][.failing]" ) { + INFO( "Should survive a section end" ); + SECTION( "Dummy section" ) { CHECK( true ); } + + REQUIRE( false ); +} + +TEST_CASE( "Captures outlive section end", "[messages][info][.failing]" ) { + int a = 1; + CAPTURE( a ); + SECTION( "Dummy section" ) { CHECK( true ); } + + REQUIRE( false ); +} + +TEST_CASE( "Scoped message applies to all assertions in scope", + "[messages][info][.failing]" ) { + INFO( "This will be reported multiple times" ); + CHECK( false ); + CHECK( false ); +} diff --git a/catch2/tests/SelfTest/UsageTests/Misc.tests.cpp b/catch2/tests/SelfTest/UsageTests/Misc.tests.cpp index 3697f06..dec51ab 100644 --- a/catch2/tests/SelfTest/UsageTests/Misc.tests.cpp +++ b/catch2/tests/SelfTest/UsageTests/Misc.tests.cpp @@ -56,7 +56,7 @@ namespace { CATCH_INTERNAL_START_WARNINGS_SUPPRESSION CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS - static AutoTestReg autoTestReg; + static const AutoTestReg autoTestReg; CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION template @@ -334,6 +334,10 @@ TEMPLATE_TEST_CASE( "TemplateTest: vectors can be sized and resized", "[vector][ } } +TEMPLATE_TEST_CASE_SIG("TemplateTestSig: compiles with a single int parameter", "[template][singleint]", ((int V), V), 1, 3, 6) {} + +TEMPLATE_TEST_CASE_SIG("TemplateTestSig: compiles with two type parameters", "[template][onlytypes]", ((typename U, typename V), U, V), (int,int)) {} + TEMPLATE_TEST_CASE_SIG("TemplateTestSig: vectors can be sized and resized", "[vector][template][nttp]", ((typename TestType, int V), TestType, V), (int,5), (float,4), (std::string,15), ((std::tuple), 6)) { std::vector v(V); @@ -558,3 +562,15 @@ TEST_CASE("Validate SEH behavior - no crash for stack unwinding", "[approvals][! } #endif // _MSC_VER + +TEST_CASE( "Comparing (and stringifying) volatile pointers works", + "[volatile]" ) { + volatile int* ptr = nullptr; + REQUIRE_FALSE( ptr ); + REQUIRE( ptr == ptr ); + REQUIRE_FALSE( ptr != ptr ); + REQUIRE_FALSE( ptr < ptr ); + REQUIRE( ptr <= ptr ); + REQUIRE_FALSE( ptr > ptr ); + REQUIRE( ptr >= ptr ); +} diff --git a/catch2/tests/SelfTest/UsageTests/ToStringChrono.tests.cpp b/catch2/tests/SelfTest/UsageTests/ToStringChrono.tests.cpp index 744b899..931b4b2 100644 --- a/catch2/tests/SelfTest/UsageTests/ToStringChrono.tests.cpp +++ b/catch2/tests/SelfTest/UsageTests/ToStringChrono.tests.cpp @@ -49,3 +49,9 @@ TEST_CASE("Stringifying std::chrono::time_point", "[toString][chrono][!no auto later2 = now2 + std::chrono::minutes(2); REQUIRE(now2 != later2); } + +TEST_CASE( "system_clock timepoint with non-default duration", "[toString][chrono]" ) { + std::chrono::time_point + tp1, tp2; + CHECK( tp1 == tp2 ); +} diff --git a/catch2/tests/TestScripts/ConfigureTestsCommon.py b/catch2/tests/TestScripts/ConfigureTestsCommon.py index 13b1d92..66896a8 100644 --- a/catch2/tests/TestScripts/ConfigureTestsCommon.py +++ b/catch2/tests/TestScripts/ConfigureTestsCommon.py @@ -15,7 +15,7 @@ def configure_and_build(source_path: str, project_path: str, options: List[Tuple[str, str]]): base_configure_cmd = ['cmake', '-B{}'.format(project_path), - '-H{}'.format(source_path), + '-S{}'.format(source_path), '-DCMAKE_BUILD_TYPE=Debug', '-DCATCH_DEVELOPMENT_BUILD=ON'] for option, value in options: diff --git a/catch2/tests/TestScripts/DiscoverTests/CMakeLists.txt b/catch2/tests/TestScripts/DiscoverTests/CMakeLists.txt index f0b49f4..1bcefbb 100644 --- a/catch2/tests/TestScripts/DiscoverTests/CMakeLists.txt +++ b/catch2/tests/TestScripts/DiscoverTests/CMakeLists.txt @@ -1,24 +1,18 @@ cmake_minimum_required(VERSION 3.16) +project(discover-tests-test LANGUAGES CXX) -project(discover-tests-test - LANGUAGES CXX -) - -add_executable(tests - register-tests.cpp -) - +add_executable(tests register-tests.cpp) add_subdirectory(${CATCH2_PATH} catch2-build) target_link_libraries(tests PRIVATE Catch2::Catch2WithMain) enable_testing() include(Catch) set(extra_args) -if (CMAKE_VERSION GREATER_EQUAL 3.27) - list(APPEND extra_args - DL_PATHS "${CMAKE_CURRENT_LIST_DIR};${CMAKE_CURRENT_LIST_DIR}/.." - ) -endif () +if(CMAKE_VERSION GREATER_EQUAL 3.27) + list(APPEND extra_args + DL_PATHS "${CMAKE_CURRENT_LIST_DIR};${CMAKE_CURRENT_LIST_DIR}/.." + ) +endif() catch_discover_tests( tests ADD_TAGS_AS_LABELS diff --git a/catch2/tests/TestScripts/DiscoverTests/VerifyRegistration.py b/catch2/tests/TestScripts/DiscoverTests/VerifyRegistration.py index 33150ca..7d9862c 100644 --- a/catch2/tests/TestScripts/DiscoverTests/VerifyRegistration.py +++ b/catch2/tests/TestScripts/DiscoverTests/VerifyRegistration.py @@ -17,7 +17,7 @@ TestInfo = namedtuple('TestInfo', ['name', 'tags']) -cmake_version_regex = re.compile('cmake version (\d+)\.(\d+)\.(\d+)') +cmake_version_regex = re.compile(r'cmake version (\d+)\.(\d+)\.(\d+)') def get_cmake_version(): result = subprocess.run(['cmake', '--version'], diff --git a/catch2/tests/TestScripts/testBazelExitGuardFile.py b/catch2/tests/TestScripts/testBazelExitGuardFile.py new file mode 100755 index 0000000..b4d31b5 --- /dev/null +++ b/catch2/tests/TestScripts/testBazelExitGuardFile.py @@ -0,0 +1,88 @@ +#!/usr/bin/env python3 + +# Copyright Catch2 Authors +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE.txt or copy at +# https://www.boost.org/LICENSE_1_0.txt) + +# SPDX-License-Identifier: BSL-1.0 + +import os +import sys +import subprocess + +def generate_path_suffix() -> str: + return os.urandom(16).hex()[:16] + + +def run_common(cmd, env = None): + cmd_env = env if env is not None else os.environ.copy() + print('Running:', cmd) + + try: + ret = subprocess.run( + cmd, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + check=True, + universal_newlines=True, + env=cmd_env + ) + except subprocess.SubprocessError as ex: + print('Could not run "{}"'.format(cmd)) + print("Return code: {}".format(ex.returncode)) + print("stdout: {}".format(ex.stdout)) + print("stderr: {}".format(ex.stderr)) + raise + + +def test_bazel_env_vars(bin_path, guard_path): + env = os.environ.copy() + env["TEST_PREMATURE_EXIT_FILE"] = guard_path + env["BAZEL_TEST"] = '1' + run_common([bin_path], env) + +def test_cli_parameter(bin_path, guard_path): + cmd = [ + bin_path, + '--premature-exit-guard-file', + guard_path + ] + run_common(cmd) + +def test_no_crash(bin_path, guard_path): + cmd = [ + bin_path, + '--premature-exit-guard-file', + guard_path, + # Disable the quick-exit test + '~[quick_exit]' + ] + run_common(cmd) + +checks = { + 'bazel': (test_bazel_env_vars, True), + 'cli': (test_cli_parameter, True), + 'no-crash': (test_no_crash, False), +} + + +bin_path = os.path.abspath(sys.argv[1]) +output_dir = os.path.abspath(sys.argv[2]) +test_kind = sys.argv[3] +guard_file_path = os.path.join(output_dir, f"guard_file.{generate_path_suffix()}") +print(f'Guard file path: "{guard_file_path}"') + +check_func, file_should_exist = checks[test_kind] +check_func(bin_path, guard_file_path) + +assert os.path.exists(guard_file_path) == file_should_exist +# With randomly generated file suffix, we should not run into name conflicts. +# However, we try to cleanup anyway, to avoid having infinity files in +# long living build directories. +if file_should_exist: + try: + os.remove(guard_file_path) + except Exception as ex: + print(f'Could not remove file {guard_file_path} because: {ex}') + diff --git a/catch2/tests/TestScripts/testBazelSharding.py b/catch2/tests/TestScripts/testBazelSharding.py index d4a9aee..2359446 100755 --- a/catch2/tests/TestScripts/testBazelSharding.py +++ b/catch2/tests/TestScripts/testBazelSharding.py @@ -46,10 +46,15 @@ env["TEST_TOTAL_SHARDS"] = "2" env["TEST_SHARD_STATUS_FILE"] = info_file_path +cmd = [ + bin_path, + # We rely on the test order being deterministic + '--order', 'decl' +] try: ret = subprocess.run( - bin_path, + cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True, diff --git a/catch2/tools/misc/CMakeLists.txt b/catch2/tools/misc/CMakeLists.txt index 59811df..39e816a 100644 --- a/catch2/tools/misc/CMakeLists.txt +++ b/catch2/tools/misc/CMakeLists.txt @@ -1,11 +1,8 @@ cmake_minimum_required(VERSION 3.16) - -project(CatchCoverageHelper) +project(CatchCoverageHelper LANGUAGES CXX) add_executable(CoverageHelper coverage-helper.cpp) -set_property(TARGET CoverageHelper PROPERTY CXX_STANDARD 11) -set_property(TARGET CoverageHelper PROPERTY CXX_STANDARD_REQUIRED ON) -set_property(TARGET CoverageHelper PROPERTY CXX_EXTENSIONS OFF) -if (MSVC) - target_compile_options( CoverageHelper PRIVATE /W4 /w44265 /WX /w44061 /w44062 ) +target_compile_features(CoverageHelper PRIVATE cxx_std_11) +if(MSVC) + target_compile_options(CoverageHelper PRIVATE /W4 /w44265 /WX /w44061 /w44062) endif() diff --git a/catch2/tools/misc/appveyorBuildConfigurationScript.bat b/catch2/tools/misc/appveyorBuildConfigurationScript.bat index 727f829..75b3955 100644 --- a/catch2/tools/misc/appveyorBuildConfigurationScript.bat +++ b/catch2/tools/misc/appveyorBuildConfigurationScript.bat @@ -8,14 +8,14 @@ SETLOCAL EnableDelayedExpansion if "%CONFIGURATION%"=="Debug" ( if "%coverage%"=="1" ( @REM # coverage needs to build the special helper as well as the main - cmake -Htools/misc -Bbuild-misc -A%PLATFORM% || exit /b !ERRORLEVEL! + cmake -Stools/misc -Bbuild-misc -A%PLATFORM% || exit /b !ERRORLEVEL! cmake --build build-misc || exit /b !ERRORLEVEL! - cmake -H. -BBuild -A%PLATFORM% -DCATCH_TEST_USE_WMAIN=%wmain% -DMEMORYCHECK_COMMAND=build-misc\Debug\CoverageHelper.exe -DMEMORYCHECK_COMMAND_OPTIONS=--sep-- -DMEMORYCHECK_TYPE=Valgrind -DCATCH_BUILD_EXAMPLES=%examples% -DCATCH_BUILD_EXTRA_TESTS=%examples% -DCATCH_ENABLE_CONFIGURE_TESTS=%configure_tests% -DCATCH_DEVELOPMENT_BUILD=ON || exit /b !ERRORLEVEL! + cmake -S. -BBuild -A%PLATFORM% -DCATCH_TEST_USE_WMAIN=%wmain% -DMEMORYCHECK_COMMAND=build-misc\Debug\CoverageHelper.exe -DMEMORYCHECK_COMMAND_OPTIONS=--sep-- -DMEMORYCHECK_TYPE=Valgrind -DCATCH_BUILD_EXAMPLES=%examples% -DCATCH_BUILD_EXTRA_TESTS=%examples% -DCATCH_ENABLE_CONFIGURE_TESTS=%configure_tests% -DCATCH_DEVELOPMENT_BUILD=ON || exit /b !ERRORLEVEL! ) else ( @REM # We know that coverage is 0 - cmake -H. -BBuild -A%PLATFORM% -DCATCH_TEST_USE_WMAIN=%wmain% -DCATCH_BUILD_EXAMPLES=%examples% -DCATCH_BUILD_EXTRA_TESTS=%examples% -DCATCH_BUILD_SURROGATES=%surrogates% -DCATCH_DEVELOPMENT_BUILD=ON -DCATCH_ENABLE_CONFIGURE_TESTS=%configure_tests% || exit /b !ERRORLEVEL! + cmake -S. -BBuild -A%PLATFORM% -DCATCH_TEST_USE_WMAIN=%wmain% -DCATCH_BUILD_EXAMPLES=%examples% -DCATCH_BUILD_EXTRA_TESTS=%examples% -DCATCH_BUILD_SURROGATES=%surrogates% -DCATCH_DEVELOPMENT_BUILD=ON -DCATCH_ENABLE_CONFIGURE_TESTS=%configure_tests% || exit /b !ERRORLEVEL! ) ) if "%CONFIGURATION%"=="Release" ( - cmake -H. -BBuild -A%PLATFORM% -DCATCH_TEST_USE_WMAIN=%wmain% -DCATCH_DEVELOPMENT_BUILD=ON || exit /b !ERRORLEVEL! + cmake -S. -BBuild -A%PLATFORM% -DCATCH_TEST_USE_WMAIN=%wmain% -DCATCH_DEVELOPMENT_BUILD=ON || exit /b !ERRORLEVEL! ) diff --git a/catch2/tools/misc/installOpenCppCoverage.ps1 b/catch2/tools/misc/installOpenCppCoverage.ps1 index 215fe20..795b7c8 100644 --- a/catch2/tools/misc/installOpenCppCoverage.ps1 +++ b/catch2/tools/misc/installOpenCppCoverage.ps1 @@ -4,7 +4,7 @@ $installerPath = [System.IO.Path]::Combine($Env:USERPROFILE, "Downloads", "OpenC if(-Not (Test-Path $installerPath)) { Write-Host -ForegroundColor White ("Downloading OpenCppCoverage from: " + $downloadUrl) - Start-FileDownload $downloadUrl -FileName $installerPath + Start-BitsTransfer $downloadUrl -Destination $installerPath } Write-Host -ForegroundColor White "About to install OpenCppCoverage..." diff --git a/catch2/tools/scripts/approvalTests.py b/catch2/tools/scripts/approvalTests.py index 4146b64..144edc0 100755 --- a/catch2/tools/scripts/approvalTests.py +++ b/catch2/tools/scripts/approvalTests.py @@ -121,7 +121,7 @@ def filterLine(line, isCompact): # strip source line numbers # Note that this parser assumes an already normalized filepath from above, # and might break terribly if it is moved around before the normalization. - line = filelocParser.sub('\g:', line) + line = filelocParser.sub(r'\g:', line) line = lineNumberParser.sub(" ", line) @@ -130,7 +130,7 @@ def filterLine(line, isCompact): line = line.replace(': PASSED', ': passed') # strip out the test order number in TAP to avoid massive diffs for every change - line = tapTestNumParser.sub("\g<1> {test-number} -", line) + line = tapTestNumParser.sub(r"\g<1> {test-number} -", line) # strip Catch2 version number line = versionParser.sub("", line) @@ -148,7 +148,7 @@ def filterLine(line, isCompact): line = junitDurationsParser.sub(' time="{duration}"', line) line = durationParser.sub(' duration="{duration}"', line) line = timestampsParser.sub('{iso8601-timestamp}', line) - line = specialCaseParser.sub('file:\g<1>', line) + line = specialCaseParser.sub(r'file:\g<1>', line) line = sinceEpochParser.sub('{since-epoch-report}', line) return line diff --git a/catch2/tools/scripts/checkConvenienceHeaders.py b/catch2/tools/scripts/checkConvenienceHeaders.py index 41b52ce..0695752 100755 --- a/catch2/tools/scripts/checkConvenienceHeaders.py +++ b/catch2/tools/scripts/checkConvenienceHeaders.py @@ -21,11 +21,11 @@ import re def normalized_path(path): - """Replaces \ in paths on Windows with /""" + r"""Replaces \ in paths on Windows with /""" return path.replace('\\', '/') def normalized_paths(paths): - """Replaces \ with / in every path""" + r"""Replaces \ with / in every path""" return [normalized_path(path) for path in paths] source_path = catchPath + '/src/catch2' diff --git a/catch2/tools/scripts/releaseCommon.py b/catch2/tools/scripts/releaseCommon.py index 81efa76..920fb98 100644 --- a/catch2/tools/scripts/releaseCommon.py +++ b/catch2/tools/scripts/releaseCommon.py @@ -114,7 +114,7 @@ def updateVersionDefine(version): def updateVersionPlaceholder(filename, version): with open(filename, 'rb') as file: lines = file.readlines() - placeholderRegex = re.compile(b'Catch[0-9]? X.Y.Z') + placeholderRegex = re.compile(b'Catch[0-9]? v?X.Y.Z') replacement = 'Catch2 {}.{}.{}'.format(version.majorVersion, version.minorVersion, version.patchNumber).encode('ascii') with open(filename, 'wb') as file: for line in lines: diff --git a/foamut b/foamut new file mode 100755 index 0000000..4da3312 --- /dev/null +++ b/foamut @@ -0,0 +1,916 @@ +#!/usr/bin/env bash +# This script was generated by bashly 1.2.10 (https://bashly.dev) +# Modifying it manually is not recommended + +# :wrapper.bash3_bouncer +if [[ "${BASH_VERSINFO:-0}" -lt 4 ]]; then + printf "bash version 4 or higher is required\n" >&2 + exit 1 +fi + +# :command.master_script +# :command.root_command +root_command() { + # src/root_command.sh + # Main command logic for foamUT + # Orchestrates the entire test execution pipeline + + # ShellChecked on every push - Always ShellCheck your scripts! + + # Validate custom test driver if provided + if [ -n "${args[--test-driver]}" ]; then + driver_path="${args[--test-driver]}" + if [ ! -f "$driver_path" ]; then + echo "Error: Test driver file not found: $driver_path" >&2 + exit 1 + fi + if [[ ! "$driver_path" =~ \.(C|cpp)$ ]]; then + echo "Error: Test driver must be a .C or .cpp source file" >&2 + exit 1 + fi + fi + + # Validate --force-timeout is only used with --test-prefix + if [ "${args[--force-timeout]}" = "1" ] && [ -z "${args[--test-prefix]}" ]; then + echo "Warning: --force-timeout has no effect without --test-prefix" >&2 + fi + + # Validate --standalone is not used with --parallel + if [ "${args[--standalone]}" = "1" ] && [ "${args[--parallel]}" = "1" ]; then + echo "Error: --standalone is not compatible with --parallel" >&2 + echo "Standalone mode only runs serial tests" >&2 + exit 1 + fi + + # Load helper functions + source "$root/src/lib/setup_test_symlinks.sh" + source "$root/src/lib/create_dummy_libs.sh" + source "$root/src/lib/compile_catch2.sh" + source "$root/src/lib/compile_test_drivers.sh" + source "$root/src/lib/run_serial_tests.sh" + source "$root/src/lib/run_parallel_tests.sh" + source "$root/src/lib/cleanup.sh" + + # Parse flags from bashly (bashly uses "1" for true flags) + doSerial=true # Default: serial only + doParallel=false + doReport=false + standalone_mode=false + + # If --parallel flag is set, run parallel only (disable serial) + if [ "${args[--parallel]}" = "1" ]; then + doSerial=false + doParallel=true + fi + + if [ "${args[--report]}" = "1" ]; then + doReport=true + fi + + if [ "${args[--standalone]}" = "1" ]; then + standalone_mode=true + fi + + set -e + + # Get OpenFOAM version string + foamV=$(echo "${WM_PROJECT}$(test ! -z "${WM_FORK}" && echo '-'"${WM_FORK}")-${WM_PROJECT_VERSION}") + + # Collect catch2 arguments from catch_all + args_array=() + if [ -n "${other_args[*]}" ]; then + args_array=("${other_args[@]}") + fi + + # Setup test symlinks if FOAM_FOAMUT_TESTS is set + setup_test_symlinks + + # Create dummy libraries if needed + create_dummy_libs + + # libraries to test + libs=$(find -L tests/ -maxdepth 1 -mindepth 1 -type d) + libs_array=($libs) + + # where to run OpenFOAM cases + caseRun=/tmp/foamUtCases + mkdir -p "$caseRun" + + # a timeout to prevent hanging processes (be CI friendly) + timeOut="${CATCH_TIMEOUT:-60}" + + # Compile Catch2 + compile_catch2 + + # Compile test drivers + compile_test_drivers + + # Go back to the root of the repository + cd "$root" + + # Get setup to run tests + mapfile -t cases_array < <(find -L cases/ -maxdepth 1 -mindepth 1 -type d) + + # Build list of case names for tag filtering + case_names=() + for case_dir in "${cases_array[@]}"; do + case_names+=("$(basename "$case_dir")") + done + + if [ "$standalone_mode" = "true" ]; then + echo "Running in standalone mode (no OpenFOAM cases)..." >&2 + echo "Will exclude tests tagged with: ${case_names[*]}" >&2 + # Create a dummy case array with one entry for the loop structure + cases_array=("standalone") + else + if [ ${#cases_array[@]} -eq 0 ]; then + echo "No cases found to run tests" + exit 1 + fi + fi + + mkdir -p "$root"/reports + + # Run the tests, but do not exit until attempting everything + set +e + err=0 + + for ((k = 0; k < ${#cases_array[@]}; k++)); do + if [ "$standalone_mode" = "true" ]; then + caseName="standalone" + casePath="" + echo "Running standalone tests (no case)..." >&2 + else + ofCase="${cases_array[k]}" + caseName=$(basename "$ofCase") + casePath=$caseRun/$caseName + cp -rL "$ofCase" "$casePath" + fi + + case $doSerial in + (true) run_serial_tests "$err" "$caseName" "$casePath" "$libs" "${args_array[@]}";; + esac + + case $doParallel in + (true) run_parallel_tests "$err" "$caseName" "$casePath" "$libs" "${args_array[@]}";; + esac + + # separator in case json reporter is used + for element in "${args_array[@]}"; do + if [ "$element" == "json" ]; then + if ((k != ${#cases_array[@]} - 1)); then + printf "," + fi + fi + done + + # Cleanup case directory if not in standalone mode + if [ "$standalone_mode" != "true" ]; then + rm -rf "$casePath" + fi + done + + # Cleanup + cleanup + + exit $err + +} + +# :command.version_command +version_command() { + echo "$version" +} + +# :command.usage +foamut_usage() { + printf "foamut - Unit/integration testing framework for OpenFOAM\n\n" + + printf "%s\n" "Usage:" + printf " foamut [OPTIONS] [--] [CATCH2_ARGS...]\n" + printf " foamut --help | -h\n" + printf " foamut --version | -v\n" + echo + + # :command.long_usage + if [[ -n "$long_usage" ]]; then + printf "%s\n" "Options:" + + # :command.usage_flags + # :flag.usage + printf " %s\n" "--parallel" + printf " Run parallel tests only (default is serial only, incompatible with\n --standalone)\n" + echo + + # :flag.usage + printf " %s\n" "--report" + printf " Generate JSON test reports in reports/ directory\n" + echo + + # :flag.usage + printf " %s\n" "--test-driver SOURCE_PATH" + printf " Path to custom testDriver.C source file (overrides default)\n" + echo + + # :flag.usage + printf " %s\n" "--standalone" + printf " Run tests without OpenFOAM cases (tests not tagged by case names, serial or\n mode-agnostic)\n" + echo + + # :flag.usage + printf " %s\n" "--test-prefix COMMAND" + printf " Prefix command for test execution (automatically disables timeout)\n Serial: testDriver ...\n Parallel: mpirun -np N testDriver ...\n Examples: \"gdb --args\", \"valgrind\", \"hpctoolkit\"\n" + echo + + # :flag.usage + printf " %s\n" "--force-timeout" + printf " Keep timeout wrapper even when using --test-prefix\n" + echo + + # :command.usage_fixed_flags + printf " %s\n" "--help, -h" + printf " Show this help\n" + echo + printf " %s\n" "--version, -v" + printf " Show version number\n" + echo + + # :command.usage_args + printf "%s\n" "Arguments:" + + echo " CATCH2_ARGS..." + printf " Arguments passed to Catch2 test framework.\n \n Common Catch2 Options:\n --list-tests List all tests\n --list-tags List all tags\n -h, --help Show Catch2 help\n -s, --success Show successful tests\n -b, --break Break into debugger on failure\n -d, --durations Show test durations\n -#, --filenames-as-tags Add filename as tag\n -r, --reporter Use specific reporter (console, xml,\n junit, etc.)\n --order Test execution order\n \n Tag Filters:\n \"[tag1]\" Run tests with tag1\n \"[tag1][tag2]\" Run tests with both tags\n \"[tag1],[tag2]\" Run tests with either tag\n \"~[tag1]\" Exclude tests with tag1\n \n Note: testDriver uses --- to separate Catch2 from OpenFOAM args internally\n" + echo + + # :command.usage_environment_variables + printf "%s\n" "Environment Variables:" + + # :environment_variable.usage + printf " %s\n" "FOAM_LIBBIN" + printf " OpenFOAM library directory (required, set by sourcing OpenFOAM)\n" + echo + + # :environment_variable.usage + printf " %s\n" "FOAM_FOAMUT_TESTS" + printf " Path to external tests directory (will be symlinked under tests/)\n" + echo + + # :environment_variable.usage + printf " %s\n" "CATCH_TIMEOUT" + printf " Test timeout in seconds (default 60)\n" + echo + + # :environment_variable.usage + printf " %s\n" "FOAM_FOAMUT" + printf " Path to foamUT repository root (set automatically)\n" + echo + + # :command.usage_examples + printf "%s\n" "Examples:" + printf " foamut --help\n" + printf " foamut\n" + printf " foamut --parallel\n" + printf " foamut --parallel --report\n" + printf " foamut --standalone\n" + printf " foamut --list-tests\n" + printf " foamut \"[serial]\"\n" + printf " foamut -s\n" + printf " foamut --test-prefix \"gdb --args\"\n" + printf " foamut --test-driver /path/to/custom/testDriver.C\n" + echo + + fi +} + +# :command.normalize_input +# :command.normalize_input_function +normalize_input() { + local arg passthru flags + passthru=false + + while [[ $# -gt 0 ]]; do + arg="$1" + if [[ $passthru == true ]]; then + input+=("$arg") + elif [[ $arg =~ ^(--[a-zA-Z0-9_\-]+)=(.+)$ ]]; then + input+=("${BASH_REMATCH[1]}") + input+=("${BASH_REMATCH[2]}") + elif [[ $arg =~ ^(-[a-zA-Z0-9])=(.+)$ ]]; then + input+=("${BASH_REMATCH[1]}") + input+=("${BASH_REMATCH[2]}") + elif [[ $arg =~ ^-([a-zA-Z0-9][a-zA-Z0-9]+)$ ]]; then + flags="${BASH_REMATCH[1]}" + for ((i = 0; i < ${#flags}; i++)); do + input+=("-${flags:i:1}") + done + elif [[ "$arg" == "--" ]]; then + passthru=true + input+=("$arg") + else + input+=("$arg") + fi + + shift + done +} + +# :command.inspect_args +inspect_args() { + if ((${#args[@]})); then + readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort) + echo args: + for k in "${sorted_keys[@]}"; do + echo "- \${args[$k]} = ${args[$k]}" + done + else + echo args: none + fi + + if ((${#other_args[@]})); then + echo + echo other_args: + echo "- \${other_args[*]} = ${other_args[*]}" + for i in "${!other_args[@]}"; do + echo "- \${other_args[$i]} = ${other_args[$i]}" + done + fi + + if ((${#deps[@]})); then + readarray -t sorted_keys < <(printf '%s\n' "${!deps[@]}" | sort) + echo + echo deps: + for k in "${sorted_keys[@]}"; do + echo "- \${deps[$k]} = ${deps[$k]}" + done + fi + + if ((${#env_var_names[@]})); then + readarray -t sorted_names < <(printf '%s\n' "${env_var_names[@]}" | sort) + echo + echo "environment variables:" + for k in "${sorted_names[@]}"; do + echo "- \$$k = ${!k:-}" + done + fi +} + +# :command.user_lib +# src/lib/cleanup.sh +#!/usr/bin/bash + +# Cleanup dummy libraries and temporary directories + +cleanup() { + local dummyLibChecks="Pstream dynamicFvMesh" + + # Cleanup dummy libraries + for dummy in $dummyLibChecks; do + if [ -f "${FOAM_USER_LIBBIN}/lib${dummy}.so" ] && + tr '\n' ' ' < "${FOAM_USER_LIBBIN}/lib${dummy}.so" | grep -q '^! $'; then + rm -rf "${FOAM_USER_LIBBIN}/lib${dummy}.so" + fi + done + + # Cleanup temporary case directory + rm -rf "$caseRun" +} + +# src/lib/compile_catch2.sh +#!/usr/bin/bash + +# Compile Catch2 v3 if not already compiled +# Installs to FOAM_USER_LIBBIN/catch2 + +compile_catch2() { + echo "Compiling Catch2 v3..." >&2 + if [ ! -f "$FOAM_USER_LIBBIN/catch2/lib/libCatch2.a" ]; then + cd catch2 || exit 1 + mkdir -p build + cd build || exit 1 + + # Use pipefail to catch failures in piped commands + set -o pipefail + + if ! cmake -DCMAKE_INSTALL_PREFIX="$FOAM_USER_LIBBIN"/catch2 .. 2>&1 | tee log.cmake; then + set +o pipefail + echo "" >&2 + echo "Error: CMake configuration failed for Catch2" >&2 + echo "Full log saved to: $PWD/log.cmake" >&2 + exit 1 + fi + + if ! make -j"$(nproc)" 2>&1 | tee log.makeBuild; then + set +o pipefail + echo "" >&2 + echo "Error: Failed to build Catch2" >&2 + echo "Full log saved to: $PWD/log.makeBuild" >&2 + exit 1 + fi + + if ! make install 2>&1 | tee log.makeInstall; then + set +o pipefail + echo "" >&2 + echo "Error: Failed to install Catch2" >&2 + echo "Full log saved to: $PWD/log.makeInstall" >&2 + exit 1 + fi + + set +o pipefail + cd - > /dev/null || exit 1 + rm -rf build + cd .. || exit 1 + fi +} + +# src/lib/compile_test_drivers.sh +#!/usr/bin/bash + +# Compile test drivers for all test libraries +# Supports custom test driver via --test-driver flag + +compile_test_drivers() { + local custom_driver="${args[--test-driver]}" + + # Compile tests + for lib in $libs; do + cd "$lib" || exit 1 + + # If custom driver is specified, copy it to this test directory + if [ -n "$custom_driver" ]; then + cp "$custom_driver" "$root/tests/testDriver.C" + echo "Using custom test driver: $custom_driver" >&2 + fi + + echo "Compiling $lib test driver..." >&2 + wmakeLnInclude . # Just in case the tested libs are header only + + # Use set -o pipefail to catch wmake failures even when piped to tee + set -o pipefail + if ! wmake 2>&1 | tee log.wmake; then + set +o pipefail + echo "" >&2 + echo "Error: Failed to compile $lib test driver" >&2 + echo "Full log saved to: $PWD/log.wmake" >&2 + exit 1 + fi + set +o pipefail + echo "Test driver for $lib has been compiled." >&2 + cd - > /dev/null || exit 1 + done +} + +# src/lib/create_dummy_libs.sh +#!/usr/bin/bash + +# Create dummy libraries if they don't exist +# Some OpenFOAM forks/configurations may not have certain libraries + +create_dummy_libs() { + # If there is no lib${libName}.so, create a dummy one + local dummyLibChecks="Pstream dynamicFvMesh" + for dummy in $dummyLibChecks; do + if [ ! -f "${FOAM_LIBBIN}/lib${dummy}.so" ] && + [ ! -f "${FOAM_USER_LIBBIN}/lib${dummy}.so" ] && + [ ! -f "${FOAM_LIBBIN}/${FOAM_MPI}/lib${dummy}.so" ]; then + echo '!' > "${FOAM_USER_LIBBIN}/lib${dummy}.so" + fi + done +} + +# src/lib/run_parallel_tests.sh +#!/usr/bin/bash + +# Run parallel tests for all libraries on a specific case +# Arguments: $1=error_count, $2=case_name, $3=case_path, $4=libs, $@=additional args + +run_parallel_tests() { + if [ "$standalone_mode" = "true" ]; then + echo "Skipping decomposePar for standalone mode..." >&2 + else + if ! test -f "${3}/system/decomposeParDict" ; then + rm -rf "${3}/processor*" + echo "decomposeParDict not found, not running parallel tests on this case..." >&2 + return 0 + fi + fi + + local fargs=("$@") + local params=() + local skip_next=false + + # Filter out foamUT-specific flags from params + for ((i = 4; i <= $#; i++)); do + arg="${fargs[i]}" + + if [ "$skip_next" = true ]; then + skip_next=false + continue + fi + + case "$arg" in + --parallel|--report|--standalone|--force-timeout) + # These flags don't take arguments + ;; + --test-driver|--test-prefix) + # These flags take an argument, skip the next one too + skip_next=true + ;; + *) + params+=("$arg") + ;; + esac + done + + local test_prefix="${args[--test-prefix]}" + local force_timeout="${args[--force-timeout]}" + + # Decompose case if not in standalone mode + if [ "$standalone_mode" != "true" ]; then + local nProcs=$(grep -oP "numberOfSubdomains\s+\K\d+" "${3}"/system/decomposeParDict) + decomposePar -force -case "${3}" > "${3}/log.decomposePar" + err=$((err + $?)) + else + # In standalone mode, default to 2 processors or read from FOAM_FOAMUT_NPROCS + local nProcs="${FOAM_FOAMUT_NPROCS:-2}" + fi + + # run the case in parallel mode + report="" + case $doReport in + (true) report="-s -r json -d yes";; + esac + + for ((i = 0; i < ${#libs_array[@]}; i++)); do + lib="${libs_array[i]}" + printf "\n\nRunning tests for lib %s, on %s case in parallel...\n" "$lib" "${2}" >&2 + libName=$(basename "$lib") + logdir="reports/${libName}_${2}_parallel" + logparams="" + direct="" + case $doReport in + (true) logparams="-output-filename $logdir" + direct="> /dev/null" + echo "Parallel Reports (${nProcs}): ${logdir}" >&2 + esac + + # Execute the test + if [ "$standalone_mode" = "true" ]; then + # Standalone mode: no case argument, exclude all case-tagged tests + # Build exclusion filter: [parallel]~[case1]~[case2]... + local tag_filter="[parallel]" + for case_name in "${case_names[@]}"; do + tag_filter="${tag_filter}~[${case_name}]" + done + + # Build and execute command with or without timeout and prefix + # Prefix comes AFTER mpirun in parallel mode + if [ -z "$test_prefix" ]; then + timeout "$timeOut" mpirun $logparams -np "$nProcs" "$root"/"$lib"/testDriver \ + --allow-running-no-tests \ + -n "$(basename "$lib")" $report \ + --rng-seed time "$tag_filter" ${params[@]} --- -parallel $direct + else + if [ "$force_timeout" = "1" ]; then + timeout "$timeOut" mpirun $logparams -np "$nProcs" $test_prefix "$root"/"$lib"/testDriver \ + --allow-running-no-tests \ + -n "$(basename "$lib")" $report \ + --rng-seed time "$tag_filter" ${params[@]} --- -parallel $direct + else + mpirun $logparams -np "$nProcs" $test_prefix "$root"/"$lib"/testDriver \ + --allow-running-no-tests \ + -n "$(basename "$lib")" $report \ + --rng-seed time "$tag_filter" ${params[@]} --- -parallel $direct + fi + fi + else + # Normal mode: with case argument and -parallel flag + if [ -z "$test_prefix" ]; then + timeout "$timeOut" mpirun $logparams -np "$nProcs" "$root"/"$lib"/testDriver \ + --allow-running-no-tests \ + -n "$(basename "$lib")" $report \ + --rng-seed time "[parallel][${2}]" ${params[@]} --- -parallel -case "${3}" $direct + else + if [ "$force_timeout" = "1" ]; then + timeout "$timeOut" mpirun $logparams -np "$nProcs" $test_prefix "$root"/"$lib"/testDriver \ + --allow-running-no-tests \ + -n "$(basename "$lib")" $report \ + --rng-seed time "[parallel][${2}]" ${params[@]} --- -parallel -case "${3}" $direct + else + mpirun $logparams -np "$nProcs" $test_prefix "$root"/"$lib"/testDriver \ + --allow-running-no-tests \ + -n "$(basename "$lib")" $report \ + --rng-seed time "[parallel][${2}]" ${params[@]} --- -parallel -case "${3}" $direct + fi + fi + fi + + set +x + # separator in case json reporter is used + for element in "${params[@]}"; do + if [ "$element" == "json" ]; then + if ((i != ${#libs_array[@]} - 1)); then + printf "," + fi + fi + done + err=$((err + lerr)) + done +} + +# src/lib/run_serial_tests.sh +#!/usr/bin/bash + +# Run serial tests for all libraries on a specific case +# Arguments: $1=error_count, $2=case_name, $3=case_path, $4=libs, $@=additional args + +run_serial_tests() { + local fargs=("$@") + local params=() + local skip_next=false + + # Filter out foamUT-specific flags from params + for ((i = 4; i <= $#; i++)); do + arg="${fargs[i]}" + + if [ "$skip_next" = true ]; then + skip_next=false + continue + fi + + case "$arg" in + --parallel|--report|--standalone|--force-timeout) + # These flags don't take arguments + ;; + --test-driver|--test-prefix) + # These flags take an argument, skip the next one too + skip_next=true + ;; + *) + params+=("$arg") + ;; + esac + done + + local test_prefix="${args[--test-prefix]}" + local force_timeout="${args[--force-timeout]}" + + for ((i = 0; i < ${#libs_array[@]}; i++)); do + lib="${libs_array[i]}" + printf "\n\nRunning tests for lib %s, on %s case in serial...\n" "$lib" "${2}" >&2 + libName=$(basename "$lib") + report="" + case $doReport in + (true) report="-s -r json::out=${root}/reports/${libName}_${2}_serial.json -d yes" + echo "Report: ${root}/reports/${libName}_${2}_serial.json" >&2 + ;; + esac + + # Execute the test + if [ "$standalone_mode" = "true" ]; then + # Standalone mode: no case argument, exclude all case-tagged tests + # Run tests that are: + # - ([serial] AND not-case-tagged) OR (not-[parallel] AND not-case-tagged) + # This includes: [serial] tests, and tests with neither [serial] nor [parallel] + local tag_filter="[serial]" + for case_name in "${case_names[@]}"; do + tag_filter="${tag_filter}~[${case_name}]" + done + tag_filter="${tag_filter},~[parallel]" + for case_name in "${case_names[@]}"; do + tag_filter="${tag_filter}~[${case_name}]" + done + + # Build and execute command with or without timeout and prefix + if [ -z "$test_prefix" ]; then + timeout "$timeOut" "$root"/"$lib"/testDriver --allow-running-no-tests \ + -n "$(basename "$lib")" $report "$tag_filter" "${params[@]}" + else + if [ "$force_timeout" = "1" ]; then + timeout "$timeOut" $test_prefix "$root"/"$lib"/testDriver --allow-running-no-tests \ + -n "$(basename "$lib")" $report "$tag_filter" "${params[@]}" + else + $test_prefix "$root"/"$lib"/testDriver --allow-running-no-tests \ + -n "$(basename "$lib")" $report "$tag_filter" "${params[@]}" + fi + fi + else + # Normal mode: with case argument + if [ -z "$test_prefix" ]; then + timeout "$timeOut" "$root"/"$lib"/testDriver --allow-running-no-tests \ + -n "$(basename "$lib")" $report "[serial][${2}]" "${params[@]}" \ + --- -case "${3}" + else + if [ "$force_timeout" = "1" ]; then + timeout "$timeOut" $test_prefix "$root"/"$lib"/testDriver --allow-running-no-tests \ + -n "$(basename "$lib")" $report "[serial][${2}]" "${params[@]}" \ + --- -case "${3}" + else + $test_prefix "$root"/"$lib"/testDriver --allow-running-no-tests \ + -n "$(basename "$lib")" $report "[serial][${2}]" "${params[@]}" \ + --- -case "${3}" + fi + fi + fi + + locErr=$? + err=$((err+locErr)) + + # separator in case json reporter is used + for element in "${params[@]}"; do + if [ "$element" == "json" ]; then + if ((i != ${#libs_array[@]})); then + printf "," + fi + fi + done + done +} + +# src/lib/setup_test_symlinks.sh +#!/usr/bin/bash + +# Setup test symlinks if FOAM_FOAMUT_TESTS environment variable is set +# Discovers Make directories and symlinks parent directories under tests/ + +setup_test_symlinks() { + # If tests folder is supplied through an env. var. do the symlinking + if [ -n "${FOAM_FOAMUT_TESTS}" ]; then + find "${FOAM_FOAMUT_TESTS}" -type d -name "Make" | while read -r make_dir; do + parent_dir=$(basename "$(dirname "$make_dir")") + target_dir="$root/tests/$parent_dir" + ln -f -s "$(dirname "$make_dir")" "$target_dir" + echo "picked up $parent_dir tests" + done + fi +} + +# :command.command_functions + +# :command.parse_requirements +parse_requirements() { + # :command.fixed_flags_filter + while [[ $# -gt 0 ]]; do + key="$1" + case "$key" in + --version | -v) + version_command + exit + ;; + + --help | -h) + long_usage=yes + foamut_usage + exit + ;; + + *) + break + ;; + + esac + done + + # :command.environment_variables_filter + + env_var_names+=("FOAM_LIBBIN") + env_var_names+=("FOAM_FOAMUT_TESTS") + env_var_names+=("CATCH_TIMEOUT") + env_var_names+=("FOAM_FOAMUT") + + # :command.command_filter + action="root" + + # :command.parse_requirements_while + while [[ $# -gt 0 ]]; do + key="$1" + case "$key" in + # :flag.case + --parallel) + + # :flag.case_no_arg + args['--parallel']=1 + shift + ;; + + # :flag.case + --report) + + # :flag.case_no_arg + args['--report']=1 + shift + ;; + + # :flag.case + --test-driver) + + # :flag.case_arg + if [[ -n ${2+x} ]]; then + args['--test-driver']="$2" + shift + shift + else + printf "%s\n" "--test-driver requires an argument: --test-driver SOURCE_PATH" >&2 + exit 1 + fi + ;; + + # :flag.case + --standalone) + + # :flag.case_no_arg + args['--standalone']=1 + shift + ;; + + # :flag.case + --test-prefix) + + # :flag.case_arg + if [[ -n ${2+x} ]]; then + args['--test-prefix']="$2" + shift + shift + else + printf "%s\n" "--test-prefix requires an argument: --test-prefix COMMAND" >&2 + exit 1 + fi + ;; + + # :flag.case + --force-timeout) + + # :flag.case_no_arg + args['--force-timeout']=1 + shift + ;; + + --) + shift + other_args+=("$@") + break + ;; + + -?*) + other_args+=("$1") + shift + ;; + + *) + # :command.parse_requirements_case + # :command.parse_requirements_case_catch_all + other_args+=("$1") + shift + + ;; + + esac + done + +} + +# :command.initialize +initialize() { + declare -g version="2.0.0" + set -e + + # src/initialize.sh + #!/usr/bin/bash + + # Bashly initialization hook - runs before command execution + # Validates environment and performs sanity checks + + # Check if OpenFOAM is sourced + if [ -z "${FOAM_LIBBIN}" ]; then + echo "Error: Please source an OpenFOAM version. Aborting..." >&2 + echo "USAGE: ./foamut [OPTIONS] [CATCH2_ARGS...]" >&2 + exit 1 + fi + + # Set root directory as the repository root + root="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + export FOAM_FOAMUT="$root" + +} + +# :command.run +run() { + # :command.globals + declare -g long_usage='' + declare -g -A args=() + declare -g -a other_args=() + declare -g -A deps=() + declare -g -a env_var_names=() + declare -g -a input=() + + normalize_input "$@" + parse_requirements "${input[@]}" + + case "$action" in + "root") root_command ;; + esac +} + +if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then + initialize + run "$@" +fi diff --git a/generate.sh b/generate.sh new file mode 100755 index 0000000..0b8facd --- /dev/null +++ b/generate.sh @@ -0,0 +1,13 @@ +#!/usr/bin/bash + +# Script to generate foamut executable and create backward compatibility symlink + +set -e + +echo "Generating foamut executable with bashly..." +bashly generate + +echo "Creating Alltest symlink for backward compatibility..." +ln -sf foamut Alltest + +echo "Done! Run ./foamut --help or ./Alltest --help to test" diff --git a/src/bashly.yml b/src/bashly.yml new file mode 100644 index 0000000..b70d326 --- /dev/null +++ b/src/bashly.yml @@ -0,0 +1,77 @@ +name: foamut +help: Unit/integration testing framework for OpenFOAM +version: 2.0.0 + +flags: + - long: --parallel + help: Run parallel tests only (default is serial only, incompatible with --standalone) + + - long: --report + help: Generate JSON test reports in reports/ directory + + - long: --test-driver + arg: source_path + help: Path to custom testDriver.C source file (overrides default) + + - long: --standalone + help: Run tests without OpenFOAM cases (tests not tagged by case names, serial or mode-agnostic) + + - long: --test-prefix + arg: command + help: | + Prefix command for test execution (automatically disables timeout) + Serial: testDriver ... + Parallel: mpirun -np N testDriver ... + Examples: "gdb --args", "valgrind", "hpctoolkit" + + - long: --force-timeout + help: Keep timeout wrapper even when using --test-prefix + +environment_variables: + - name: FOAM_LIBBIN + help: OpenFOAM library directory (required, set by sourcing OpenFOAM) + + - name: FOAM_FOAMUT_TESTS + help: Path to external tests directory (will be symlinked under tests/) + + - name: CATCH_TIMEOUT + help: Test timeout in seconds (default 60) + + - name: FOAM_FOAMUT + help: Path to foamUT repository root (set automatically) + +catch_all: + label: catch2_args + help: |- + Arguments passed to Catch2 test framework. + + Common Catch2 Options: + --list-tests List all tests + --list-tags List all tags + -h, --help Show Catch2 help + -s, --success Show successful tests + -b, --break Break into debugger on failure + -d, --durations Show test durations + -#, --filenames-as-tags Add filename as tag + -r, --reporter Use specific reporter (console, xml, junit, etc.) + --order Test execution order + + Tag Filters: + "[tag1]" Run tests with tag1 + "[tag1][tag2]" Run tests with both tags + "[tag1],[tag2]" Run tests with either tag + "~[tag1]" Exclude tests with tag1 + + Note: testDriver uses --- to separate Catch2 from OpenFOAM args internally + +examples: + - foamut --help # Show this help (foamUT options + Catch2 reference) + - foamut # Run serial tests only (default) + - foamut --parallel # Run parallel tests only + - foamut --parallel --report # Run parallel tests with JSON reports + - foamut --standalone # Run tests NOT tagged with case names + - foamut --list-tests # List all available tests (Catch2) + - foamut "[serial]" # Run specific test tags (Catch2) + - foamut -s # Show successful tests (Catch2) + - foamut --test-prefix "gdb --args" # Debug serial tests + - foamut --test-driver /path/to/custom/testDriver.C # Use custom test driver diff --git a/src/initialize.sh b/src/initialize.sh new file mode 100644 index 0000000..534066a --- /dev/null +++ b/src/initialize.sh @@ -0,0 +1,15 @@ +#!/usr/bin/bash + +# Bashly initialization hook - runs before command execution +# Validates environment and performs sanity checks + +# Check if OpenFOAM is sourced +if [ -z "${FOAM_LIBBIN}" ]; then + echo "Error: Please source an OpenFOAM version. Aborting..." >&2 + echo "USAGE: ./foamut [OPTIONS] [CATCH2_ARGS...]" >&2 + exit 1 +fi + +# Set root directory as the repository root +root="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +export FOAM_FOAMUT="$root" diff --git a/src/lib/cleanup.sh b/src/lib/cleanup.sh new file mode 100644 index 0000000..9b9f7b3 --- /dev/null +++ b/src/lib/cleanup.sh @@ -0,0 +1,18 @@ +#!/usr/bin/bash + +# Cleanup dummy libraries and temporary directories + +cleanup() { + local dummyLibChecks="Pstream dynamicFvMesh" + + # Cleanup dummy libraries + for dummy in $dummyLibChecks; do + if [ -f "${FOAM_USER_LIBBIN}/lib${dummy}.so" ] && + tr '\n' ' ' < "${FOAM_USER_LIBBIN}/lib${dummy}.so" | grep -q '^! $'; then + rm -rf "${FOAM_USER_LIBBIN}/lib${dummy}.so" + fi + done + + # Cleanup temporary case directory + rm -rf "$caseRun" +} diff --git a/src/lib/compile_catch2.sh b/src/lib/compile_catch2.sh new file mode 100644 index 0000000..a89190a --- /dev/null +++ b/src/lib/compile_catch2.sh @@ -0,0 +1,45 @@ +#!/usr/bin/bash + +# Compile Catch2 v3 if not already compiled +# Installs to FOAM_USER_LIBBIN/catch2 + +compile_catch2() { + echo "Compiling Catch2 v3..." >&2 + if [ ! -f "$FOAM_USER_LIBBIN/catch2/lib/libCatch2.a" ]; then + cd catch2 || exit 1 + mkdir -p build + cd build || exit 1 + + # Use pipefail to catch failures in piped commands + set -o pipefail + + if ! cmake -DCMAKE_INSTALL_PREFIX="$FOAM_USER_LIBBIN"/catch2 .. 2>&1 | tee log.cmake; then + set +o pipefail + echo "" >&2 + echo "Error: CMake configuration failed for Catch2" >&2 + echo "Full log saved to: $PWD/log.cmake" >&2 + exit 1 + fi + + if ! make -j"$(nproc)" 2>&1 | tee log.makeBuild; then + set +o pipefail + echo "" >&2 + echo "Error: Failed to build Catch2" >&2 + echo "Full log saved to: $PWD/log.makeBuild" >&2 + exit 1 + fi + + if ! make install 2>&1 | tee log.makeInstall; then + set +o pipefail + echo "" >&2 + echo "Error: Failed to install Catch2" >&2 + echo "Full log saved to: $PWD/log.makeInstall" >&2 + exit 1 + fi + + set +o pipefail + cd - > /dev/null || exit 1 + rm -rf build + cd .. || exit 1 + fi +} diff --git a/src/lib/compile_test_drivers.sh b/src/lib/compile_test_drivers.sh new file mode 100644 index 0000000..f75cab3 --- /dev/null +++ b/src/lib/compile_test_drivers.sh @@ -0,0 +1,35 @@ +#!/usr/bin/bash + +# Compile test drivers for all test libraries +# Supports custom test driver via --test-driver flag + +compile_test_drivers() { + local custom_driver="${args[--test-driver]}" + + # Compile tests + for lib in $libs; do + cd "$lib" || exit 1 + + # If custom driver is specified, copy it to this test directory + if [ -n "$custom_driver" ]; then + cp "$custom_driver" "$root/tests/testDriver.C" + echo "Using custom test driver: $custom_driver" >&2 + fi + + echo "Compiling $lib test driver..." >&2 + wmakeLnInclude . # Just in case the tested libs are header only + + # Use set -o pipefail to catch wmake failures even when piped to tee + set -o pipefail + if ! wmake 2>&1 | tee log.wmake; then + set +o pipefail + echo "" >&2 + echo "Error: Failed to compile $lib test driver" >&2 + echo "Full log saved to: $PWD/log.wmake" >&2 + exit 1 + fi + set +o pipefail + echo "Test driver for $lib has been compiled." >&2 + cd - > /dev/null || exit 1 + done +} diff --git a/src/lib/create_dummy_libs.sh b/src/lib/create_dummy_libs.sh new file mode 100644 index 0000000..b6547b1 --- /dev/null +++ b/src/lib/create_dummy_libs.sh @@ -0,0 +1,16 @@ +#!/usr/bin/bash + +# Create dummy libraries if they don't exist +# Some OpenFOAM forks/configurations may not have certain libraries + +create_dummy_libs() { + # If there is no lib${libName}.so, create a dummy one + local dummyLibChecks="Pstream dynamicFvMesh" + for dummy in $dummyLibChecks; do + if [ ! -f "${FOAM_LIBBIN}/lib${dummy}.so" ] && + [ ! -f "${FOAM_USER_LIBBIN}/lib${dummy}.so" ] && + [ ! -f "${FOAM_LIBBIN}/${FOAM_MPI}/lib${dummy}.so" ]; then + echo '!' > "${FOAM_USER_LIBBIN}/lib${dummy}.so" + fi + done +} diff --git a/src/lib/run_parallel_tests.sh b/src/lib/run_parallel_tests.sh new file mode 100644 index 0000000..1644597 --- /dev/null +++ b/src/lib/run_parallel_tests.sh @@ -0,0 +1,138 @@ +#!/usr/bin/bash + +# Run parallel tests for all libraries on a specific case +# Arguments: $1=error_count, $2=case_name, $3=case_path, $4=libs, $@=additional args + +run_parallel_tests() { + if [ "$standalone_mode" = "true" ]; then + echo "Skipping decomposePar for standalone mode..." >&2 + else + if ! test -f "${3}/system/decomposeParDict" ; then + rm -rf "${3}/processor*" + echo "decomposeParDict not found, not running parallel tests on this case..." >&2 + return 0 + fi + fi + + local fargs=("$@") + local params=() + local skip_next=false + + # Filter out foamUT-specific flags from params + for ((i = 4; i <= $#; i++)); do + arg="${fargs[i]}" + + if [ "$skip_next" = true ]; then + skip_next=false + continue + fi + + case "$arg" in + --parallel|--report|--standalone|--force-timeout) + # These flags don't take arguments + ;; + --test-driver|--test-prefix) + # These flags take an argument, skip the next one too + skip_next=true + ;; + *) + params+=("$arg") + ;; + esac + done + + local test_prefix="${args[--test-prefix]}" + local force_timeout="${args[--force-timeout]}" + + # Decompose case if not in standalone mode + if [ "$standalone_mode" != "true" ]; then + local nProcs=$(grep -oP "numberOfSubdomains\s+\K\d+" "${3}"/system/decomposeParDict) + decomposePar -force -case "${3}" > "${3}/log.decomposePar" + err=$((err + $?)) + else + # In standalone mode, default to 2 processors or read from FOAM_FOAMUT_NPROCS + local nProcs="${FOAM_FOAMUT_NPROCS:-2}" + fi + + # run the case in parallel mode + report="" + case $doReport in + (true) report="-s -r json -d yes";; + esac + + for ((i = 0; i < ${#libs_array[@]}; i++)); do + lib="${libs_array[i]}" + printf "\n\nRunning tests for lib %s, on %s case in parallel...\n" "$lib" "${2}" >&2 + libName=$(basename "$lib") + logdir="reports/${libName}_${2}_parallel" + logparams="" + direct="" + case $doReport in + (true) logparams="-output-filename $logdir" + direct="> /dev/null" + echo "Parallel Reports (${nProcs}): ${logdir}" >&2 + esac + + # Execute the test + if [ "$standalone_mode" = "true" ]; then + # Standalone mode: no case argument, exclude all case-tagged tests + # Build exclusion filter: [parallel]~[case1]~[case2]... + local tag_filter="[parallel]" + for case_name in "${case_names[@]}"; do + tag_filter="${tag_filter}~[${case_name}]" + done + + # Build and execute command with or without timeout and prefix + # Prefix comes AFTER mpirun in parallel mode + if [ -z "$test_prefix" ]; then + timeout "$timeOut" mpirun $logparams -np "$nProcs" "$root"/"$lib"/testDriver \ + --allow-running-no-tests \ + -n "$(basename "$lib")" $report \ + --rng-seed time "$tag_filter" ${params[@]} --- -parallel $direct + else + if [ "$force_timeout" = "1" ]; then + timeout "$timeOut" mpirun $logparams -np "$nProcs" $test_prefix "$root"/"$lib"/testDriver \ + --allow-running-no-tests \ + -n "$(basename "$lib")" $report \ + --rng-seed time "$tag_filter" ${params[@]} --- -parallel $direct + else + mpirun $logparams -np "$nProcs" $test_prefix "$root"/"$lib"/testDriver \ + --allow-running-no-tests \ + -n "$(basename "$lib")" $report \ + --rng-seed time "$tag_filter" ${params[@]} --- -parallel $direct + fi + fi + else + # Normal mode: with case argument and -parallel flag + if [ -z "$test_prefix" ]; then + timeout "$timeOut" mpirun $logparams -np "$nProcs" "$root"/"$lib"/testDriver \ + --allow-running-no-tests \ + -n "$(basename "$lib")" $report \ + --rng-seed time "[parallel][${2}]" ${params[@]} --- -parallel -case "${3}" $direct + else + if [ "$force_timeout" = "1" ]; then + timeout "$timeOut" mpirun $logparams -np "$nProcs" $test_prefix "$root"/"$lib"/testDriver \ + --allow-running-no-tests \ + -n "$(basename "$lib")" $report \ + --rng-seed time "[parallel][${2}]" ${params[@]} --- -parallel -case "${3}" $direct + else + mpirun $logparams -np "$nProcs" $test_prefix "$root"/"$lib"/testDriver \ + --allow-running-no-tests \ + -n "$(basename "$lib")" $report \ + --rng-seed time "[parallel][${2}]" ${params[@]} --- -parallel -case "${3}" $direct + fi + fi + fi + + set +x + # separator in case json reporter is used + for element in "${params[@]}"; do + if [ "$element" == "json" ]; then + if ((i != ${#libs_array[@]} - 1)); then + printf "," + fi + fi + done + err=$((err + lerr)) + done +} diff --git a/src/lib/run_serial_tests.sh b/src/lib/run_serial_tests.sh new file mode 100644 index 0000000..6c72102 --- /dev/null +++ b/src/lib/run_serial_tests.sh @@ -0,0 +1,107 @@ +#!/usr/bin/bash + +# Run serial tests for all libraries on a specific case +# Arguments: $1=error_count, $2=case_name, $3=case_path, $4=libs, $@=additional args + +run_serial_tests() { + local fargs=("$@") + local params=() + local skip_next=false + + # Filter out foamUT-specific flags from params + for ((i = 4; i <= $#; i++)); do + arg="${fargs[i]}" + + if [ "$skip_next" = true ]; then + skip_next=false + continue + fi + + case "$arg" in + --parallel|--report|--standalone|--force-timeout) + # These flags don't take arguments + ;; + --test-driver|--test-prefix) + # These flags take an argument, skip the next one too + skip_next=true + ;; + *) + params+=("$arg") + ;; + esac + done + + local test_prefix="${args[--test-prefix]}" + local force_timeout="${args[--force-timeout]}" + + for ((i = 0; i < ${#libs_array[@]}; i++)); do + lib="${libs_array[i]}" + printf "\n\nRunning tests for lib %s, on %s case in serial...\n" "$lib" "${2}" >&2 + libName=$(basename "$lib") + report="" + case $doReport in + (true) report="-s -r json::out=${root}/reports/${libName}_${2}_serial.json -d yes" + echo "Report: ${root}/reports/${libName}_${2}_serial.json" >&2 + ;; + esac + + # Execute the test + if [ "$standalone_mode" = "true" ]; then + # Standalone mode: no case argument, exclude all case-tagged tests + # Run tests that are: + # - ([serial] AND not-case-tagged) OR (not-[parallel] AND not-case-tagged) + # This includes: [serial] tests, and tests with neither [serial] nor [parallel] + local tag_filter="[serial]" + for case_name in "${case_names[@]}"; do + tag_filter="${tag_filter}~[${case_name}]" + done + tag_filter="${tag_filter},~[parallel]" + for case_name in "${case_names[@]}"; do + tag_filter="${tag_filter}~[${case_name}]" + done + + # Build and execute command with or without timeout and prefix + if [ -z "$test_prefix" ]; then + timeout "$timeOut" "$root"/"$lib"/testDriver --allow-running-no-tests \ + -n "$(basename "$lib")" $report "$tag_filter" "${params[@]}" + else + if [ "$force_timeout" = "1" ]; then + timeout "$timeOut" $test_prefix "$root"/"$lib"/testDriver --allow-running-no-tests \ + -n "$(basename "$lib")" $report "$tag_filter" "${params[@]}" + else + $test_prefix "$root"/"$lib"/testDriver --allow-running-no-tests \ + -n "$(basename "$lib")" $report "$tag_filter" "${params[@]}" + fi + fi + else + # Normal mode: with case argument + if [ -z "$test_prefix" ]; then + timeout "$timeOut" "$root"/"$lib"/testDriver --allow-running-no-tests \ + -n "$(basename "$lib")" $report "[serial][${2}]" "${params[@]}" \ + --- -case "${3}" + else + if [ "$force_timeout" = "1" ]; then + timeout "$timeOut" $test_prefix "$root"/"$lib"/testDriver --allow-running-no-tests \ + -n "$(basename "$lib")" $report "[serial][${2}]" "${params[@]}" \ + --- -case "${3}" + else + $test_prefix "$root"/"$lib"/testDriver --allow-running-no-tests \ + -n "$(basename "$lib")" $report "[serial][${2}]" "${params[@]}" \ + --- -case "${3}" + fi + fi + fi + + locErr=$? + err=$((err+locErr)) + + # separator in case json reporter is used + for element in "${params[@]}"; do + if [ "$element" == "json" ]; then + if ((i != ${#libs_array[@]})); then + printf "," + fi + fi + done + done +} diff --git a/src/lib/setup_test_symlinks.sh b/src/lib/setup_test_symlinks.sh new file mode 100644 index 0000000..3a2335d --- /dev/null +++ b/src/lib/setup_test_symlinks.sh @@ -0,0 +1,16 @@ +#!/usr/bin/bash + +# Setup test symlinks if FOAM_FOAMUT_TESTS environment variable is set +# Discovers Make directories and symlinks parent directories under tests/ + +setup_test_symlinks() { + # If tests folder is supplied through an env. var. do the symlinking + if [ -n "${FOAM_FOAMUT_TESTS}" ]; then + find "${FOAM_FOAMUT_TESTS}" -type d -name "Make" | while read -r make_dir; do + parent_dir=$(basename "$(dirname "$make_dir")") + target_dir="$root/tests/$parent_dir" + ln -f -s "$(dirname "$make_dir")" "$target_dir" + echo "picked up $parent_dir tests" + done + fi +} diff --git a/src/root_command.sh b/src/root_command.sh new file mode 100644 index 0000000..450f7cb --- /dev/null +++ b/src/root_command.sh @@ -0,0 +1,162 @@ +# Main command logic for foamUT +# Orchestrates the entire test execution pipeline + +# ShellChecked on every push - Always ShellCheck your scripts! + +# Validate custom test driver if provided +if [ -n "${args[--test-driver]}" ]; then + driver_path="${args[--test-driver]}" + if [ ! -f "$driver_path" ]; then + echo "Error: Test driver file not found: $driver_path" >&2 + exit 1 + fi + if [[ ! "$driver_path" =~ \.(C|cpp)$ ]]; then + echo "Error: Test driver must be a .C or .cpp source file" >&2 + exit 1 + fi +fi + +# Validate --force-timeout is only used with --test-prefix +if [ "${args[--force-timeout]}" = "1" ] && [ -z "${args[--test-prefix]}" ]; then + echo "Warning: --force-timeout has no effect without --test-prefix" >&2 +fi + +# Validate --standalone is not used with --parallel +if [ "${args[--standalone]}" = "1" ] && [ "${args[--parallel]}" = "1" ]; then + echo "Error: --standalone is not compatible with --parallel" >&2 + echo "Standalone mode only runs serial tests" >&2 + exit 1 +fi + +# Load helper functions +source "$root/src/lib/setup_test_symlinks.sh" +source "$root/src/lib/create_dummy_libs.sh" +source "$root/src/lib/compile_catch2.sh" +source "$root/src/lib/compile_test_drivers.sh" +source "$root/src/lib/run_serial_tests.sh" +source "$root/src/lib/run_parallel_tests.sh" +source "$root/src/lib/cleanup.sh" + +# Parse flags from bashly (bashly uses "1" for true flags) +doSerial=true # Default: serial only +doParallel=false +doReport=false +standalone_mode=false + +# If --parallel flag is set, run parallel only (disable serial) +if [ "${args[--parallel]}" = "1" ]; then + doSerial=false + doParallel=true +fi + +if [ "${args[--report]}" = "1" ]; then + doReport=true +fi + +if [ "${args[--standalone]}" = "1" ]; then + standalone_mode=true +fi + +set -e + +# Get OpenFOAM version string +foamV=$(echo "${WM_PROJECT}$(test ! -z "${WM_FORK}" && echo '-'"${WM_FORK}")-${WM_PROJECT_VERSION}") + +# Collect catch2 arguments from catch_all +args_array=() +if [ -n "${other_args[*]}" ]; then + args_array=("${other_args[@]}") +fi + +# Setup test symlinks if FOAM_FOAMUT_TESTS is set +setup_test_symlinks + +# Create dummy libraries if needed +create_dummy_libs + +# libraries to test +libs=$(find -L tests/ -maxdepth 1 -mindepth 1 -type d) +libs_array=($libs) + +# where to run OpenFOAM cases +caseRun=/tmp/foamUtCases +mkdir -p "$caseRun" + +# a timeout to prevent hanging processes (be CI friendly) +timeOut="${CATCH_TIMEOUT:-60}" + +# Compile Catch2 +compile_catch2 + +# Compile test drivers +compile_test_drivers + +# Go back to the root of the repository +cd "$root" + +# Get setup to run tests +mapfile -t cases_array < <(find -L cases/ -maxdepth 1 -mindepth 1 -type d) + +# Build list of case names for tag filtering +case_names=() +for case_dir in "${cases_array[@]}"; do + case_names+=("$(basename "$case_dir")") +done + +if [ "$standalone_mode" = "true" ]; then + echo "Running in standalone mode (no OpenFOAM cases)..." >&2 + echo "Will exclude tests tagged with: ${case_names[*]}" >&2 + # Create a dummy case array with one entry for the loop structure + cases_array=("standalone") +else + if [ ${#cases_array[@]} -eq 0 ]; then + echo "No cases found to run tests" + exit 1 + fi +fi + +mkdir -p "$root"/reports + +# Run the tests, but do not exit until attempting everything +set +e +err=0 + +for ((k = 0; k < ${#cases_array[@]}; k++)); do + if [ "$standalone_mode" = "true" ]; then + caseName="standalone" + casePath="" + echo "Running standalone tests (no case)..." >&2 + else + ofCase="${cases_array[k]}" + caseName=$(basename "$ofCase") + casePath=$caseRun/$caseName + cp -rL "$ofCase" "$casePath" + fi + + case $doSerial in + (true) run_serial_tests "$err" "$caseName" "$casePath" "$libs" "${args_array[@]}";; + esac + + case $doParallel in + (true) run_parallel_tests "$err" "$caseName" "$casePath" "$libs" "${args_array[@]}";; + esac + + # separator in case json reporter is used + for element in "${args_array[@]}"; do + if [ "$element" == "json" ]; then + if ((k != ${#cases_array[@]} - 1)); then + printf "," + fi + fi + done + + # Cleanup case directory if not in standalone mode + if [ "$standalone_mode" != "true" ]; then + rm -rf "$casePath" + fi +done + +# Cleanup +cleanup + +exit $err diff --git a/tests/exampleTests/Make/files b/tests/exampleTests/Make/files index cfd31bb..8917c6a 100644 --- a/tests/exampleTests/Make/files +++ b/tests/exampleTests/Make/files @@ -2,5 +2,6 @@ $(FOAM_FOAMUT)/tests/testDriver.C time.C fields.C +noCase.C EXE = testDriver diff --git a/tests/exampleTests/Make/options b/tests/exampleTests/Make/options index 2c51c9c..f96056d 100644 --- a/tests/exampleTests/Make/options +++ b/tests/exampleTests/Make/options @@ -1,4 +1,4 @@ -EXE_INC = -std=c++14 \ +EXE_INC = -std=c++17 \ -I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude \ -I$(LIB_SRC)/dynamicMesh/dynamicFvMesh/lnInclude \ diff --git a/tests/exampleTests/fields.C b/tests/exampleTests/fields.C index 0aed381..0daeeb9 100644 --- a/tests/exampleTests/fields.C +++ b/tests/exampleTests/fields.C @@ -11,7 +11,6 @@ extern Time* timePtr; extern argList* argsPtr; SCENARIO("Check field initialization methods", "[cavity][serial][parallel]") { - Foam::FatalError.dontThrowExceptions(); Time& runTime = *timePtr; argList& args = *argsPtr; #include "createMesh.H" @@ -29,7 +28,8 @@ SCENARIO("Check field initialization methods", "[cavity][serial][parallel]") { runTime.timeName(), mesh, IOobject::NO_READ, - IOobject::NO_WRITE + IOobject::NO_WRITE, + false ), mesh, zero diff --git a/tests/exampleTests/noCase.C b/tests/exampleTests/noCase.C new file mode 100644 index 0000000..0a81bfb --- /dev/null +++ b/tests/exampleTests/noCase.C @@ -0,0 +1,11 @@ +#include "catch2/catch_all.hpp" +#include "catch2/catch_test_macros.hpp" + + +TEST_CASE("No case tagged so no time object needed", "[serial]") { + REQUIRE(true); +} + +TEST_CASE("another no case tagged test") { + REQUIRE(true); +} diff --git a/tests/testDriver.C b/tests/testDriver.C index dd9fcf9..993f482 100644 --- a/tests/testDriver.C +++ b/tests/testDriver.C @@ -75,13 +75,29 @@ int main(int argc, char *argv[]) Warning().stdStream().setstate(std::ios_base::failbit); } - //argList::noBanner(); - #include "setRootCase.H" - #include "createTime.H" - argsPtr = &args; - timePtr = &runTime; + // Only create OpenFOAM Time object if case arguments are provided + // (standalone mode doesn't provide --- separator or foam arguments) + int ret = 0; + if (foamArgc > 1) + { + #include "setRootCase.H" + #include "createTime.H" + argsPtr = &args; + timePtr = &runTime; + + // Run tests with valid args and runTime pointers + ret = session.run(); + } + else + { + // Standalone mode: no OpenFOAM case + argsPtr = nullptr; + timePtr = nullptr; + + // Run tests without OpenFOAM objects + ret = session.run(); + } - auto ret = session.run(); if (ret != 0) abort(); return 0; }