Skip to content

Commit

Permalink
master: gunit basics
Browse files Browse the repository at this point in the history
  • Loading branch information
Mate Pek committed Apr 26, 2022
1 parent a42420e commit 17e8e7e
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 46 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]

## [4.1.1]

### Added

- experimental basic support for GUnit framework.

## [4.1.0] - 2022-04-26

### Added
Expand Down
42 changes: 29 additions & 13 deletions src/framework/GoogleTestExecutable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,33 @@ export class GoogleTestExecutable extends AbstractExecutable<GoogleTestTest> {
valueParam: string | undefined,
): Promise<GoogleTestTest> => {
const resolvedFile = this.findSourceFilePath(file);
return this._createTreeAndAddTest(
this.getTestGrouping(),
testName,
resolvedFile,
line,
[suiteName],
undefined,
(parent: TestItemParent) =>
new GoogleTestTest(this, parent, testName, suiteName, typeParam, valueParam, resolvedFile, line),
(test: GoogleTestTest) => test.update2(testName, suiteName, resolvedFile, line, typeParam, valueParam),
);
const id = suiteName + '.' + testName;
// gunit
if (testName === '') {
return this._createTreeAndAddTest(
this.getTestGrouping(),
'<GUnit>',
resolvedFile,
line,
[suiteName],
undefined,
(parent: TestItemParent) =>
new GoogleTestTest(this, parent, id, '<GUnit>', suiteName, typeParam, valueParam, resolvedFile, line),
(test: GoogleTestTest) => test.update2('<GUnit>', suiteName, resolvedFile, line, typeParam, valueParam),
);
} else {
return this._createTreeAndAddTest(
this.getTestGrouping(),
testName,
resolvedFile,
line,
[suiteName],
undefined,
(parent: TestItemParent) =>
new GoogleTestTest(this, parent, id, testName, suiteName, typeParam, valueParam, resolvedFile, line),
(test: GoogleTestTest) => test.update2(testName, suiteName, resolvedFile, line, typeParam, valueParam),
);
}
};

protected async _reloadChildren(cancellationToken: CancellationToken): Promise<void> {
Expand Down Expand Up @@ -314,7 +330,7 @@ class TestSuiteListingProcessor implements XmlTagProcessor {
switch (tag.name) {
case 'testcase': {
assert(this.suiteName);
assert(tag.attribs.name);
assert(typeof tag.attribs.name == 'string'); // for gunit it can be empty
await this.create(
tag.attribs.name,
this.suiteName!,
Expand All @@ -334,7 +350,7 @@ class TestSuiteListingProcessor implements XmlTagProcessor {
///

// Remark: not necessarily starts like this so do not use: ^
const testBeginRe = /\[ RUN \] ((.+)\.(.+))$/m;
const testBeginRe = /\[ RUN \] ((.+)\.(.*))$/m;
// Ex: "Is True[ OK ] TestCas1.test5 (0 ms)"
// m[1] == '[ '
// m[2] == 'OK'
Expand Down
2 changes: 1 addition & 1 deletion src/framework/GoogleTestTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ export class GoogleTestTest extends AbstractTest {
constructor(
executable: AbstractExecutable,
parent: TestItemParent,
testNameAsId: string,
testName: string,
suiteName: string,
typeParam: string | undefined,
valueParam: string | undefined,
file: string | undefined,
line: string | undefined,
) {
const testNameAsId = suiteName + '.' + testName;
super(
executable,
parent,
Expand Down
1 change: 1 addition & 0 deletions test/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ add_custom_target(
#

add_subdirectory("catch2")
add_subdirectory("gunit")
add_subdirectory("gtest")
add_subdirectory("doctest")
add_subdirectory("gbenchmark")
Expand Down
62 changes: 31 additions & 31 deletions test/cpp/gtest/GoogleTest.cmake
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
include(FetchContent)

# Prevent overriding the parent project's compiler/linker
# settings on Windows
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)

FetchContent_Declare(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.10.0)

FetchContent_GetProperties(googletest)
if(NOT googletest_POPULATED)
FetchContent_Populate(googletest)
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR}
EXCLUDE_FROM_ALL)
endif()

mark_as_advanced(BUILD_GMOCK
BUILD_GTEST
BUILD_SHARED_LIBS
gmock_build_tests
gtest_build_samples
gtest_build_tests
gtest_disable_pthreads
gtest_force_shared_crt
gtest_hide_internal_symbols)

set_target_properties(gtest PROPERTIES FOLDER extern)
set_target_properties(gtest_main PROPERTIES FOLDER extern)
set_target_properties(gmock PROPERTIES FOLDER extern)
set_target_properties(gmock_main PROPERTIES FOLDER extern)
# include(FetchContent)

# # Prevent overriding the parent project's compiler/linker
# # settings on Windows
# set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)

# FetchContent_Declare(googletest
# GIT_REPOSITORY https://github.com/google/googletest.git
# GIT_TAG release-1.10.0)

# FetchContent_GetProperties(googletest)
# if(NOT googletest_POPULATED)
# FetchContent_Populate(googletest)
# add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR}
# EXCLUDE_FROM_ALL)
# endif()

# mark_as_advanced(BUILD_GMOCK
# BUILD_GTEST
# BUILD_SHARED_LIBS
# gmock_build_tests
# gtest_build_samples
# gtest_build_tests
# gtest_disable_pthreads
# gtest_force_shared_crt
# gtest_hide_internal_symbols)

# set_target_properties(gtest PROPERTIES FOLDER extern)
# set_target_properties(gtest_main PROPERTIES FOLDER extern)
# set_target_properties(gmock PROPERTIES FOLDER extern)
# set_target_properties(gmock_main PROPERTIES FOLDER extern)

#

Expand Down
2 changes: 1 addition & 1 deletion test/cpp/gtest/gtest2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ GTEST_TEST(TestCas3, test5) {

GTEST_TEST(TestCas3, test6) {
std::vector<int> v({5, 10});
ASSERT_THAT(v, ::testing::ElementsAre(5, 10, 15));
ASSERT_THAT(v, ::testing::ElementsAre(5, 10, 15)) << "extra message";
}

// with custom matcher
Expand Down
3 changes: 3 additions & 0 deletions test/cpp/gunit/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include("GUnit.cmake")

add_gunit_with_main(gunit1 "gunit1.cpp")
52 changes: 52 additions & 0 deletions test/cpp/gunit/GUnit.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
include(FetchContent)

# Prevent overriding the parent project's compiler/linker
# settings on Windows
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)

FetchContent_Declare(gunit
GIT_REPOSITORY https://github.com/cpp-testing/GUnit.git
GIT_TAG v1.11.0)

FetchContent_GetProperties(gunit)
if(NOT gunit_POPULATED)
FetchContent_Populate(gunit)
add_subdirectory(${gunit_SOURCE_DIR} ${gunit_BINARY_DIR}
EXCLUDE_FROM_ALL)
endif()

mark_as_advanced(BUILD_GMOCK
BUILD_GTEST
BUILD_SHARED_LIBS
gmock_build_tests
gtest_build_samples
gtest_build_tests
gtest_disable_pthreads
gtest_force_shared_crt
gtest_hide_internal_symbols)

set_target_properties(gtest PROPERTIES FOLDER extern)
set_target_properties(gtest_main PROPERTIES FOLDER extern)
set_target_properties(gmock PROPERTIES FOLDER extern)
set_target_properties(gmock_main PROPERTIES FOLDER extern)

#

add_library(ThirdParty.GUnit INTERFACE)

target_link_libraries(ThirdParty.GUnit
INTERFACE gunit)

target_compile_features(ThirdParty.GUnit INTERFACE cxx_std_14)

target_include_directories(
ThirdParty.GUnit
INTERFACE "${gunit_SOURCE_DIR}/include")

#

function(add_gunit_with_main target cpp_file)
add_executable(${target} "${cpp_file}")
target_link_libraries(${target} PUBLIC ThirdParty.GUnit)
endfunction()

12 changes: 12 additions & 0 deletions test/cpp/gunit/gunit1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <GUnit.h>

GTEST("Calc Test") {
// SetUp
SHOULD("return succ") {
EXPECT(5 == 5);
}
SHOULD("return fail") {
EXPECT(5 == 6);
}
// TearDown
}

0 comments on commit 17e8e7e

Please sign in to comment.