Skip to content

Commit 7f1bd0f

Browse files
committed
cmake: Update Catch2
1 parent fea4c64 commit 7f1bd0f

File tree

397 files changed

+89216
-2980
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

397 files changed

+89216
-2980
lines changed

CMakeLists.txt

+7-5
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ SET(SELECTED_LANGUAGES ${MAIN_LANGUAGES} ${COMMUNITY_LANGUAGES})
6060

6161
get_dependency_directory(prusa3dboards PRUSA_BOARDS_DIR)
6262
project(Prusa-Firmware)
63+
add_subdirectory(lib)
6364

6465
FILE(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/Firmware/config.h MAX_SIZE_LINE REGEX "^#define \+LANG_SIZE_RESERVED \+")
6566
STRING(REGEX MATCH "0x[0-9]+" MAX_SIZE_HEX "${MAX_SIZE_LINE}")
@@ -477,10 +478,8 @@ if(NOT CMAKE_CROSSCOMPILING)
477478
# do not build the firmware by default (tests are the focus if not crosscompiling)
478479
project(cmake_test)
479480

480-
# Prepare "Catch" library for other executables
481-
set(CATCH_INCLUDE_DIR Catch2)
482-
add_library(Catch INTERFACE)
483-
target_include_directories(Catch INTERFACE ${CATCH_INCLUDE_DIR})
481+
# include catch_discover_tests function from Catch2
482+
include(${Catch2_SOURCE_DIR}/contrib/Catch.cmake)
484483

485484
# Make test executable
486485
set(TEST_SOURCES
@@ -492,6 +491,9 @@ if(NOT CMAKE_CROSSCOMPILING)
492491
)
493492
add_executable(tests ${TEST_SOURCES})
494493
target_include_directories(tests PRIVATE Tests)
495-
target_link_libraries(tests Catch)
494+
target_link_libraries(tests Catch2::Catch2)
495+
496+
enable_testing()
497+
catch_discover_tests(tests)
496498

497499
endif()

Tests/Example_test.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "catch.hpp"
1+
#include "catch2/catch.hpp"
22

33
unsigned int Factorial( unsigned int number ) {
44
return number <= 1 ? number : Factorial(number-1)*number;

Tests/PrusaStatistics_test.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
// For now the functions are just COPIED (lots of depencendies in ultralcd.h)
77

8-
#include "catch.hpp"
8+
#include "catch2/catch.hpp"
99
#include <iostream>
1010

1111
static bool VERBOSE_MODE = false; // If true - output additional info to std:cout

Tests/tests.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#define CATCH_CONFIG_MAIN
2-
#include "catch.hpp"
2+
#include "catch2/catch.hpp"

lib/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
if(NOT CMAKE_CROSSCOMPILING)
2+
add_subdirectory(Catch2)
3+
endif()

lib/Catch2/.clang-format

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
AccessModifierOffset: '-4'
3+
AlignEscapedNewlines: Left
4+
AllowAllConstructorInitializersOnNextLine: 'true'
5+
BinPackArguments: 'false'
6+
BinPackParameters: 'false'
7+
BreakConstructorInitializers: AfterColon
8+
ConstructorInitializerAllOnOneLineOrOnePerLine: 'true'
9+
DerivePointerAlignment: 'false'
10+
FixNamespaceComments: 'true'
11+
IncludeBlocks: Regroup
12+
IndentCaseLabels: 'false'
13+
IndentPPDirectives: AfterHash
14+
IndentWidth: '4'
15+
Language: Cpp
16+
NamespaceIndentation: All
17+
PointerAlignment: Left
18+
SpaceBeforeCtorInitializerColon: 'false'
19+
SpaceInEmptyParentheses: 'false'
20+
SpacesInParentheses: 'true'
21+
Standard: Cpp11
22+
TabWidth: '4'
23+
UseTab: Never
24+
25+
...

lib/Catch2/.conan/build.py

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
import os
5+
import re
6+
from cpt.packager import ConanMultiPackager
7+
from cpt.ci_manager import CIManager
8+
from cpt.printer import Printer
9+
10+
11+
class BuilderSettings(object):
12+
@property
13+
def username(self):
14+
""" Set catchorg as package's owner
15+
"""
16+
return os.getenv("CONAN_USERNAME", "catchorg")
17+
18+
@property
19+
def login_username(self):
20+
""" Set Bintray login username
21+
"""
22+
return os.getenv("CONAN_LOGIN_USERNAME", "horenmar")
23+
24+
@property
25+
def upload(self):
26+
""" Set Catch2 repository to be used on upload.
27+
The upload server address could be customized by env var
28+
CONAN_UPLOAD. If not defined, the method will check the branch name.
29+
Only master or CONAN_STABLE_BRANCH_PATTERN will be accepted.
30+
The master branch will be pushed to testing channel, because it does
31+
not match the stable pattern. Otherwise it will upload to stable
32+
channel.
33+
"""
34+
return os.getenv("CONAN_UPLOAD", "https://api.bintray.com/conan/catchorg/catch2")
35+
36+
@property
37+
def upload_only_when_stable(self):
38+
""" Force to upload when running over tag branch
39+
"""
40+
return os.getenv("CONAN_UPLOAD_ONLY_WHEN_STABLE", "True").lower() in ["true", "1", "yes"]
41+
42+
@property
43+
def stable_branch_pattern(self):
44+
""" Only upload the package the branch name is like a tag
45+
"""
46+
return os.getenv("CONAN_STABLE_BRANCH_PATTERN", r"v\d+\.\d+\.\d+")
47+
48+
@property
49+
def reference(self):
50+
""" Read project version from branch create Conan reference
51+
"""
52+
return os.getenv("CONAN_REFERENCE", "Catch2/{}".format(self._version))
53+
54+
@property
55+
def channel(self):
56+
""" Default Conan package channel when not stable
57+
"""
58+
return os.getenv("CONAN_CHANNEL", "testing")
59+
60+
@property
61+
def _version(self):
62+
""" Get version name from cmake file
63+
"""
64+
pattern = re.compile(r"project\(Catch2 LANGUAGES CXX VERSION (\d+\.\d+\.\d+)\)")
65+
version = "latest"
66+
with open("CMakeLists.txt") as file:
67+
for line in file:
68+
result = pattern.search(line)
69+
if result:
70+
version = result.group(1)
71+
return version
72+
73+
@property
74+
def _branch(self):
75+
""" Get branch name from CI manager
76+
"""
77+
printer = Printer(None)
78+
ci_manager = CIManager(printer)
79+
return ci_manager.get_branch()
80+
81+
82+
if __name__ == "__main__":
83+
settings = BuilderSettings()
84+
builder = ConanMultiPackager(
85+
reference=settings.reference,
86+
channel=settings.channel,
87+
upload=settings.upload,
88+
upload_only_when_stable=settings.upload_only_when_stable,
89+
stable_branch_pattern=settings.stable_branch_pattern,
90+
login_username=settings.login_username,
91+
username=settings.username,
92+
test_folder=os.path.join(".conan", "test_package"))
93+
builder.add()
94+
builder.run()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
cmake_minimum_required(VERSION 3.2.0)
2+
project(test_package CXX)
3+
4+
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
5+
conan_basic_setup(TARGETS)
6+
7+
find_package(Catch2 REQUIRED CONFIG)
8+
9+
add_executable(${PROJECT_NAME} test_package.cpp)
10+
target_link_libraries(${PROJECT_NAME} CONAN_PKG::Catch2)
11+
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 11)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
from conans import ConanFile, CMake
4+
import os
5+
6+
7+
class TestPackageConan(ConanFile):
8+
settings = "os", "compiler", "build_type", "arch"
9+
generators = "cmake"
10+
11+
def build(self):
12+
cmake = CMake(self)
13+
cmake.configure()
14+
cmake.build()
15+
16+
def test(self):
17+
assert os.path.isfile(os.path.join(self.deps_cpp_info["Catch2"].rootpath, "licenses", "LICENSE.txt"))
18+
bin_path = os.path.join("bin", "test_package")
19+
self.run("%s -s" % bin_path, run_environment=True)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#define CATCH_CONFIG_MAIN
2+
3+
#include <catch2/catch.hpp>
4+
5+
int Factorial( int number ) {
6+
return number <= 1 ? 1 : Factorial( number - 1 ) * number;
7+
}
8+
9+
TEST_CASE( "Factorial Tests", "[single-file]" ) {
10+
REQUIRE( Factorial(0) == 1 );
11+
REQUIRE( Factorial(1) == 1 );
12+
REQUIRE( Factorial(2) == 2 );
13+
REQUIRE( Factorial(3) == 6 );
14+
REQUIRE( Factorial(10) == 3628800 );
15+
}

lib/Catch2/.gitattributes

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# This sets the default behaviour, overriding core.autocrlf
2+
* text=auto
3+
4+
# All source files should have unix line-endings in the repository,
5+
# but convert to native line-endings on checkout
6+
*.cpp text
7+
*.h text
8+
*.hpp text
9+
10+
# Windows specific files should retain windows line-endings
11+
*.sln text eol=crlf
12+
13+
# Keep executable scripts with LFs so they can be run after being
14+
# checked out on Windows
15+
*.py text eol=lf
16+
17+
18+
# Keep the single include header with LFs to make sure it is uploaded,
19+
# hashed etc with LF
20+
single_include/**/*.hpp eol=lf
21+
# Also keep the LICENCE file with LFs for the same reason
22+
LICENCE.txt eol=lf

lib/Catch2/.github/FUNDING.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
custom: "https://www.paypal.me/horenmar"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
name: Bug report
3+
about: Create an issue that documents a bug
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Describe the bug**
11+
A clear and concise description of what the bug is.
12+
13+
**Expected behavior**
14+
A clear and concise description of what you expected to happen.
15+
16+
**Reproduction steps**
17+
Steps to reproduce the bug.
18+
<!-- Usually this means a small and self-contained piece of code that uses Catch and specifying compiler flags if relevant. -->
19+
20+
21+
**Platform information:**
22+
<!-- Fill in any extra information that might be important for your issue. -->
23+
- OS: **Windows NT**
24+
- Compiler+version: **GCC v2.9.5**
25+
- Catch version: **v1.2.3**
26+
27+
28+
**Additional context**
29+
Add any other context about the problem here.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
name: Feature request
3+
about: Create an issue that requests a feature or other improvement
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Description**
11+
Describe the feature/change you request and why do you want it.
12+
13+
**Additional context**
14+
Add any other context or screenshots about the feature request here.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!--
2+
Please do not submit pull requests changing the `version.hpp`
3+
or the single-include `catch.hpp` file, these are changed
4+
only when a new release is made.
5+
6+
Before submitting a PR you should probably read the contributor documentation
7+
at docs/contributing.md. It will tell you how to properly test your changes.
8+
-->
9+
10+
11+
## Description
12+
<!--
13+
Describe the what and the why of your pull request. Remember that these two
14+
are usually a bit different. As an example, if you have made various changes
15+
to decrease the number of new strings allocated, that's what. The why probably
16+
was that you have a large set of tests and found that this speeds them up.
17+
-->
18+
19+
## GitHub Issues
20+
<!--
21+
If this PR was motivated by some existing issues, reference them here.
22+
23+
If it is a simple bug-fix, please also add a line like 'Closes #123'
24+
to your commit message, so that it is automatically closed.
25+
If it is not, don't, as it might take several iterations for a feature
26+
to be done properly. If in doubt, leave it open and reference it in the
27+
PR itself, so that maintainers can decide.
28+
-->

lib/Catch2/.gitignore

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
*.build
2+
*.pbxuser
3+
*.mode1v3
4+
*.ncb
5+
*.suo
6+
Debug
7+
Release
8+
*.user
9+
*.xcuserstate
10+
.DS_Store
11+
xcuserdata
12+
CatchSelfTest.xcscheme
13+
Breakpoints.xcbkptlist
14+
projects/VS2010/TestCatch/_UpgradeReport_Files/
15+
projects/VS2010/TestCatch/TestCatch/TestCatch.vcxproj.filters
16+
projects/VisualStudio/TestCatch/UpgradeLog.XML
17+
projects/CMake/.idea
18+
projects/CMake/cmake-build-debug
19+
UpgradeLog.XML
20+
Resources/DWARF
21+
projects/Generated
22+
*.pyc
23+
DerivedData
24+
*.xccheckout
25+
Build
26+
.idea
27+
.vs
28+
cmake-build-*
29+
benchmark-dir
30+
.conan/test_package/build
31+
bazel-*

lib/Catch2/.gitrepo

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
; DO NOT EDIT (unless you know what you are doing)
2+
;
3+
; This subdirectory is a git "subrepo", and this file is maintained by the
4+
; git-subrepo command. See https://github.com/git-commands/git-subrepo#readme
5+
;
6+
[subrepo]
7+
remote = git@github.com:catchorg/Catch2.git
8+
branch = v2.x
9+
commit = 5c88067bd339465513af4aec606bd2292f1b594a
10+
parent = c58a5298d683f9b137f23a929eac699cd776f66c
11+
method = merge
12+
cmdver = 0.4.3

0 commit comments

Comments
 (0)