Merge pull request #1191 from gennadiycivil/master
Adding Bazel build to googletest (initial version )
This commit is contained in:
		
							
								
								
									
										7
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										7
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -1,3 +1,10 @@
 | 
				
			|||||||
# Ignore CI build directory
 | 
					# Ignore CI build directory
 | 
				
			||||||
build/
 | 
					build/
 | 
				
			||||||
xcuserdata
 | 
					xcuserdata
 | 
				
			||||||
 | 
					cmake-build-debug/
 | 
				
			||||||
 | 
					.idea/
 | 
				
			||||||
 | 
					bazel-bin
 | 
				
			||||||
 | 
					bazel-genfiles
 | 
				
			||||||
 | 
					bazel-googletest
 | 
				
			||||||
 | 
					bazel-out
 | 
				
			||||||
 | 
					bazel-testlogs
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										147
									
								
								BUILD.bazel
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										147
									
								
								BUILD.bazel
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,147 @@
 | 
				
			|||||||
 | 
					# Copyright 2017 Google Inc. 
 | 
				
			||||||
 | 
					# All Rights Reserved.
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# Redistribution and use in source and binary forms, with or without
 | 
				
			||||||
 | 
					# modification, are permitted provided that the following conditions are
 | 
				
			||||||
 | 
					# met:
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					#     * Redistributions of source code must retain the above copyright
 | 
				
			||||||
 | 
					# notice, this list of conditions and the following disclaimer.
 | 
				
			||||||
 | 
					#     * Redistributions in binary form must reproduce the above
 | 
				
			||||||
 | 
					# copyright notice, this list of conditions and the following disclaimer
 | 
				
			||||||
 | 
					# in the documentation and/or other materials provided with the
 | 
				
			||||||
 | 
					# distribution.
 | 
				
			||||||
 | 
					#     * Neither the name of Google Inc. nor the names of its
 | 
				
			||||||
 | 
					# contributors may be used to endorse or promote products derived from
 | 
				
			||||||
 | 
					# this software without specific prior written permission.
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 | 
				
			||||||
 | 
					# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 | 
				
			||||||
 | 
					# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 | 
				
			||||||
 | 
					# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 | 
				
			||||||
 | 
					# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 | 
				
			||||||
 | 
					# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 | 
				
			||||||
 | 
					# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 | 
				
			||||||
 | 
					# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 | 
				
			||||||
 | 
					# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 | 
				
			||||||
 | 
					# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 | 
				
			||||||
 | 
					# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# Author: misterg@google.com (Gennadiy Civil)
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					#   Bazel Build for Google C++ Testing Framework(Google Test)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					package(default_visibility = ["//visibility:public"])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					licenses(["notice"])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					config_setting(
 | 
				
			||||||
 | 
					    name = "win",
 | 
				
			||||||
 | 
					    values = {"cpu": "x64_windows_msvc"},
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Google Test including Google Mock 
 | 
				
			||||||
 | 
					cc_library(
 | 
				
			||||||
 | 
					    name = "gtest",
 | 
				
			||||||
 | 
					    srcs = glob(
 | 
				
			||||||
 | 
					        include = [
 | 
				
			||||||
 | 
					            "googletest/src/*.cc",
 | 
				
			||||||
 | 
					            "googletest/src/*.h",
 | 
				
			||||||
 | 
					            "googletest/include/gtest/**/*.h",
 | 
				
			||||||
 | 
					            "googlemock/src/*.cc",
 | 
				
			||||||
 | 
					            "googlemock/include/gmock/**/*.h",
 | 
				
			||||||
 | 
					        ],
 | 
				
			||||||
 | 
					        exclude = [
 | 
				
			||||||
 | 
					            "googletest/src/gtest-all.cc",
 | 
				
			||||||
 | 
					            "googletest/src/gtest_main.cc",
 | 
				
			||||||
 | 
					            "googlemock/src/gmock-all.cc",
 | 
				
			||||||
 | 
					            "googlemock/src/gmock_main.cc",
 | 
				
			||||||
 | 
					        ],
 | 
				
			||||||
 | 
					    ),
 | 
				
			||||||
 | 
					    hdrs =glob([
 | 
				
			||||||
 | 
					        "googletest/include/gtest/*.h",
 | 
				
			||||||
 | 
					        "googlemock/include/gmock/*.h",
 | 
				
			||||||
 | 
					    ]),
 | 
				
			||||||
 | 
					    copts = select(
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            ":win": [],
 | 
				
			||||||
 | 
					            "//conditions:default": ["-pthread"],
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					    ),
 | 
				
			||||||
 | 
					    includes = [
 | 
				
			||||||
 | 
					        "googlemock",
 | 
				
			||||||
 | 
					        "googlemock/include",
 | 
				
			||||||
 | 
					        "googletest",
 | 
				
			||||||
 | 
					        "googletest/include",
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
 | 
					    linkopts = select({
 | 
				
			||||||
 | 
					        ":win": [],
 | 
				
			||||||
 | 
					        "//conditions:default": [
 | 
				
			||||||
 | 
					            "-pthread",
 | 
				
			||||||
 | 
					        ],
 | 
				
			||||||
 | 
					    }),
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					cc_library(
 | 
				
			||||||
 | 
					    name = "gtest_main",
 | 
				
			||||||
 | 
					    srcs = [
 | 
				
			||||||
 | 
					        "googlemock/src/gmock_main.cc",
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
 | 
					    deps = ["//:gtest"],
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# The following rules build samples of how to use gTest.
 | 
				
			||||||
 | 
					cc_library(
 | 
				
			||||||
 | 
					    name = "gtest_sample_lib",
 | 
				
			||||||
 | 
					    srcs = [
 | 
				
			||||||
 | 
					        "googletest/samples/sample1.cc",
 | 
				
			||||||
 | 
					        "googletest/samples/sample2.cc",
 | 
				
			||||||
 | 
					        "googletest/samples/sample4.cc",
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
 | 
					    hdrs = [
 | 
				
			||||||
 | 
					        "googletest/samples/prime_tables.h",
 | 
				
			||||||
 | 
					        "googletest/samples/sample1.h",
 | 
				
			||||||
 | 
					        "googletest/samples/sample2.h",
 | 
				
			||||||
 | 
					        "googletest/samples/sample3-inl.h",
 | 
				
			||||||
 | 
					        "googletest/samples/sample4.h",
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					cc_test(
 | 
				
			||||||
 | 
					    name = "gtest_samples",
 | 
				
			||||||
 | 
					    size = "small",
 | 
				
			||||||
 | 
					    #All Samples except:
 | 
				
			||||||
 | 
					    #sample9 ( main )
 | 
				
			||||||
 | 
					    #sample10 (main and takes a command line option and needs to be separate)
 | 
				
			||||||
 | 
					    srcs = [
 | 
				
			||||||
 | 
					        "googletest/samples/sample1_unittest.cc",
 | 
				
			||||||
 | 
					        "googletest/samples/sample2_unittest.cc",
 | 
				
			||||||
 | 
					        "googletest/samples/sample3_unittest.cc",
 | 
				
			||||||
 | 
					        "googletest/samples/sample4_unittest.cc",
 | 
				
			||||||
 | 
					        "googletest/samples/sample5_unittest.cc",
 | 
				
			||||||
 | 
					        "googletest/samples/sample6_unittest.cc",
 | 
				
			||||||
 | 
					        "googletest/samples/sample7_unittest.cc",
 | 
				
			||||||
 | 
					        "googletest/samples/sample8_unittest.cc",
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
 | 
					    deps = [
 | 
				
			||||||
 | 
					        "gtest_sample_lib",
 | 
				
			||||||
 | 
					        ":gtest_main",
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					cc_test(
 | 
				
			||||||
 | 
					    name = "sample9_unittest",
 | 
				
			||||||
 | 
					    size = "small",
 | 
				
			||||||
 | 
					    srcs = ["googletest/samples/sample9_unittest.cc"],
 | 
				
			||||||
 | 
					    deps = [":gtest"],
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					cc_test(
 | 
				
			||||||
 | 
					    name = "sample10_unittest",
 | 
				
			||||||
 | 
					    size = "small",
 | 
				
			||||||
 | 
					    srcs = ["googletest/samples/sample10_unittest.cc"],
 | 
				
			||||||
 | 
					    deps = [
 | 
				
			||||||
 | 
					        ":gtest",
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
							
								
								
									
										52
									
								
								googlemock/test/BUILD.bazel
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								googlemock/test/BUILD.bazel
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,52 @@
 | 
				
			|||||||
 | 
					# Copyright 2017 Google Inc. 
 | 
				
			||||||
 | 
					# All Rights Reserved.
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# Redistribution and use in source and binary forms, with or without
 | 
				
			||||||
 | 
					# modification, are permitted provided that the following conditions are
 | 
				
			||||||
 | 
					# met:
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					#     * Redistributions of source code must retain the above copyright
 | 
				
			||||||
 | 
					# notice, this list of conditions and the following disclaimer.
 | 
				
			||||||
 | 
					#     * Redistributions in binary form must reproduce the above
 | 
				
			||||||
 | 
					# copyright notice, this list of conditions and the following disclaimer
 | 
				
			||||||
 | 
					# in the documentation and/or other materials provided with the
 | 
				
			||||||
 | 
					# distribution.
 | 
				
			||||||
 | 
					#     * Neither the name of Google Inc. nor the names of its
 | 
				
			||||||
 | 
					# contributors may be used to endorse or promote products derived from
 | 
				
			||||||
 | 
					# this software without specific prior written permission.
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 | 
				
			||||||
 | 
					# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 | 
				
			||||||
 | 
					# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 | 
				
			||||||
 | 
					# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 | 
				
			||||||
 | 
					# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 | 
				
			||||||
 | 
					# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 | 
				
			||||||
 | 
					# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 | 
				
			||||||
 | 
					# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 | 
				
			||||||
 | 
					# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 | 
				
			||||||
 | 
					# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 | 
				
			||||||
 | 
					# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# Author: misterg@google.com (Gennadiy Civil)
 | 
				
			||||||
 | 
					#   
 | 
				
			||||||
 | 
					#   Bazel Build for Google C++ Testing Framework(Google Test)-googlemock
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					""" gmock own tests """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					cc_test(
 | 
				
			||||||
 | 
					    name = "gmock_all_test",
 | 
				
			||||||
 | 
					    size = "small",
 | 
				
			||||||
 | 
					    srcs = glob(
 | 
				
			||||||
 | 
					        include = [
 | 
				
			||||||
 | 
					            "gmock-*.cc",
 | 
				
			||||||
 | 
					        ],
 | 
				
			||||||
 | 
					    ),
 | 
				
			||||||
 | 
					    linkopts = select({
 | 
				
			||||||
 | 
					        "//:win": [],
 | 
				
			||||||
 | 
					        "//conditions:default": [
 | 
				
			||||||
 | 
					            "-pthread",
 | 
				
			||||||
 | 
					        ],
 | 
				
			||||||
 | 
					    }),
 | 
				
			||||||
 | 
					    deps = ["//:gtest"],
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
@@ -35,7 +35,6 @@
 | 
				
			|||||||
#include <stdlib.h>
 | 
					#include <stdlib.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "gtest/gtest.h"
 | 
					#include "gtest/gtest.h"
 | 
				
			||||||
 | 
					 | 
				
			||||||
using ::testing::EmptyTestEventListener;
 | 
					using ::testing::EmptyTestEventListener;
 | 
				
			||||||
using ::testing::InitGoogleTest;
 | 
					using ::testing::InitGoogleTest;
 | 
				
			||||||
using ::testing::Test;
 | 
					using ::testing::Test;
 | 
				
			||||||
@@ -46,7 +45,6 @@ using ::testing::TestPartResult;
 | 
				
			|||||||
using ::testing::UnitTest;
 | 
					using ::testing::UnitTest;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace {
 | 
					namespace {
 | 
				
			||||||
 | 
					 | 
				
			||||||
// We will track memory used by this class.
 | 
					// We will track memory used by this class.
 | 
				
			||||||
class Water {
 | 
					class Water {
 | 
				
			||||||
 public:
 | 
					 public:
 | 
				
			||||||
@@ -106,7 +104,6 @@ TEST(ListenersTest, LeaksWater) {
 | 
				
			|||||||
  Water* water = new Water;
 | 
					  Water* water = new Water;
 | 
				
			||||||
  EXPECT_TRUE(water != NULL);
 | 
					  EXPECT_TRUE(water != NULL);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
}  // namespace
 | 
					}  // namespace
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int main(int argc, char **argv) {
 | 
					int main(int argc, char **argv) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -46,7 +46,7 @@
 | 
				
			|||||||
#include <limits.h>
 | 
					#include <limits.h>
 | 
				
			||||||
#include "sample1.h"
 | 
					#include "sample1.h"
 | 
				
			||||||
#include "gtest/gtest.h"
 | 
					#include "gtest/gtest.h"
 | 
				
			||||||
 | 
					namespace {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Step 2. Use the TEST macro to define your tests.
 | 
					// Step 2. Use the TEST macro to define your tests.
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
@@ -139,6 +139,7 @@ TEST(IsPrimeTest, Positive) {
 | 
				
			|||||||
  EXPECT_FALSE(IsPrime(6));
 | 
					  EXPECT_FALSE(IsPrime(6));
 | 
				
			||||||
  EXPECT_TRUE(IsPrime(23));
 | 
					  EXPECT_TRUE(IsPrime(23));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					}  // namespace
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Step 3. Call RUN_ALL_TESTS() in main().
 | 
					// Step 3. Call RUN_ALL_TESTS() in main().
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -42,7 +42,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include "sample2.h"
 | 
					#include "sample2.h"
 | 
				
			||||||
#include "gtest/gtest.h"
 | 
					#include "gtest/gtest.h"
 | 
				
			||||||
 | 
					namespace {
 | 
				
			||||||
// In this example, we test the MyString class (a simple string).
 | 
					// In this example, we test the MyString class (a simple string).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Tests the default c'tor.
 | 
					// Tests the default c'tor.
 | 
				
			||||||
@@ -107,3 +107,4 @@ TEST(MyString, Set) {
 | 
				
			|||||||
  s.Set(NULL);
 | 
					  s.Set(NULL);
 | 
				
			||||||
  EXPECT_STREQ(NULL, s.c_string());
 | 
					  EXPECT_STREQ(NULL, s.c_string());
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					}  // namespace
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -65,9 +65,9 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include "sample3-inl.h"
 | 
					#include "sample3-inl.h"
 | 
				
			||||||
#include "gtest/gtest.h"
 | 
					#include "gtest/gtest.h"
 | 
				
			||||||
 | 
					namespace {
 | 
				
			||||||
// To use a test fixture, derive a class from testing::Test.
 | 
					// To use a test fixture, derive a class from testing::Test.
 | 
				
			||||||
class QueueTest : public testing::Test {
 | 
					class QueueTestSmpl3 : public testing::Test {
 | 
				
			||||||
 protected:  // You should make the members protected s.t. they can be
 | 
					 protected:  // You should make the members protected s.t. they can be
 | 
				
			||||||
             // accessed from sub-classes.
 | 
					             // accessed from sub-classes.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -120,13 +120,13 @@ class QueueTest : public testing::Test {
 | 
				
			|||||||
// instead of TEST.
 | 
					// instead of TEST.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Tests the default c'tor.
 | 
					// Tests the default c'tor.
 | 
				
			||||||
TEST_F(QueueTest, DefaultConstructor) {
 | 
					TEST_F(QueueTestSmpl3, DefaultConstructor) {
 | 
				
			||||||
  // You can access data in the test fixture here.
 | 
					  // You can access data in the test fixture here.
 | 
				
			||||||
  EXPECT_EQ(0u, q0_.Size());
 | 
					  EXPECT_EQ(0u, q0_.Size());
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Tests Dequeue().
 | 
					// Tests Dequeue().
 | 
				
			||||||
TEST_F(QueueTest, Dequeue) {
 | 
					TEST_F(QueueTestSmpl3, Dequeue) {
 | 
				
			||||||
  int * n = q0_.Dequeue();
 | 
					  int * n = q0_.Dequeue();
 | 
				
			||||||
  EXPECT_TRUE(n == NULL);
 | 
					  EXPECT_TRUE(n == NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -144,8 +144,9 @@ TEST_F(QueueTest, Dequeue) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Tests the Queue::Map() function.
 | 
					// Tests the Queue::Map() function.
 | 
				
			||||||
TEST_F(QueueTest, Map) {
 | 
					TEST_F(QueueTestSmpl3, Map) {
 | 
				
			||||||
  MapTester(&q0_);
 | 
					  MapTester(&q0_);
 | 
				
			||||||
  MapTester(&q1_);
 | 
					  MapTester(&q1_);
 | 
				
			||||||
  MapTester(&q2_);
 | 
					  MapTester(&q2_);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					}  // namespace
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -31,7 +31,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include "gtest/gtest.h"
 | 
					#include "gtest/gtest.h"
 | 
				
			||||||
#include "sample4.h"
 | 
					#include "sample4.h"
 | 
				
			||||||
 | 
					namespace {
 | 
				
			||||||
// Tests the Increment() method.
 | 
					// Tests the Increment() method.
 | 
				
			||||||
TEST(Counter, Increment) {
 | 
					TEST(Counter, Increment) {
 | 
				
			||||||
  Counter c;
 | 
					  Counter c;
 | 
				
			||||||
@@ -43,3 +43,4 @@ TEST(Counter, Increment) {
 | 
				
			|||||||
  EXPECT_EQ(1, c.Increment());
 | 
					  EXPECT_EQ(1, c.Increment());
 | 
				
			||||||
  EXPECT_EQ(2, c.Increment());
 | 
					  EXPECT_EQ(2, c.Increment());
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					}  // namespace
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -49,7 +49,7 @@
 | 
				
			|||||||
#include "sample3-inl.h"
 | 
					#include "sample3-inl.h"
 | 
				
			||||||
#include "gtest/gtest.h"
 | 
					#include "gtest/gtest.h"
 | 
				
			||||||
#include "sample1.h"
 | 
					#include "sample1.h"
 | 
				
			||||||
 | 
					namespace {
 | 
				
			||||||
// In this sample, we want to ensure that every test finishes within
 | 
					// In this sample, we want to ensure that every test finishes within
 | 
				
			||||||
// ~5 seconds.  If a test takes longer to run, we consider it a
 | 
					// ~5 seconds.  If a test takes longer to run, we consider it a
 | 
				
			||||||
// failure.
 | 
					// failure.
 | 
				
			||||||
@@ -191,7 +191,7 @@ TEST_F(QueueTest, Dequeue) {
 | 
				
			|||||||
  EXPECT_EQ(1u, q2_.Size());
 | 
					  EXPECT_EQ(1u, q2_.Size());
 | 
				
			||||||
  delete n;
 | 
					  delete n;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					}  // namespace
 | 
				
			||||||
// If necessary, you can derive further test fixtures from a derived
 | 
					// If necessary, you can derive further test fixtures from a derived
 | 
				
			||||||
// fixture itself.  For example, you can derive another fixture from
 | 
					// fixture itself.  For example, you can derive another fixture from
 | 
				
			||||||
// QueueTest.  Google Test imposes no limit on how deep the hierarchy
 | 
					// QueueTest.  Google Test imposes no limit on how deep the hierarchy
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -36,7 +36,7 @@
 | 
				
			|||||||
#include "prime_tables.h"
 | 
					#include "prime_tables.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "gtest/gtest.h"
 | 
					#include "gtest/gtest.h"
 | 
				
			||||||
 | 
					namespace {
 | 
				
			||||||
// First, we define some factory functions for creating instances of
 | 
					// First, we define some factory functions for creating instances of
 | 
				
			||||||
// the implementations.  You may be able to skip this step if all your
 | 
					// the implementations.  You may be able to skip this step if all your
 | 
				
			||||||
// implementations can be constructed the same way.
 | 
					// implementations can be constructed the same way.
 | 
				
			||||||
@@ -222,3 +222,4 @@ INSTANTIATE_TYPED_TEST_CASE_P(OnTheFlyAndPreCalculated,    // Instance name
 | 
				
			|||||||
                              PrimeTableImplementations);  // Type list
 | 
					                              PrimeTableImplementations);  // Type list
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif  // GTEST_HAS_TYPED_TEST_P
 | 
					#endif  // GTEST_HAS_TYPED_TEST_P
 | 
				
			||||||
 | 
					}  // namespace
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -39,7 +39,7 @@
 | 
				
			|||||||
#include "prime_tables.h"
 | 
					#include "prime_tables.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "gtest/gtest.h"
 | 
					#include "gtest/gtest.h"
 | 
				
			||||||
 | 
					namespace {
 | 
				
			||||||
#if GTEST_HAS_PARAM_TEST
 | 
					#if GTEST_HAS_PARAM_TEST
 | 
				
			||||||
 | 
					
 | 
				
			||||||
using ::testing::TestWithParam;
 | 
					using ::testing::TestWithParam;
 | 
				
			||||||
@@ -65,9 +65,9 @@ PrimeTable* CreatePreCalculatedPrimeTable() {
 | 
				
			|||||||
// can refer to the test parameter by GetParam().  In this case, the test
 | 
					// can refer to the test parameter by GetParam().  In this case, the test
 | 
				
			||||||
// parameter is a factory function which we call in fixture's SetUp() to
 | 
					// parameter is a factory function which we call in fixture's SetUp() to
 | 
				
			||||||
// create and store an instance of PrimeTable.
 | 
					// create and store an instance of PrimeTable.
 | 
				
			||||||
class PrimeTableTest : public TestWithParam<CreatePrimeTableFunc*> {
 | 
					class PrimeTableTestSmpl7 : public TestWithParam<CreatePrimeTableFunc*> {
 | 
				
			||||||
 public:
 | 
					 public:
 | 
				
			||||||
  virtual ~PrimeTableTest() { delete table_; }
 | 
					  virtual ~PrimeTableTestSmpl7() { delete table_; }
 | 
				
			||||||
  virtual void SetUp() { table_ = (*GetParam())(); }
 | 
					  virtual void SetUp() { table_ = (*GetParam())(); }
 | 
				
			||||||
  virtual void TearDown() {
 | 
					  virtual void TearDown() {
 | 
				
			||||||
    delete table_;
 | 
					    delete table_;
 | 
				
			||||||
@@ -78,7 +78,7 @@ class PrimeTableTest : public TestWithParam<CreatePrimeTableFunc*> {
 | 
				
			|||||||
  PrimeTable* table_;
 | 
					  PrimeTable* table_;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
TEST_P(PrimeTableTest, ReturnsFalseForNonPrimes) {
 | 
					TEST_P(PrimeTableTestSmpl7, ReturnsFalseForNonPrimes) {
 | 
				
			||||||
  EXPECT_FALSE(table_->IsPrime(-5));
 | 
					  EXPECT_FALSE(table_->IsPrime(-5));
 | 
				
			||||||
  EXPECT_FALSE(table_->IsPrime(0));
 | 
					  EXPECT_FALSE(table_->IsPrime(0));
 | 
				
			||||||
  EXPECT_FALSE(table_->IsPrime(1));
 | 
					  EXPECT_FALSE(table_->IsPrime(1));
 | 
				
			||||||
@@ -87,7 +87,7 @@ TEST_P(PrimeTableTest, ReturnsFalseForNonPrimes) {
 | 
				
			|||||||
  EXPECT_FALSE(table_->IsPrime(100));
 | 
					  EXPECT_FALSE(table_->IsPrime(100));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
TEST_P(PrimeTableTest, ReturnsTrueForPrimes) {
 | 
					TEST_P(PrimeTableTestSmpl7, ReturnsTrueForPrimes) {
 | 
				
			||||||
  EXPECT_TRUE(table_->IsPrime(2));
 | 
					  EXPECT_TRUE(table_->IsPrime(2));
 | 
				
			||||||
  EXPECT_TRUE(table_->IsPrime(3));
 | 
					  EXPECT_TRUE(table_->IsPrime(3));
 | 
				
			||||||
  EXPECT_TRUE(table_->IsPrime(5));
 | 
					  EXPECT_TRUE(table_->IsPrime(5));
 | 
				
			||||||
@@ -96,7 +96,7 @@ TEST_P(PrimeTableTest, ReturnsTrueForPrimes) {
 | 
				
			|||||||
  EXPECT_TRUE(table_->IsPrime(131));
 | 
					  EXPECT_TRUE(table_->IsPrime(131));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
TEST_P(PrimeTableTest, CanGetNextPrime) {
 | 
					TEST_P(PrimeTableTestSmpl7, CanGetNextPrime) {
 | 
				
			||||||
  EXPECT_EQ(2, table_->GetNextPrime(0));
 | 
					  EXPECT_EQ(2, table_->GetNextPrime(0));
 | 
				
			||||||
  EXPECT_EQ(3, table_->GetNextPrime(2));
 | 
					  EXPECT_EQ(3, table_->GetNextPrime(2));
 | 
				
			||||||
  EXPECT_EQ(5, table_->GetNextPrime(3));
 | 
					  EXPECT_EQ(5, table_->GetNextPrime(3));
 | 
				
			||||||
@@ -112,10 +112,9 @@ TEST_P(PrimeTableTest, CanGetNextPrime) {
 | 
				
			|||||||
//
 | 
					//
 | 
				
			||||||
// Here, we instantiate our tests with a list of two PrimeTable object
 | 
					// Here, we instantiate our tests with a list of two PrimeTable object
 | 
				
			||||||
// factory functions:
 | 
					// factory functions:
 | 
				
			||||||
INSTANTIATE_TEST_CASE_P(
 | 
					INSTANTIATE_TEST_CASE_P(OnTheFlyAndPreCalculated, PrimeTableTestSmpl7,
 | 
				
			||||||
    OnTheFlyAndPreCalculated,
 | 
					                        Values(&CreateOnTheFlyPrimeTable,
 | 
				
			||||||
    PrimeTableTest,
 | 
					                               &CreatePreCalculatedPrimeTable<1000>));
 | 
				
			||||||
    Values(&CreateOnTheFlyPrimeTable, &CreatePreCalculatedPrimeTable<1000>));
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -128,3 +127,4 @@ INSTANTIATE_TEST_CASE_P(
 | 
				
			|||||||
TEST(DummyTest, ValueParameterizedTestsAreNotSupportedOnThisPlatform) {}
 | 
					TEST(DummyTest, ValueParameterizedTestsAreNotSupportedOnThisPlatform) {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif  // GTEST_HAS_PARAM_TEST
 | 
					#endif  // GTEST_HAS_PARAM_TEST
 | 
				
			||||||
 | 
					}  // namespace
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -37,7 +37,7 @@
 | 
				
			|||||||
#include "prime_tables.h"
 | 
					#include "prime_tables.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "gtest/gtest.h"
 | 
					#include "gtest/gtest.h"
 | 
				
			||||||
 | 
					namespace {
 | 
				
			||||||
#if GTEST_HAS_COMBINE
 | 
					#if GTEST_HAS_COMBINE
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Suppose we want to introduce a new, improved implementation of PrimeTable
 | 
					// Suppose we want to introduce a new, improved implementation of PrimeTable
 | 
				
			||||||
@@ -171,3 +171,4 @@ INSTANTIATE_TEST_CASE_P(MeaningfulTestParameters,
 | 
				
			|||||||
TEST(DummyTest, CombineIsNotSupportedOnThisPlatform) {}
 | 
					TEST(DummyTest, CombineIsNotSupportedOnThisPlatform) {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif  // GTEST_HAS_COMBINE
 | 
					#endif  // GTEST_HAS_COMBINE
 | 
				
			||||||
 | 
					}  // namespace
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -44,9 +44,7 @@ using ::testing::TestEventListeners;
 | 
				
			|||||||
using ::testing::TestInfo;
 | 
					using ::testing::TestInfo;
 | 
				
			||||||
using ::testing::TestPartResult;
 | 
					using ::testing::TestPartResult;
 | 
				
			||||||
using ::testing::UnitTest;
 | 
					using ::testing::UnitTest;
 | 
				
			||||||
 | 
					 | 
				
			||||||
namespace {
 | 
					namespace {
 | 
				
			||||||
 | 
					 | 
				
			||||||
// Provides alternative output mode which produces minimal amount of
 | 
					// Provides alternative output mode which produces minimal amount of
 | 
				
			||||||
// information about tests.
 | 
					// information about tests.
 | 
				
			||||||
class TersePrinter : public EmptyTestEventListener {
 | 
					class TersePrinter : public EmptyTestEventListener {
 | 
				
			||||||
@@ -102,7 +100,6 @@ TEST(CustomOutputTest, Fails) {
 | 
				
			|||||||
  EXPECT_EQ(1, 2)
 | 
					  EXPECT_EQ(1, 2)
 | 
				
			||||||
      << "This test fails in order to demonstrate alternative failure messages";
 | 
					      << "This test fails in order to demonstrate alternative failure messages";
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
}  // namespace
 | 
					}  // namespace
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int main(int argc, char **argv) {
 | 
					int main(int argc, char **argv) {
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										118
									
								
								googletest/test/BUILD.bazel
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										118
									
								
								googletest/test/BUILD.bazel
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,118 @@
 | 
				
			|||||||
 | 
					# Copyright 2017 Google Inc. 
 | 
				
			||||||
 | 
					# All Rights Reserved.
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# Redistribution and use in source and binary forms, with or without
 | 
				
			||||||
 | 
					# modification, are permitted provided that the following conditions are
 | 
				
			||||||
 | 
					# met:
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					#     * Redistributions of source code must retain the above copyright
 | 
				
			||||||
 | 
					# notice, this list of conditions and the following disclaimer.
 | 
				
			||||||
 | 
					#     * Redistributions in binary form must reproduce the above
 | 
				
			||||||
 | 
					# copyright notice, this list of conditions and the following disclaimer
 | 
				
			||||||
 | 
					# in the documentation and/or other materials provided with the
 | 
				
			||||||
 | 
					# distribution.
 | 
				
			||||||
 | 
					#     * Neither the name of Google Inc. nor the names of its
 | 
				
			||||||
 | 
					# contributors may be used to endorse or promote products derived from
 | 
				
			||||||
 | 
					# this software without specific prior written permission.
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 | 
				
			||||||
 | 
					# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 | 
				
			||||||
 | 
					# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 | 
				
			||||||
 | 
					# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 | 
				
			||||||
 | 
					# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 | 
				
			||||||
 | 
					# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 | 
				
			||||||
 | 
					# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 | 
				
			||||||
 | 
					# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 | 
				
			||||||
 | 
					# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 | 
				
			||||||
 | 
					# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 | 
				
			||||||
 | 
					# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# Author: misterg@google.com (Gennadiy Civil)
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# Bazel BUILD for The Google C++ Testing Framework (Google Test)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					licenses(["notice"])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					""" gtest own tests """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#on windows exclude gtest-tuple.h and gtest-tuple_test.cc
 | 
				
			||||||
 | 
					cc_test(
 | 
				
			||||||
 | 
					    name = "gtest_all_test",
 | 
				
			||||||
 | 
					    size = "small",
 | 
				
			||||||
 | 
					    srcs =  glob(
 | 
				
			||||||
 | 
					                    include = [
 | 
				
			||||||
 | 
					                        "gtest-*.cc",
 | 
				
			||||||
 | 
					                        "*.h",
 | 
				
			||||||
 | 
					                        "googletest/include/gtest/**/*.h",
 | 
				
			||||||
 | 
					                    ],
 | 
				
			||||||
 | 
					                    exclude = [
 | 
				
			||||||
 | 
					                        "gtest-unittest-api_test.cc",
 | 
				
			||||||
 | 
					                        "gtest-tuple_test.cc",
 | 
				
			||||||
 | 
					                        "googletest/src/gtest-all.cc",
 | 
				
			||||||
 | 
					                        "gtest_all_test.cc",
 | 
				
			||||||
 | 
					                        "gtest-death-test_ex_test.cc",
 | 
				
			||||||
 | 
					                        "gtest-listener_test.cc",
 | 
				
			||||||
 | 
					                        "gtest-unittest-api_test.cc",
 | 
				
			||||||
 | 
					                        "gtest-param-test_test.cc",
 | 
				
			||||||
 | 
					                    ],
 | 
				
			||||||
 | 
					                ) + select({
 | 
				
			||||||
 | 
					        "//:win": [],
 | 
				
			||||||
 | 
					        "//conditions:default": [
 | 
				
			||||||
 | 
					            "gtest-tuple_test.cc",
 | 
				
			||||||
 | 
					        ],
 | 
				
			||||||
 | 
					        }),
 | 
				
			||||||
 | 
					    copts = select({
 | 
				
			||||||
 | 
					        "//:win": ["-DGTEST_USE_OWN_TR1_TUPLE=0"],
 | 
				
			||||||
 | 
					        "//conditions:default": ["-DGTEST_USE_OWN_TR1_TUPLE=1"],
 | 
				
			||||||
 | 
					    }),
 | 
				
			||||||
 | 
					    includes = [
 | 
				
			||||||
 | 
					        "googletest",
 | 
				
			||||||
 | 
					        "googletest/include",
 | 
				
			||||||
 | 
					        "googletest/include/internal",
 | 
				
			||||||
 | 
					        "googletest/test",
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
 | 
					    linkopts = select({
 | 
				
			||||||
 | 
					        "//:win": [],
 | 
				
			||||||
 | 
					        "//conditions:default": [
 | 
				
			||||||
 | 
					            "-pthread",
 | 
				
			||||||
 | 
					        ],
 | 
				
			||||||
 | 
					    }),
 | 
				
			||||||
 | 
					    deps = ["//:gtest_main"],
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#These googletest tests have their own main()
 | 
				
			||||||
 | 
					cc_test(
 | 
				
			||||||
 | 
					    name = "gtest-listener_test",
 | 
				
			||||||
 | 
					    size = "small",
 | 
				
			||||||
 | 
					    srcs = [
 | 
				
			||||||
 | 
					        "gtest-listener_test.cc",
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
 | 
					    deps = [
 | 
				
			||||||
 | 
					        "//:gtest",
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					cc_test(
 | 
				
			||||||
 | 
					    name = "gtest-unittest-api_test",
 | 
				
			||||||
 | 
					    size = "small",
 | 
				
			||||||
 | 
					    srcs = [
 | 
				
			||||||
 | 
					        "gtest-unittest-api_test.cc",
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
 | 
					    deps = [
 | 
				
			||||||
 | 
					        "//:gtest",
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					cc_test(
 | 
				
			||||||
 | 
					    name = "gtest-param-test_test",
 | 
				
			||||||
 | 
					    size = "small",
 | 
				
			||||||
 | 
					    srcs = [
 | 
				
			||||||
 | 
					        "gtest-param-test2_test.cc",
 | 
				
			||||||
 | 
					        "gtest-param-test_test.cc",
 | 
				
			||||||
 | 
					        "gtest-param-test_test.h",
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
 | 
					    deps = [
 | 
				
			||||||
 | 
					        "//:gtest",
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
		Reference in New Issue
	
	Block a user