mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[wpiutil] Refactor SpanMatcher and TestPrinters from ntcore (#5658)
This commit is contained in:
@@ -91,5 +91,5 @@ target_link_libraries(ntcoredev ntcore)
|
||||
if (WITH_TESTS)
|
||||
wpilib_add_test(ntcore src/test/native/cpp)
|
||||
target_include_directories(ntcore_test PRIVATE src/main/native/cpp)
|
||||
target_link_libraries(ntcore_test ntcore gmock_main)
|
||||
target_link_libraries(ntcore_test ntcore gmock_main wpiutil_testlib)
|
||||
endif()
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <wpi/SpanMatcher.h>
|
||||
|
||||
#include "LocalStorage.h"
|
||||
#include "MockListenerStorage.h"
|
||||
#include "MockLogger.h"
|
||||
#include "PubSubOptionsMatcher.h"
|
||||
#include "SpanMatcher.h"
|
||||
#include "TestPrinters.h"
|
||||
#include "ValueMatcher.h"
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
|
||||
#include "TestPrinters.h"
|
||||
|
||||
#include <wpi/json.h>
|
||||
|
||||
#include "Handle.h"
|
||||
#include "PubSubOptions.h"
|
||||
#include "net/Message.h"
|
||||
@@ -13,12 +11,6 @@
|
||||
#include "networktables/NetworkTableValue.h"
|
||||
#include "ntcore_cpp.h"
|
||||
|
||||
namespace wpi {
|
||||
void PrintTo(const json& val, ::std::ostream* os) {
|
||||
*os << val.dump();
|
||||
}
|
||||
} // namespace wpi
|
||||
|
||||
namespace nt {
|
||||
|
||||
void PrintTo(const Event& event, std::ostream* os) {
|
||||
|
||||
@@ -10,33 +10,7 @@
|
||||
#include <string_view>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace wpi {
|
||||
|
||||
class json;
|
||||
|
||||
inline void PrintTo(std::string_view str, ::std::ostream* os) {
|
||||
::testing::internal::PrintStringTo(std::string{str}, os);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void PrintTo(std::span<T> val, ::std::ostream* os) {
|
||||
*os << '{';
|
||||
bool first = true;
|
||||
for (auto v : val) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
*os << ", ";
|
||||
}
|
||||
*os << ::testing::PrintToString(v);
|
||||
}
|
||||
*os << '}';
|
||||
}
|
||||
|
||||
void PrintTo(const json& val, ::std::ostream* os);
|
||||
|
||||
} // namespace wpi
|
||||
#include <wpi/TestPrinters.h>
|
||||
|
||||
namespace nt {
|
||||
|
||||
|
||||
@@ -10,10 +10,10 @@
|
||||
#include <vector>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <wpi/SpanMatcher.h>
|
||||
|
||||
#include "../MockLogger.h"
|
||||
#include "../PubSubOptionsMatcher.h"
|
||||
#include "../SpanMatcher.h"
|
||||
#include "../TestPrinters.h"
|
||||
#include "../ValueMatcher.h"
|
||||
#include "Handle.h"
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
#include <vector>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <wpi/SpanMatcher.h>
|
||||
#include <wpi/json.h>
|
||||
#include <wpi/raw_ostream.h>
|
||||
|
||||
#include "../SpanMatcher.h"
|
||||
#include "../TestPrinters.h"
|
||||
#include "Handle.h"
|
||||
#include "PubSubOptions.h"
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
#include <string_view>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <wpi/SpanMatcher.h>
|
||||
|
||||
#include "../SpanMatcher.h"
|
||||
#include "../TestPrinters.h"
|
||||
#include "../ValueMatcher.h"
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
#include <vector>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <wpi/SpanMatcher.h>
|
||||
#include <wpi/raw_ostream.h>
|
||||
|
||||
#include "../SpanMatcher.h"
|
||||
#include "../TestPrinters.h"
|
||||
#include "net3/Message3.h"
|
||||
#include "net3/WireEncoder3.h"
|
||||
|
||||
@@ -91,6 +91,19 @@ model {
|
||||
}
|
||||
}
|
||||
}
|
||||
"${nativeName}TestLib"(NativeLibrarySpec) {
|
||||
sources {
|
||||
cpp {
|
||||
source {
|
||||
srcDirs 'src/testlib/native/cpp'
|
||||
include '**/*.cpp'
|
||||
}
|
||||
exportedHeaders {
|
||||
srcDirs 'src/test/native/include'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
testSuites {
|
||||
"${nativeName}Test"(GoogleTestTestSuiteSpec) {
|
||||
@@ -116,8 +129,10 @@ model {
|
||||
binaries {
|
||||
withType(GoogleTestTestSuiteBinarySpec) {
|
||||
lib library: nativeName, linkage: 'shared'
|
||||
lib library: "${nativeName}TestLib", linkage: 'shared'
|
||||
if (!project.hasProperty('noWpiutil')) {
|
||||
lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
|
||||
lib project: ':wpiutil', library: 'wpiutilTestLib', linkage: 'shared'
|
||||
if (it.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
|
||||
nativeUtils.useRequiredLibrary(it, 'ni_link_libraries', 'ni_runtime_libraries')
|
||||
}
|
||||
|
||||
@@ -225,6 +225,19 @@ model {
|
||||
}
|
||||
}
|
||||
}
|
||||
"${nativeName}TestLib"(NativeLibrarySpec) {
|
||||
sources {
|
||||
cpp {
|
||||
source {
|
||||
srcDirs 'src/testlib/native/cpp'
|
||||
include '**/*.cpp'
|
||||
}
|
||||
exportedHeaders {
|
||||
srcDirs 'src/test/native/include'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
testSuites {
|
||||
"${nativeName}Test"(GoogleTestTestSuiteSpec) {
|
||||
@@ -255,6 +268,7 @@ model {
|
||||
lib library: nativeName, linkage: 'shared'
|
||||
if (!project.hasProperty('noWpiutil')) {
|
||||
lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared'
|
||||
lib project: ':wpiutil', library: 'wpiutilTestLib', linkage: 'shared'
|
||||
if (it.targetPlatform.name == nativeUtils.wpi.platforms.roborio) {
|
||||
nativeUtils.useRequiredLibrary(it, 'ni_link_libraries', 'ni_runtime_libraries')
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ repoRootNameOverride {
|
||||
|
||||
includeOtherLibs {
|
||||
^fmt/
|
||||
^gmock/
|
||||
^gtest/
|
||||
}
|
||||
|
||||
|
||||
@@ -189,7 +189,10 @@ foreach(example ${wpiutil_examples})
|
||||
endforeach()
|
||||
|
||||
if (WITH_TESTS)
|
||||
file(GLOB_RECURSE wpiutil_testlib_src src/test/native/include/*.h)
|
||||
add_library(wpiutil_testlib INTERFACE ${wpiutil_test_src})
|
||||
target_include_directories(wpiutil_testlib INTERFACE src/test/native/include)
|
||||
|
||||
wpilib_add_test(wpiutil src/test/native/cpp)
|
||||
target_include_directories(wpiutil_test PRIVATE src/test/native/include)
|
||||
target_link_libraries(wpiutil_test wpiutil gmock_main)
|
||||
target_link_libraries(wpiutil_test wpiutil gmock_main wpiutil_testlib)
|
||||
endif()
|
||||
|
||||
@@ -13,8 +13,9 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "TestPrinters.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
#include "wpi/TestPrinters.h"
|
||||
|
||||
namespace wpi {
|
||||
|
||||
41
wpiutil/src/test/native/include/wpi/TestPrinters.h
Normal file
41
wpiutil/src/test/native/include/wpi/TestPrinters.h
Normal file
@@ -0,0 +1,41 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// 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.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ostream>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "wpi/json.h"
|
||||
|
||||
namespace wpi {
|
||||
|
||||
inline void PrintTo(std::string_view str, ::std::ostream* os) {
|
||||
::testing::internal::PrintStringTo(std::string{str}, os);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void PrintTo(std::span<T> val, ::std::ostream* os) {
|
||||
*os << '{';
|
||||
bool first = true;
|
||||
for (auto v : val) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
*os << ", ";
|
||||
}
|
||||
*os << ::testing::PrintToString(v);
|
||||
}
|
||||
*os << '}';
|
||||
}
|
||||
|
||||
inline void PrintTo(const json& val, ::std::ostream* os) {
|
||||
*os << val.dump();
|
||||
}
|
||||
|
||||
} // namespace wpi
|
||||
Reference in New Issue
Block a user