mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-02 02:51:42 +00:00
[sim] Translate unit tests to catch2 (#9004)
This commit is contained in:
@@ -78,7 +78,7 @@ cc_test(
|
||||
srcs = glob(["src/test/native/**/*.cpp"]),
|
||||
deps = [
|
||||
"//simulation/halsim_ds_socket",
|
||||
"//thirdparty/googletest",
|
||||
"//thirdparty/catch2",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@@ -11,18 +11,13 @@ ext {
|
||||
|
||||
apply plugin: 'google-test-test-suite'
|
||||
|
||||
ext {
|
||||
staticGtestConfigs = [:]
|
||||
}
|
||||
|
||||
staticGtestConfigs["${pluginName}Test"] = []
|
||||
apply from: "${rootDir}/shared/googletest.gradle"
|
||||
apply from: "${rootDir}/shared/catch2.gradle"
|
||||
|
||||
apply from: "${rootDir}/shared/plugins/setupBuild.gradle"
|
||||
|
||||
model {
|
||||
testSuites {
|
||||
"${pluginName}Test"(GoogleTestTestSuiteSpec) {
|
||||
"${pluginName}Catch2Test"(GoogleTestTestSuiteSpec) {
|
||||
for(NativeComponentSpec c : $.components) {
|
||||
if (c.name == pluginName) {
|
||||
testing c
|
||||
@@ -38,6 +33,9 @@ model {
|
||||
srcDirs 'src/test/native/include', 'src/main/native/cpp'
|
||||
}
|
||||
}
|
||||
binaries.all {
|
||||
lib project: ':thirdparty:catch2', library: 'catch2', linkage: 'static'
|
||||
}
|
||||
}
|
||||
}
|
||||
binaries {
|
||||
|
||||
@@ -2,13 +2,35 @@
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <string_view>
|
||||
|
||||
#include <catch2/catch_session.hpp>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "wpi/hal/HAL.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
HAL_Initialize(500, 0);
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
int ret = RUN_ALL_TESTS();
|
||||
return ret;
|
||||
namespace {
|
||||
|
||||
bool IsCatchListCommand(int argc, char** argv) {
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
std::string_view arg{argv[i]};
|
||||
if (arg == "--list-tests" || arg == "--list-tags" ||
|
||||
arg == "--list-reporters" || arg == "--list-listeners") {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("HALSimDSSocket RuntimeType", "[simulation][halsim_ds_socket]") {
|
||||
CHECK(HAL_RuntimeType::HAL_RUNTIME_SIMULATION == HAL_GetRuntimeType());
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
if (!IsCatchListCommand(argc, argv)) {
|
||||
HAL_Initialize(500, 0);
|
||||
}
|
||||
return Catch::Session().run(argc, argv);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user