Skip to content

Commit 2a2f125

Browse files
Include skipped message when using GTEST_SKIP macro (#70)
Co-authored-by: Bruno Oliveira <[email protected]>
1 parent 10fca5c commit 2a2f125

23 files changed

+231
-229
lines changed

.github/workflows/main.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
strategy:
1111
fail-fast: false
1212
matrix:
13-
gtest_ver: [ "1.8.0" ]
13+
gtest_ver: [ "1.11.0" ]
1414

1515
steps:
1616
- uses: actions/checkout@v1
@@ -22,8 +22,10 @@ jobs:
2222
run: |
2323
wget https://github.com/google/googletest/archive/release-${{ matrix.gtest_ver }}.tar.gz
2424
tar -zxvf release-${{ matrix.gtest_ver }}.tar.gz
25-
cd googletest-release-${{ matrix.gtest_ver }}/googletest
26-
cmake .
25+
cd googletest-release-${{ matrix.gtest_ver }}
26+
mkdir build
27+
cd build
28+
cmake ..
2729
sudo make install
2830
- name: Install Boost.Test
2931
run: |

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 2.1.0
2+
3+
- Added support for `GTEST_SKIP()` skipped message from Google Test 1.11.
4+
15
# 2.0.0
26

37
- `pytest-cpp` now supports [Catch2](https://github.com/catchorg/Catch2). Many thanks to [@salim-runsafe](https://github.com/salim-runsafe) for the contribution.

src/pytest_cpp/google.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def run_test(self, executable, test_id, test_args=(), harness=None):
9898
if failures:
9999
return [GoogleTestFailure(x) for x in failures], output
100100
elif skipped:
101-
pytest.skip()
101+
pytest.skip("\n".join(skipped))
102102
else:
103103
return None, output
104104

@@ -121,11 +121,21 @@ def _parse_xml(self, xml_filename):
121121
failure_elements = test_case.findall("failure")
122122
for failure_elem in failure_elements:
123123
failures.append(failure_elem.text)
124-
skipped = (
125-
test_case.attrib["status"] == "notrun"
126-
or test_case.attrib.get("result", None) == "skipped"
127-
)
128-
result.append((test_suite_name + "." + test_name, failures, skipped))
124+
skippeds = []
125+
if test_case.attrib["result"] == "skipped":
126+
# In gtest 1.11 a skipped message was added to
127+
# the output file
128+
skipped_elements = test_case.findall("skipped")
129+
for skipped_elem in skipped_elements:
130+
skippeds.append(skipped_elem.text)
131+
# In gtest 1.10 the skipped message is not dump,
132+
# so if no skipped message was found just
133+
# append a "skipped" keyword
134+
if not skipped_elements:
135+
skippeds.append("Skipped")
136+
if test_case.attrib["status"] == "notrun":
137+
skippeds.append("Disabled")
138+
result.append((test_suite_name + "." + test_name, failures, skippeds))
129139

130140
return result
131141

tests/acceptance/googletest-samples/prime_tables.h

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,15 @@
2626
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2727
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2828
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29-
//
30-
// Author: [email protected] (Zhanyong Wan)
31-
// Author: [email protected] (Vlad Losev)
29+
30+
3231

3332
// This provides interface PrimeTable that determines whether a number is a
3433
// prime and determines a next prime number. This interface is used
3534
// in Google Test samples demonstrating use of parameterized tests.
3635

37-
#ifndef GTEST_SAMPLES_PRIME_TABLES_H_
38-
#define GTEST_SAMPLES_PRIME_TABLES_H_
36+
#ifndef GOOGLETEST_SAMPLES_PRIME_TABLES_H_
37+
#define GOOGLETEST_SAMPLES_PRIME_TABLES_H_
3938

4039
#include <algorithm>
4140

@@ -44,7 +43,7 @@ class PrimeTable {
4443
public:
4544
virtual ~PrimeTable() {}
4645

47-
// Returns true iff n is a prime number.
46+
// Returns true if and only if n is a prime number.
4847
virtual bool IsPrime(int n) const = 0;
4948

5049
// Returns the smallest prime number greater than p; or returns -1
@@ -55,7 +54,7 @@ class PrimeTable {
5554
// Implementation #1 calculates the primes on-the-fly.
5655
class OnTheFlyPrimeTable : public PrimeTable {
5756
public:
58-
virtual bool IsPrime(int n) const {
57+
bool IsPrime(int n) const override {
5958
if (n <= 1) return false;
6059

6160
for (int i = 2; i*i <= n; i++) {
@@ -66,12 +65,12 @@ class OnTheFlyPrimeTable : public PrimeTable {
6665
return true;
6766
}
6867

69-
virtual int GetNextPrime(int p) const {
70-
for (int n = p + 1; n > 0; n++) {
68+
int GetNextPrime(int p) const override {
69+
if (p < 0) return -1;
70+
71+
for (int n = p + 1;; n++) {
7172
if (IsPrime(n)) return n;
7273
}
73-
74-
return -1;
7574
}
7675
};
7776

@@ -84,13 +83,13 @@ class PreCalculatedPrimeTable : public PrimeTable {
8483
: is_prime_size_(max + 1), is_prime_(new bool[max + 1]) {
8584
CalculatePrimesUpTo(max);
8685
}
87-
virtual ~PreCalculatedPrimeTable() { delete[] is_prime_; }
86+
~PreCalculatedPrimeTable() override { delete[] is_prime_; }
8887

89-
virtual bool IsPrime(int n) const {
88+
bool IsPrime(int n) const override {
9089
return 0 <= n && n < is_prime_size_ && is_prime_[n];
9190
}
9291

93-
virtual int GetNextPrime(int p) const {
92+
int GetNextPrime(int p) const override {
9493
for (int n = p + 1; n < is_prime_size_; n++) {
9594
if (is_prime_[n]) return n;
9695
}
@@ -103,11 +102,15 @@ class PreCalculatedPrimeTable : public PrimeTable {
103102
::std::fill(is_prime_, is_prime_ + is_prime_size_, true);
104103
is_prime_[0] = is_prime_[1] = false;
105104

106-
for (int i = 2; i <= max; i++) {
105+
// Checks every candidate for prime number (we know that 2 is the only even
106+
// prime).
107+
for (int i = 2; i*i <= max; i += i%2+1) {
107108
if (!is_prime_[i]) continue;
108109

109110
// Marks all multiples of i (except i itself) as non-prime.
110-
for (int j = 2*i; j <= max; j += i) {
111+
// We are starting here from i-th multiplier, because all smaller
112+
// complex numbers were already marked.
113+
for (int j = i*i; j <= max; j += i) {
111114
is_prime_[j] = false;
112115
}
113116
}
@@ -120,4 +123,4 @@ class PreCalculatedPrimeTable : public PrimeTable {
120123
void operator=(const PreCalculatedPrimeTable& rhs);
121124
};
122125

123-
#endif // GTEST_SAMPLES_PRIME_TABLES_H_
126+
#endif // GOOGLETEST_SAMPLES_PRIME_TABLES_H_

tests/acceptance/googletest-samples/sample1.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929

3030
// A sample program demonstrating using Google C++ testing framework.
31-
//
32-
// Author: [email protected] (Zhanyong Wan)
3331

3432
#include "sample1.h"
3533

@@ -43,7 +41,7 @@ int Factorial(int n) {
4341
return result;
4442
}
4543

46-
// Returns true iff n is a prime number.
44+
// Returns true if and only if n is a prime number.
4745
bool IsPrime(int n) {
4846
// Trivial case 1: small numbers
4947
if (n <= 1) return false;
@@ -55,7 +53,7 @@ bool IsPrime(int n) {
5553

5654
// Try to divide n by every odd number i, starting from 3
5755
for (int i = 3; ; i += 2) {
58-
// We only have to try i up to the squre root of n
56+
// We only have to try i up to the square root of n
5957
if (i > n/i) break;
6058

6159
// Now, we have i <= n/i < n.

tests/acceptance/googletest-samples/sample1.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,14 @@
2828
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929

3030
// A sample program demonstrating using Google C++ testing framework.
31-
//
32-
// Author: [email protected] (Zhanyong Wan)
3331

34-
#ifndef GTEST_SAMPLES_SAMPLE1_H_
35-
#define GTEST_SAMPLES_SAMPLE1_H_
32+
#ifndef GOOGLETEST_SAMPLES_SAMPLE1_H_
33+
#define GOOGLETEST_SAMPLES_SAMPLE1_H_
3634

3735
// Returns n! (the factorial of n). For negative n, n! is defined to be 1.
3836
int Factorial(int n);
3937

40-
// Returns true iff n is a prime number.
38+
// Returns true if and only if n is a prime number.
4139
bool IsPrime(int n);
4240

43-
#endif // GTEST_SAMPLES_SAMPLE1_H_
41+
#endif // GOOGLETEST_SAMPLES_SAMPLE1_H_

tests/acceptance/googletest-samples/sample10_unittest.cc

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2626
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2727
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28-
//
29-
// Author: [email protected] (Vlad Losev)
28+
3029

3130
// This sample shows how to use Google Test listener API to implement
3231
// a primitive leak checker.
@@ -35,18 +34,15 @@
3534
#include <stdlib.h>
3635

3736
#include "gtest/gtest.h"
38-
3937
using ::testing::EmptyTestEventListener;
4038
using ::testing::InitGoogleTest;
4139
using ::testing::Test;
42-
using ::testing::TestCase;
4340
using ::testing::TestEventListeners;
4441
using ::testing::TestInfo;
4542
using ::testing::TestPartResult;
4643
using ::testing::UnitTest;
4744

4845
namespace {
49-
5046
// We will track memory used by this class.
5147
class Water {
5248
public:
@@ -78,12 +74,12 @@ int Water::allocated_ = 0;
7874
class LeakChecker : public EmptyTestEventListener {
7975
private:
8076
// Called before a test starts.
81-
virtual void OnTestStart(const TestInfo& /* test_info */) {
77+
void OnTestStart(const TestInfo& /* test_info */) override {
8278
initially_allocated_ = Water::allocated();
8379
}
8480

8581
// Called after a test ends.
86-
virtual void OnTestEnd(const TestInfo& /* test_info */) {
82+
void OnTestEnd(const TestInfo& /* test_info */) override {
8783
int difference = Water::allocated() - initially_allocated_;
8884

8985
// You can generate a failure in any event handler except
@@ -104,9 +100,8 @@ TEST(ListenersTest, DoesNotLeak) {
104100
// specified.
105101
TEST(ListenersTest, LeaksWater) {
106102
Water* water = new Water;
107-
EXPECT_TRUE(water != NULL);
103+
EXPECT_TRUE(water != nullptr);
108104
}
109-
110105
} // namespace
111106

112107
int main(int argc, char **argv) {

tests/acceptance/googletest-samples/sample1_unittest.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@
2828
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929

3030
// A sample program demonstrating using Google C++ testing framework.
31-
//
32-
// Author: [email protected] (Zhanyong Wan)
33-
3431

3532
// This sample shows how to write a simple unit test for a function,
3633
// using Google C++ testing framework.
@@ -46,7 +43,7 @@
4643
#include <limits.h>
4744
#include "sample1.h"
4845
#include "gtest/gtest.h"
49-
46+
namespace {
5047

5148
// Step 2. Use the TEST macro to define your tests.
5249
//
@@ -139,6 +136,7 @@ TEST(IsPrimeTest, Positive) {
139136
EXPECT_FALSE(IsPrime(6));
140137
EXPECT_TRUE(IsPrime(23));
141138
}
139+
} // namespace
142140

143141
// Step 3. Call RUN_ALL_TESTS() in main().
144142
//

tests/acceptance/googletest-samples/sample2.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,14 @@
2828
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929

3030
// A sample program demonstrating using Google C++ testing framework.
31-
//
32-
// Author: [email protected] (Zhanyong Wan)
3331

3432
#include "sample2.h"
3533

3634
#include <string.h>
3735

3836
// Clones a 0-terminated C string, allocating memory using new.
3937
const char* MyString::CloneCString(const char* a_c_string) {
40-
if (a_c_string == NULL) return NULL;
38+
if (a_c_string == nullptr) return nullptr;
4139

4240
const size_t len = strlen(a_c_string);
4341
char* const clone = new char[ len + 1 ];

tests/acceptance/googletest-samples/sample2.h

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,9 @@
2828
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929

3030
// A sample program demonstrating using Google C++ testing framework.
31-
//
32-
// Author: [email protected] (Zhanyong Wan)
3331

34-
#ifndef GTEST_SAMPLES_SAMPLE2_H_
35-
#define GTEST_SAMPLES_SAMPLE2_H_
32+
#ifndef GOOGLETEST_SAMPLES_SAMPLE2_H_
33+
#define GOOGLETEST_SAMPLES_SAMPLE2_H_
3634

3735
#include <string.h>
3836

@@ -52,15 +50,15 @@ class MyString {
5250
// C'tors
5351

5452
// The default c'tor constructs a NULL string.
55-
MyString() : c_string_(NULL) {}
53+
MyString() : c_string_(nullptr) {}
5654

5755
// Constructs a MyString by cloning a 0-terminated C string.
58-
explicit MyString(const char* a_c_string) : c_string_(NULL) {
56+
explicit MyString(const char* a_c_string) : c_string_(nullptr) {
5957
Set(a_c_string);
6058
}
6159

6260
// Copy c'tor
63-
MyString(const MyString& string) : c_string_(NULL) {
61+
MyString(const MyString& string) : c_string_(nullptr) {
6462
Set(string.c_string_);
6563
}
6664

@@ -73,13 +71,10 @@ class MyString {
7371
// Gets the 0-terminated C string this MyString object represents.
7472
const char* c_string() const { return c_string_; }
7573

76-
size_t Length() const {
77-
return c_string_ == NULL ? 0 : strlen(c_string_);
78-
}
74+
size_t Length() const { return c_string_ == nullptr ? 0 : strlen(c_string_); }
7975

8076
// Sets the 0-terminated C string this MyString object represents.
8177
void Set(const char* c_string);
8278
};
8379

84-
85-
#endif // GTEST_SAMPLES_SAMPLE2_H_
80+
#endif // GOOGLETEST_SAMPLES_SAMPLE2_H_

0 commit comments

Comments
 (0)