Googletest - Google Testing and Mocking Framework

GoogleTest

OSS Builds Status

Build status

Announcements

Release 1.10.x

Release 1.10.x is now available.

Coming Soon

Welcome to GoogleTest, Google's C++ test framework!

This repository is a merger of the formerly separate GoogleTest and GoogleMock projects. These were so closely related that it makes sense to maintain and release them together.

Getting Started

The information for GoogleTest is available in the GoogleTest Primer documentation.

GoogleMock is an extension to GoogleTest for writing and using C++ mock classes. See the separate GoogleMock documentation.

More detailed documentation for googletest is in its interior googletest/README.md file.

Features

  • An xUnit test framework.
  • Test discovery.
  • A rich set of assertions.
  • User-defined assertions.
  • Death tests.
  • Fatal and non-fatal failures.
  • Value-parameterized tests.
  • Type-parameterized tests.
  • Various options for running the tests.
  • XML test report generation.

Supported Platforms

GoogleTest requires a codebase and compiler compliant with the C++11 standard or newer.

The GoogleTest code is officially supported on the following platforms. Operating systems or tools not listed below are community-supported. For community-supported platforms, patches that do not complicate the code may be considered.

If you notice any problems on your platform, please file an issue on the GoogleTest GitHub Issue Tracker. Pull requests containing fixes are welcome!

Operating Systems

  • Linux
  • macOS
  • Windows

Compilers

  • gcc 5.0+
  • clang 5.0+
  • MSVC 2015+

macOS users: Xcode 9.3+ provides clang 5.0+.

Build Systems

Note: Bazel is the build system used by the team internally and in tests. CMake is supported on a best-effort basis and by the community.

Who Is Using GoogleTest?

In addition to many internal projects at Google, GoogleTest is also used by the following notable projects:

Related Open Source Projects

GTest Runner is a Qt5 based automated test-runner and Graphical User Interface with powerful features for Windows and Linux platforms.

GoogleTest UI is a test runner that runs your test binary, allows you to track its progress via a progress bar, and displays a list of test failures. Clicking on one shows failure text. Google Test UI is written in C#.

GTest TAP Listener is an event listener for GoogleTest that implements the TAP protocol for test result output. If your test runner understands TAP, you may find it useful.

gtest-parallel is a test runner that runs tests from your binary in parallel to provide significant speed-up.

GoogleTest Adapter is a VS Code extension allowing to view GoogleTest in a tree view, and run/debug your tests.

C++ TestMate is a VS Code extension allowing to view GoogleTest in a tree view, and run/debug your tests.

Cornichon is a small Gherkin DSL parser that generates stub code for GoogleTest.

Contributing Changes

Please read CONTRIBUTING.md for details on how to contribute to this project.

Happy testing!

Owner
Google
Google ❤️ Open Source
Google
Comments
  • Install CMake export files

    Install CMake export files

    CMake export files automate the task of importing GTest libraries into the CMake project that links them (See Exporting from an Installation Tree). Also:

    1. Issue https://github.com/google/googletest/issues/878 mentions two alternative approaches, but the CMake export files are the more idiomatic solution nowadays (see The Ultimate Guide to Modern CMake). Specifically: a. The add_subdirectory approach might interfere with the global settings of the host CMake project. b. The find_package approach does not support Release+Debug installations. The CMake export files address both these limitations.
    2. W.r.t. PR #768, this patch uses 'GTest' instead of 'Gtest' for the CMake namespace of the exported targets. Rationale: to be consistent with the existing 'FindGtest' CMake module (https://cmake.org/cmake/help/v3.10/module/FindGTest.html).
    3. Also, w.r.t. PR #768, this patch does not override the DEBUG_POSTFIX CMake property for the exported targets. Rationale: give to the user the flexibility to choose its own suffix (and if to use one at all).
  • Test Pull For Monotonic clock

    Test Pull For Monotonic clock

    This is a tentative cross platform patch for enabling a monotonic clock in gtest for test elapsed time. It uses C++ 11 chrono library if available; otherwise specific OS calls for Windows/Linux/Mac.

  • add timeouts to tests

    add timeouts to tests

    it would be nice to implement timeouts for tests.
    thus a test will fail if it does not complete successfully within the alloted 
    time frame. makes it easier to impose performance restrictions on cerain 
    operations, and also to make sure that if a certain test hangs, other test 
    cases can run instead of aborting everything/
    
    

    Original issue reported on code.google.com by [email protected] on 29 Dec 2010 at 7:15

  • Allow MOCK_METHOD without specifying the argument count

    Allow MOCK_METHOD without specifying the argument count

    Currently, you must use the correct MOCK_METHODn macro:

    MOCK_METHOD2(foo, void(int, int));
    MOCK_METHOD3(bar, void(int, int, int));
    

    I suggest a variation that works without the number:

    MOCK_METHOD(foo, void, (int, int));
    MOCK_METHOD(bar, void, (int, int, int));
    

    Note that the return type is now separate from the argument types.

    Implementing this isn't complicated. It's basically this:

    #define MOCK_METHOD(name, ret, args) MOCK_METHOD##PP_NARG(args)(name, ret args)
    

    Where PP_NARG is define as in this StackOverflow answer. It will be limited to a maximum number of arguments - but so are existing MOCK_METHODn macros. Perhaps there's a more elegant implementation, instead of reducing it to existing macros.

    I'm willing to do the development (if I think there's a chance that it will be accepted).

  • Use override keyword with new C++11 compilers

    Use override keyword with new C++11 compilers

    From @GoogleCodeExporter on August 24, 2015 22:40

    The C++11 standard introduces new "override" and "final" keywords in virtual 
    function declarations. The "override" keyword is especially useful in context 
    of creating mock functions. Macros MOCK_METHOD* expand to virtual methods that 
    have to be present in base class in order to be useful as mocks. And, since we 
    have to define mocks and class interface separately, this creates a possible 
    gap for bugs when changing method prototypes.
    
    For example, changing a type of argument in base class method, without updating 
    the associated MOCK_METHOD* macro, will define the mock method as overloading 
    and compilers will silently allow such buggy code to compile. However, using 
    the new C++11 feature, mismatched function declarations will result in compile 
    error, thus allowing the programmer to clearly state his purpose.
    
    In my projects, I patched GMock macros to optionally include the override 
    keyword - see the attached diff. I think such improvement merits for inclusion 
    in upstream, so I decided to create this issue.
    

    Original issue reported on code.google.com by [email protected] on 15 Dec 2012 at 9:23

    Attachments:

    Copied from original issue: google/googlemock#157

  • 10.6 SL : pointer being freed was not allocated

    10.6 SL : pointer being freed was not allocated

    What steps will reproduce the problem?
    1. Build and link code on MacOS X 10.6 GM
    2. Run any test code with or without debugger
    
    What is the expected output? What do you see instead?
    
    1. If code is run without a debugger, the following errors appear in the 
    terminal, EVERY time 
    there is text to display:
    
    <proc>(27319) malloc: *** error for object 0x7fff70ca5500: pointer being freed 
    was not 
    allocated
    *** set a breakpoint in malloc_error_break to debug
    
    The tests will still run, as the SIGABRT is being caught by gtest, but the 
    error will persist.
    
    2. If the code is run with a debugger, here is the following output:
    
    <proc>(27319) malloc: *** error for object 0x7fff70ca5500: pointer being freed 
    was not 
    allocated
    *** set a breakpoint in malloc_error_break to debug
    Program received signal:  “SIGABRT”.
    
    What version of the product are you using? On what operating system?
    
    GTest 1.3.0, 10.6 Snow Leopard (10A432)
    
    Please provide any additional information below.
    
    There seems to be some funny interaction with the libstdc++ and gtest 1.3.0. 
    10.5.x (all 
    versions) work perfectly with gtest 1.3.0
    
    
    

    Original issue reported on code.google.com by [email protected] on 31 Aug 2009 at 3:05

  • googletest on Visual Studio 2012 RC on Windows 8 RC does not compile

    googletest on Visual Studio 2012 RC on Windows 8 RC does not compile

    I would like to request that the team supports Windows 8 RC.  I know that 
    Windows 8 RC is not a release from Microsoft.  However, being able to support 
    developers working on the Windows 8 platform would be really nice.  Currently, 
    trying to even compile gtest on Windows 8 fails.  I detail the problems below.  
    
    What steps will reproduce the problem?
    1.  Loading the solution with Visual Studio 2012 RC on Windows 8 RC Build 8400 
    will cause the solution to be converted to Visual Studio 2012 v110 code 
    generation.
    2.  Upon attempting to build gtest a number of compiler issues occur.  All of 
    the errors occur in gtest-param-util-generated.h related to templates.  Visual 
    Studio 2012 has an issue with the number of template arguments in 
    std::tr1::tuple according to the compiler.
    
    What is the expected output? What do you see instead?
    The expected output is that the build is successful.  Instead, I get the 
    following output:  
    
    Note: Output has been modified slightly to hide some details unrelated to gtest:
    
    1>\ext\gtest-1.5.0\include\gtest\internal\gtest-param-util-generated.h(4015): 
    error C2977: 'std::tuple' : too many template arguments
    1>          c:\program files (x86)\microsoft visual studio 
    11.0\vc\include\utility(73) : see declaration of 'std::tuple'
    1>          
    \ext\gtest-1.5.0\include\gtest\internal\gtest-param-util-generated.h(4247) : 
    see reference to class template instantiation 
    'testing::internal::CartesianProductGenerator9<T1,T2,T3,T4,T5,T6,T7,T8,T9>' 
    being compiled
    1>c:\users\msfrucht\desktop\win8nfc\win8nfc\c3nfc\ext\gtest-1.5.0\include\gtest\
    internal\gtest-param-util-generated.h(4015): error C3203: 'tuple' : 
    unspecialized class template can't be used as a template argument for template 
    parameter 'T', expected a real type
    1>c:\users\msfrucht\desktop\win8nfc\win8nfc\c3nfc\ext\gtest-1.5.0\include\gtest\
    internal\gtest-param-util-generated.h(4015): error C2955: 'std::tuple' : use of 
    class template requires template argument list
    1>          c:\program files (x86)\microsoft visual studio 
    11.0\vc\include\utility(73) : see declaration of 'std::tuple'
    1>\ext\gtest-1.5.0\include\gtest\internal\gtest-param-util-generated.h(4015): 
    error C2955: 'testing::internal::ParamGeneratorInterface' : use of class 
    template requires template argument list
    1>          \ext\gtest-1.5.0\include\gtest\internal\gtest-param-util.h(141) : 
    see declaration of 'testing::internal::ParamGeneratorInterface'
    1>\gtest-1.5.0\include\gtest\internal\gtest-param-util-generated.h(4017): error 
    C2977: 'std::tuple' : too many template arguments
    1>          c:\program files (x86)\microsoft visual studio 
    11.0\vc\include\utility(73) : see declaration of 'std::tuple'
    
    What version of Google Test are you using? On what operating system?
    I am using Google Test 1.5 on Windows 8 RC Build 8400 x64.
    
    

    Original issue reported on code.google.com by [email protected] on 4 Jun 2012 at 11:45

  • need a way to resume from the TEST that crashed

    need a way to resume from the TEST that crashed

    Requested by Timur Iskhodzhanov <[email protected]>:
    
    Consider we have a large number of tests in one executable (e.g.
    Chromium unit_tests or ui_tests)
    
    Use case:
    One's local change has introduced a failure in a test X.Y which is
    executed somewhere in the middle of the test run
    (e.g. the whole binary takes 10 minutes, the failure happens after 5
    minutes of running).
    
    If he/she is sure the tests that are executed before X.Y are not
    affected by the fix - he/she should be able to skip them and run only
    X.Y and the following tests.
    
    This feature will be especially useful for those who develop Valgrind-
    like tools and test them using binaries based on googletest.
    In this case it's quite common that some particular test is failing
    when run under the tool and when it's fixed we should run only those
    tests that follow X.Y
    
    By "failure" I meant a crash or non-googletest assertion.
    So the execution stops when X.Y fails.
    
    Example: Chromium code uses CHECKs inside its code and as soon as they
    fail, it prints out the stack trace and aborts the execution.
    Another example: if there is a bug in Valgrind-like tool, it may crash
    in an internal assertion when running X.Y and stop the test execution.
    

    Original issue reported on code.google.com by [email protected] on 7 Sep 2010 at 7:07

  • Skipping tests at runtime with GTEST_SKIP()

    Skipping tests at runtime with GTEST_SKIP()

    Description

    Nothing fancy, plain and simple test skipping based on condition evaluated at runtime. One might want to skip

    • tests which are not supported within current environment,
    • tests which depend on some external resource with conditional availability,
    • tests which require privileges when run under user with no such privileges, etc.

    Feature has been requested several times, see #160, #490 and #822. Works as demonstrated in sample test:

    TEST(SkipTest, DoesSkip) {
      SKIP();
      EXPECT_EQ(0, 1);
    }
    

    yields

    [==========] Running 1 test from 1 test case.
    [----------] Global test environment set-up.
    [----------] 1 test from SkipTest
    [ RUN      ] SkipTest.DoesSkip
    [  SKIPPED ] SkipTest.DoesSkip (1 ms)
    [----------] 1 test from SkipTest (1 ms total)
    
    [----------] Global test environment tear-down
    [==========] 1 test from 1 test case ran. (1 ms total)
    [  PASSED  ] 0 tests.
    [  SKIPPED ] 1 test, listed below:
    [  SKIPPED ] SkipTest.DoesSkip
    

    Skipped tests are displayed in green, and are not considered neither successful nor failed since they have never been completely run.

    Further work

    There are some conceptual issues which are not yet resolved, but I would love to hear you thoughts on them.

    1. Listing all skipped tests on teardown might be not such a good idea; it is at least reasonable to add compile option to control this behaviour.
    2. If test is skipped at any point, all preceding failures, which occurred in this test, are ignored; this can be handled in test result assigning with checking for failures before setting kSkip result.
    3. Skipping is not available from SetUp() and TearDown() methods, as well as from functions external to test body, since skipping aborts only current function; this can be resolved by adding additional AssertHelpers in fashion similar to handling FAIL().
    4. Additional improvements shall be made in loggers to support this additional test result.
  • Fix FreeBSD -Werror compilation issues

    Fix FreeBSD -Werror compilation issues

    The attached pull request fixes 2 trivial issues when compiling the googletest tests on FreeBSD with WARNS >= 1, i.e., -Werror on, with clang.

    This issue was seen when trying to integrate googletest 1.8.1 into the FreeBSD base system on my GitHub project branch.

    This PR requires #2100.

  • Regular expressions from C++ 11?

    Regular expressions from C++ 11?

    Hi, I did a preliminary check and it doesn't seem that Google Test uses C++'s regex library. Would you be interested in adding it? Or are there reasons why this is not a good idea?

    If it is something worthwhile, I'd like to take a closer look and propose a pull request.

  • [Bug]: valgrind reports still reachable memory leaks when StrictMock or NiceMock are used

    [Bug]: valgrind reports still reachable memory leaks when StrictMock or NiceMock are used

    Describe the issue

    Valgrind reports still reachable memory leaks when StrictMock or NiceMock are used. This didn't happen in gtest/gmock 1.11.0.

    Steps to reproduce the problem

    • Save this to a file and build it (I used g++ -g gmock_leak.cpp -lgtest -lgmock -lgmock_main):
    #include <gmock/gmock.h>
    #include <gtest/gtest.h>
    struct A { virtual ~A() {} virtual void do_it() {} };
    struct MockA: public A { MOCK_METHOD(void, do_it, (), (override)); };
    TEST(Test, PleaseDoNotLeak) { ::testing::StrictMock<MockA> mock; }
    
    • Run the resultant executable under valgrind with full leak checking enabled (I used valgrind --track-origins=yes --leak-check=full --show-leak-kinds=all ./a.out)

    What version of GoogleTest are you using?

    1.12.1

    What operating system and version are you using?

    debian testing (aka 12, aka bookworm)

    What compiler and version are you using?

    COLLECT_GCC=gcc
    COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/12/lto-wrapper
    OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
    OFFLOAD_TARGET_DEFAULT=1
    Target: x86_64-linux-gnu
    Configured with: ../src/configure -v --with-pkgversion='Debian 12.2.0-11' --with-bugurl=file:///usr/share/doc/gcc-12/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-12 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-12-gRbBs2/gcc-12-12.2.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-12-gRbBs2/gcc-12-12.2.0/debian/tmp-gcn/usr --enable-offload-defaulted --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
    Thread model: posix
    Supported LTO compression algorithms: zlib zstd
    gcc version 12.2.0 (Debian 12.2.0-11)```
    
    ### What build system are you using?
    
    I'm using the package distributed with debian, libgtest-dev:amd64 version 1.12.1-0.2.  So I didn't build it myself.
    
    ### Additional context
    
    I'm using valgrind version 3.19.0.
    
    Here's the valgrind output from the simple test program from the "steps to reproduce" section:
    ```==19050== HEAP SUMMARY:
    ==19050==     in use at exit: 160 bytes in 2 blocks
    ==19050==   total heap usage: 187 allocs, 185 frees, 112,822 bytes allocated
    ==19050==
    ==19050== 56 bytes in 1 blocks are still reachable in loss record 1 of 2
    ==19050==    at 0x4840F2F: operator new(unsigned long) (vg_replace_malloc.c:422)
    ==19050==    by 0x14E471: testing::(anonymous namespace)::UninterestingCallReactionMap()
    ==19050==    by 0x157E9C: testing::(anonymous namespace)::SetReactionOnUninterestingCalls(unsigned long, testing::internal::CallReaction)
    ==19050==    by 0x118A71: testing::internal::StrictMockImpl<MockA>::StrictMockImpl() (gmock-nice-strict.h:138)
    ==19050==    by 0x117D84: testing::StrictMock<MockA>::StrictMock() (gmock-nice-strict.h:242)
    ==19050==    by 0x1166E1: Test_PleaseDoNotLeak_Test::TestBody() (gmock_leak.cpp:5)
    ==19050==    by 0x14D486: void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*)
    ==19050==    by 0x13DE7D: testing::Test::Run()
    ==19050==    by 0x13E034: testing::TestInfo::Run()
    ==19050==    by 0x13E5D8: testing::TestSuite::Run()
    ==19050==    by 0x14397E: testing::internal::UnitTestImpl::RunAllTests()
    ==19050==    by 0x14D9F6: bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*)
    ==19050==
    
    ==19050== 104 bytes in 1 blocks are still reachable in loss record 2 of 2
    ==19050==    at 0x4840F2F: operator new(unsigned long) (vg_replace_malloc.c:422)
    ==19050==    by 0x15A7C9: std::_Hashtable<unsigned long, std::pair<unsigned long const, testing::internal::CallReaction>, std::allocator<std::pair<unsigned long const, testing::internal::CallReaction> >, std::__detail::_Select1st, std::equal_to<unsigned long>, std::hash<unsigned long>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::_M_rehash(unsigned long, unsigned long const&)
    ==19050==    by 0x15A965: std::_Hashtable<unsigned long, std::pair<unsigned long const, testing::internal::CallReaction>, std::allocator<std::pair<unsigned long const, testing::internal::CallReaction> >, std::__detail::_Select1st, std::equal_to<unsigned long>, std::hash<unsigned long>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::_M_insert_unique_node(unsigned long, unsigned long, std::__detail::_Hash_node<std::pair<unsigned long const, testing::internal::CallReaction>, false>*, unsigned long)
    ==19050==    by 0x157F73: testing::(anonymous namespace)::SetReactionOnUninterestingCalls(unsigned long, testing::internal::CallReaction)
    ==19050==    by 0x118A71: testing::internal::StrictMockImpl<MockA>::StrictMockImpl() (gmock-nice-strict.h:138)
    ==19050==    by 0x117D84: testing::StrictMock<MockA>::StrictMock() (gmock-nice-strict.h:242)
    ==19050==    by 0x1166E1: Test_PleaseDoNotLeak_Test::TestBody() (gmock_leak.cpp:5)
    ==19050==    by 0x14D486: void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*)
    ==19050==    by 0x13DE7D: testing::Test::Run()
    ==19050==    by 0x13E034: testing::TestInfo::Run()
    ==19050==    by 0x13E5D8: testing::TestSuite::Run()
    ==19050==    by 0x14397E: testing::internal::UnitTestImpl::RunAllTests()
    ==19050==
    ==19050== LEAK SUMMARY:
    ==19050==    definitely lost: 0 bytes in 0 blocks
    ==19050==    indirectly lost: 0 bytes in 0 blocks
    ==19050==      possibly lost: 0 bytes in 0 blocks
    ==19050==    still reachable: 160 bytes in 2 blocks
    ==19050==         suppressed: 0 bytes in 0 blocks```
  • GCC-12: Compiler error with C++20 mode on `char* + string`.

    GCC-12: Compiler error with C++20 mode on `char* + string`.

    Describe the issue

    Compile error in gtest-all.cc with GCC-12 and C++20 mode.

    Steps to reproduce the problem

    There were no errors compiling with GCC-11, but with GCC-12 I get this error:

    FAILED: third_party/googletest/googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.o 
    /usr/bin/g++-12  -I/home/runner/work/subspace/subspace/third_party/googletest/googletest/include -I/home/runner/work/subspace/subspace/third_party/googletest/googletest -O3 -DNDEBUG -Wall -Wshadow -Werror -Wno-error=dangling-else -DGTEST_HAS_PTHREAD=1 -fexceptions -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -std=c++20 -MD -MT third_party/googletest/googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.o -MF third_party/googletest/googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.o.d -o third_party/googletest/googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.o -c /home/runner/work/subspace/subspace/third_party/googletest/googletest/src/gtest-all.cc
    In file included from /usr/include/c++/12/ios:40,
                     from /usr/include/c++/12/ostream:38,
                     from /usr/include/c++/12/bits/unique_ptr.h:41,
                     from /usr/include/c++/12/memory:76,
                     from /home/runner/work/subspace/subspace/third_party/googletest/googletest/include/gtest/gtest.h:57,
                     from /home/runner/work/subspace/subspace/third_party/googletest/googletest/src/gtest-all.cc:38:
    In static member function ‘static constexpr std::char_traits<char>::char_type* std::char_traits<char>::copy(char_type*, const char_type*, std::size_t)’,
        inlined from ‘static constexpr void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_S_copy(_CharT*, const _CharT*, size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ at /usr/include/c++/12/bits/basic_string.h:423:21,
        inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits, _Allocator>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_replace(size_type, size_type, const _CharT*, size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ at /usr/include/c++/12/bits/basic_string.tcc:532:22,
        inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::replace(size_type, size_type, const _CharT*, size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ at /usr/include/c++/12/bits/basic_string.h:2171:19,
        inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::insert(size_type, const _CharT*) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ at /usr/include/c++/12/bits/basic_string.h:1928:22,
        inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const _CharT*, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&) [with _CharT = char; _Traits = char_traits<char>; _Alloc = allocator<char>]’ at /usr/include/c++/12/bits/basic_string.h:3541:36,
        inlined from ‘static std::string testing::internal::StreamingListener::UrlEncode(const char*)’ at /home/runner/work/subspace/subspace/third_party/googletest/googletest/src/gtest.cc:4882:27:
    /usr/include/c++/12/bits/char_traits.h:431:56: error: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ accessing 9223[37](https://github.com/chromium/subspace/actions/runs/3814961661/jobs/6489651472#step:7:38)2036854775810 or more bytes at offsets [2, 9223372036854775807] and 1 may overlap up to 9223372036854775813 bytes at offset -3 [-Werror=restrict]
      [43](https://github.com/chromium/subspace/actions/runs/3814961661/jobs/6489651472#step:7:44)1 |         return static_cast<char_type*>(__builtin_memcpy(__s1, __s2, __n));
          |                                        ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
    cc1plus: all warnings being treated as errors
    

    Clearly 9223372036854775813 is a lot of bytes.

    https://github.com/chromium/subspace/actions/runs/3814961661/jobs/6489651472 demonstrates the error.

    https://github.com/chromium/subspace/pull/173/commits/ecded91d1accaa6718628f5bd8eee07ea027c2f8 fixes the error.

    -        result.append("%" + String::FormatByte(static_cast<unsigned char>(ch)));
    +        result.push_back('%');
    +        result.append(String::FormatByte(static_cast<unsigned char>(ch)));
    

    What version of GoogleTest are you using?

    googletest 1.11

    What operating system and version are you using?

    Ubuntu 22.04.1 LTS

    What compiler and version are you using?

    gcc 12.1.0 Compiling with -std=c++20

    What build system are you using?

    cmake on github actions

    Additional context

    No response

  • Add GTEST_HAS_PTHREAD to GTest::* target interfaces

    Add GTEST_HAS_PTHREAD to GTest::* target interfaces

    Add -DGTEST_HAS_PTHREAD=0/1 compiler flag to GTest::* CMake targets as pkg-config do.

    Using CMake find_package my code compiled & linked smoothly but SIGSEGV when executed. Setting macro in CMAKE_CXX_FLAGS fixed it. I noted pkg-config gtest --cflags includes this macro.

  • [Bug]: C++20: gtest attempts to invoke deleted stream insertion operators :: Still a problem for MSVC UNICODE builds

    [Bug]: C++20: gtest attempts to invoke deleted stream insertion operators :: Still a problem for MSVC UNICODE builds

    Describe the issue

    Same error as #3266, different cause (probably, if I read the entrails of #3266 right).

    Steps to reproduce the problem

    Build gtest code in MSVC2022 as a full UNICODE ("Use Unicode Character Set") build & /std:c++20 compiler option set. (We use our own in-house MSVC projects for that, enforcing unified builds of all libraries employed around here)

    Results in this:

    googletest\googletest\src\gtest.cc(5026,5): error C2280: 'std::basic_ostream<char,std::char_traits<char>> &std::operator <<<std::char_traits<char>>(std::basic_ostream<char,std::char_traits<char>> &,const wchar_t *)': attempting to reference a deleted function
    1>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.34.31933\include\ostream(965,31): message : see declaration of 'std::operator <<'
    googletest\googletest\src\gtest.cc(5026,5): error C2088: '<<': illegal for class
    

    What version of GoogleTest are you using?

    Bleeding edge master from this repo, patched in a few other places. (Did a code review/comparison, and this is issue exists in vanilla mainline as-is.)

    What operating system and version are you using?

    Win10/64, latest updates as of time of writing this issue.

    What compiler and version are you using?

    MSVC2022 Version 17.4.3

    What build system are you using?

    in-house managed MSVC2022 solution + project files.

    Additional context

    No response

  • [Bug]: NVCC, lambdas and private `TestBody`

    [Bug]: NVCC, lambdas and private `TestBody`

    Describe the issue

    When using nvcc (for compiling on NVidia GPUs), it is not possible to create lambdas withing the test body because ::testing::Test::TestBody is private (e.g. when using the macro GTEST_TEST). It is a restriction from CUDA, see https://docs.nvidia.com/cuda/cuda-c-programming-guide/#extended-lambda-restrictions.

    This means code bases like https://github.com/trilinos/Trilinos have less chance to use Google Test for their unit testing, since their goal is to work with a code on any CPU or GPU.

    The fix could be to promote ::testing::Test::TestBody as a public method. It could even be an opt-in choice (i.e. keep it private by default, and allow it to be public based on some CMake option.

    Steps to reproduce the problem

    Here is a minimal reproducer:

    class MyClass
    {
        protected:
            void TestBody()
            {
                auto my_lambda = [=] __host__ __device__ (void) -> int { return 5.0; };
            }
    };
    

    that would fail compiling with

    test.cpp(...): error: The enclosing parent function ("TestBody") for an extended __host__ __device__ lambda cannot have private or protected access within its class
    

    What version of GoogleTest are you using?

    I'm using the latest release 1.12.1.

    What operating system and version are you using?

    I'm on Ubuntu 22.04.

    What compiler and version are you using?

    I'm using nvcc from CUDA 12.0.0 in conjunction with gcc 11.3.0.

    What build system are you using?

    cmake version 3.25.1

    Proposed patch

    From 84c85d697bc6309f448df7af691ff6e71027fc59 Mon Sep 17 00:00:00 2001
    From: "romin.tomasetti" <[email protected]>
    Date: Wed, 28 Dec 2022 16:48:53 +0100
    Subject: [PATCH] fix: allow for TestBody to be public, see #4104
    
    ---
     googletest/include/gtest/internal/gtest-internal.h | 7 ++++++-
     1 file changed, 6 insertions(+), 1 deletion(-)
    
    diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h
    index e9c2441a..b8920176 100644
    --- a/googletest/include/gtest/internal/gtest-internal.h
    +++ b/googletest/include/gtest/internal/gtest-internal.h
    @@ -94,6 +94,10 @@
     #define GTEST_STRINGIFY_HELPER_(name, ...) #name
     #define GTEST_STRINGIFY_(...) GTEST_STRINGIFY_HELPER_(__VA_ARGS__, )
     
    +#ifndef GTEST_TESTBODY_VISIBILITY
    +  #define GTEST_TESTBODY_VISIBILITY private
    +#endif
    +
     namespace proto2 {
     class MessageLite;
     }
    @@ -1549,8 +1553,9 @@ class NeverThrown {
             GTEST_TEST_CLASS_NAME_(test_suite_name,                                \
                                    test_name) &&) noexcept = delete; /* NOLINT */  \
                                                                                    \
    -   private:                                                                    \
    +   GTEST_TESTBODY_VISIBILITY:                                                  \
         void TestBody() override;                                                  \
    +   private:                                                                    \
         static ::testing::TestInfo* const test_info_ GTEST_ATTRIBUTE_UNUSED_;      \
       };                                                                           \
                                                                                    \
    -- 
    2.34.1
    
    
Related tags
xtest is a C++ testing framework inspired by googletest.
xtest is a C++ testing framework inspired by googletest.

xtest C++ testing framework inspired by googletest Explore the docs » Wiki · Report Bug · Request Feature Contents xtest Commence Prerequisites Ubuntu

Dec 13, 2022
Header only C++14 mocking framework
Header only C++14 mocking framework

Trompeloeil Get: trompe l'oeil noun (Concise Encyclopedia) Style of representation in which a painted object is intended to deceive the viewer into be

Dec 29, 2022
C++ Unit Testing Easier: A Header-only C++ unit testing framework

CUTE C++ Unit Testing Easier: A Header-only C++ unit testing framework usually available as part of the Cevelop C++ IDE (http://cevelop.com) Dependenc

Dec 26, 2022
The C Unit Testing Library on GitHub is a library designed for easy unit testing in C

The C Unit Testing Library on GitHub is a library designed for easy unit testing in C. It was written by Brennan Hurst for the purpose of providing a J-Unit-like testing framework within C for personal projects.

Oct 11, 2021
Modern c++17 unit testing framework on Microsoft Windows, Apple macOS, Linux, iOS and android.
Modern c++17 unit testing framework on Microsoft Windows, Apple macOS, Linux, iOS and android.

tunit Modern c++17 unit testing framework on Windows, macOS, Linux, iOS and android. Continuous Integration build status Operating system Status Windo

Apr 5, 2022
The fastest feature-rich C++11/14/17/20 single-header testing framework
The fastest feature-rich C++11/14/17/20 single-header testing framework

master branch Windows All dev branch Windows All doctest is a new C++ testing framework but is by far the fastest both in compile times (by orders of

Jan 4, 2023
C++ xUnit-like testing framework without macros

tst C++ testing framework. Installation, documentation, tutorials See WiKi. Features xUnit-like concepts minimal use of preprocessor macros declarativ

Sep 26, 2022
c++ testing framework

iutest iutest - iris unit test framework Welcome to the iutest iutest is framework for writing C++ tests. Features An XUnit test framework. Header onl

Sep 12, 2022
UT: C++20 μ(micro)/Unit Testing Framework
UT: C++20 μ(micro)/Unit Testing Framework

"If you liked it then you "should have put a"_test on it", Beyonce rule UT / μt | Motivation | Quick Start | Overview | Tutorial | Examples | User Gui

Jan 3, 2023
A complete unit testing framework in a header

liblittletest A complete unit testing framework in a header liblittletest is an easy to use all-in-an-header testing framework; all you have to do in

Nov 11, 2021
Simple C testing framework

MrTest Simple C testing framework Usage Copy the mrtest.c and mrtest.h file into your project. In order to use the mrtest main: create a .c file that

Jul 20, 2022
A minimal testing framework for C/C++
A minimal testing framework for C/C++

mtest About mtest is a minimal testing framework for C++. Requirements Windows or UNIX-like host A compiler supporting C++11 Usage To include mtest in

Jan 10, 2022
Kernel-mode C++ unit testing framework in BDD-style

There is a lack of unit testing frameworks that work in OS kernel. This library closes that gap and is targeted for windows driver developers.

Dec 28, 2022
The fastest feature-rich C++11/14/17/20 single-header testing framework
The fastest feature-rich C++11/14/17/20 single-header testing framework

master branch dev branch doctest is a new C++ testing framework but is by far the fastest both in compile times (by orders of magnitude) and runtime c

Jan 5, 2023
C++ Testing using spies and fakes for isolation and simulation
C++ Testing using spies and fakes for isolation and simulation

ELFspy is a library for linux for writing tests using fakes and spies in C++. For very large call graphs, the testing of the higher nodes can be diffi

Dec 9, 2022
Practical mutation testing tool for C and C++

Mull Mull is a tool for Mutation Testing based on LLVM/Clang with a strong focus on C and C++ languages. For installation and usage please refer to th

Dec 30, 2022
testing joystick under Linux environment, support monitoring disconnection state and auto recovery mode

qjoystick This qjoystick class is rewritten based on the library: https://github.com/drewnoakes/joystick. Please look at this library if you want to s

Oct 30, 2021
Header-only C++11 library for property-based testing.

autocheck Header-only C++11 library for QuickCheck (and later, SmallCheck) testing. Please consult the wiki for documentation. Install conan remote ad

Dec 22, 2022
proftest is a C application for testing the quality of different operating system APIs for profiling.

proftest is a C application for testing the quality of different operating system APIs for profiling.

Jul 23, 2021