Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
yangql
googletest
Commits
f11a8f91
Unverified
Commit
f11a8f91
authored
Feb 12, 2018
by
Conor Burgess
Committed by
GitHub
Feb 12, 2018
Browse files
Merge branch 'master' into fix-argc
parents
27bb844e
15392f1a
Changes
66
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
321 additions
and
82 deletions
+321
-82
googletest/test/gtest-param-test2_test.cc
googletest/test/gtest-param-test2_test.cc
+1
-1
googletest/test/gtest-printers_test.cc
googletest/test/gtest-printers_test.cc
+96
-12
googletest/test/gtest-typed-test2_test.cc
googletest/test/gtest-typed-test2_test.cc
+1
-1
googletest/test/gtest-typed-test_test.cc
googletest/test/gtest-typed-test_test.cc
+1
-1
googletest/test/gtest_assert_by_exception_test.cc
googletest/test/gtest_assert_by_exception_test.cc
+119
-0
googletest/test/gtest_break_on_failure_unittest.py
googletest/test/gtest_break_on_failure_unittest.py
+1
-3
googletest/test/gtest_catch_exceptions_test.py
googletest/test/gtest_catch_exceptions_test.py
+0
-2
googletest/test/gtest_color_test.py
googletest/test/gtest_color_test.py
+1
-2
googletest/test/gtest_env_var_test.py
googletest/test/gtest_env_var_test.py
+3
-3
googletest/test/gtest_filter_unittest.py
googletest/test/gtest_filter_unittest.py
+20
-18
googletest/test/gtest_list_tests_unittest.py
googletest/test/gtest_list_tests_unittest.py
+2
-2
googletest/test/gtest_output_test.py
googletest/test/gtest_output_test.py
+10
-6
googletest/test/gtest_output_test_.cc
googletest/test/gtest_output_test_.cc
+17
-0
googletest/test/gtest_output_test_golden_lin.txt
googletest/test/gtest_output_test_golden_lin.txt
+28
-8
googletest/test/gtest_pred_impl_unittest.cc
googletest/test/gtest_pred_impl_unittest.cc
+1
-1
googletest/test/gtest_prod_test.cc
googletest/test/gtest_prod_test.cc
+2
-2
googletest/test/gtest_repeat_test.cc
googletest/test/gtest_repeat_test.cc
+1
-1
googletest/test/gtest_test_utils.py
googletest/test/gtest_test_utils.py
+11
-13
googletest/test/gtest_throw_on_failure_test.py
googletest/test/gtest_throw_on_failure_test.py
+1
-1
googletest/test/gtest_uninitialized_test.py
googletest/test/gtest_uninitialized_test.py
+5
-5
No files found.
googletest/test/gtest-param-test2_test.cc
View file @
f11a8f91
...
...
@@ -33,7 +33,7 @@
// Google Test work.
#include "gtest/gtest.h"
#include "
test/
gtest-param-test_test.h"
#include "gtest-param-test_test.h"
using
::
testing
::
Values
;
using
::
testing
::
internal
::
ParamGenerator
;
...
...
googletest/test/gtest-printers_test.cc
View file @
f11a8f91
...
...
@@ -275,11 +275,11 @@ using hash_multiset = ::std::unordered_multiset<Key>;
#elif GTEST_HAS_HASH_SET_
#ifdef _STLP_HASH_MAP // We got <hash_map> from STLport.
using
::
std
::
hash_
set
;
using
::
std
::
hash_multi
set
;
using
::
std
::
hash_
map
;
using
::
std
::
hash_multi
map
;
#elif _MSC_VER
using
::
stdext
::
hash_
set
;
using
::
stdext
::
hash_multi
set
;
using
::
stdext
::
hash_
map
;
using
::
stdext
::
hash_multi
map
;
#endif
#endif
...
...
@@ -837,22 +837,22 @@ TEST(PrintTypeWithGenericStreamingTest, TypeImplicitlyConvertible) {
EXPECT_EQ
(
"AllowsGenericStreamingAndImplicitConversionTemplate"
,
Print
(
a
));
}
#if GTEST_HAS_
STRING_PIECE_
#if GTEST_HAS_
ABSL
// Tests printing
StringPiece
.
// Tests printing
::absl::string_view
.
TEST
(
PrintString
P
ie
ce
Test
,
SimpleString
P
ie
ce
)
{
const
StringPiece
sp
=
"Hello"
;
TEST
(
PrintString
V
ie
w
Test
,
SimpleString
V
ie
w
)
{
const
::
absl
::
string_view
sp
=
"Hello"
;
EXPECT_EQ
(
"
\"
Hello
\"
"
,
Print
(
sp
));
}
TEST
(
PrintString
P
ie
ce
Test
,
UnprintableCharacters
)
{
TEST
(
PrintString
V
ie
w
Test
,
UnprintableCharacters
)
{
const
char
str
[]
=
"NUL (
\0
) and
\r\t
"
;
const
StringPiece
sp
(
str
,
sizeof
(
str
)
-
1
);
const
::
absl
::
string_view
sp
(
str
,
sizeof
(
str
)
-
1
);
EXPECT_EQ
(
"
\"
NUL (
\\
0) and
\\
r
\\
t
\"
"
,
Print
(
sp
));
}
#endif // GTEST_HAS_
STRING_PIECE_
#endif // GTEST_HAS_
ABSL
// Tests printing STL containers.
...
...
@@ -1327,7 +1327,7 @@ TEST(FormatForComparisonFailureMessageTest, FormatsNonCharArrayAsPointer) {
}
// Tests formatting a char pointer when it's compared with another pointer.
// In this case we want to print it as a raw pointer, as the comparis
i
on is by
// In this case we want to print it as a raw pointer, as the comparison is by
// pointer.
// char pointer vs pointer
...
...
@@ -1552,6 +1552,78 @@ TEST(PrintToStringTest, WorksForCharArrayWithEmbeddedNul) {
EXPECT_PRINT_TO_STRING_
(
mutable_str_with_nul
,
"
\"
hello
\\
0 world
\"
"
);
}
TEST
(
PrintToStringTest
,
ContainsNonLatin
)
{
// Sanity test with valid UTF-8. Prints both in hex and as text.
std
::
string
non_ascii_str
=
::
std
::
string
(
"오전 4:30"
);
EXPECT_PRINT_TO_STRING_
(
non_ascii_str
,
"
\"\\
xEC
\\
x98
\\
xA4
\\
xEC
\\
xA0
\\
x84 4:30
\"\n
"
" As Text:
\"
오전 4:30
\"
"
);
non_ascii_str
=
::
std
::
string
(
"From ä — ẑ"
);
EXPECT_PRINT_TO_STRING_
(
non_ascii_str
,
"
\"
From
\\
xC3
\\
xA4
\\
xE2
\\
x80
\\
x94
\\
xE1
\\
xBA
\\
x91
\"
"
"
\n
As Text:
\"
From ä — ẑ
\"
"
);
}
TEST
(
IsValidUTF8Test
,
IllFormedUTF8
)
{
// The following test strings are ill-formed UTF-8 and are printed
// as hex only (or ASCII, in case of ASCII bytes) because IsValidUTF8() is
// expected to fail, thus output does not contain "As Text:".
static
const
char
*
const
kTestdata
[][
2
]
=
{
// 2-byte lead byte followed by a single-byte character.
{
"
\xC3\x74
"
,
"
\"\\
xC3t
\"
"
},
// Valid 2-byte character followed by an orphan trail byte.
{
"
\xC3\x84\xA4
"
,
"
\"\\
xC3
\\
x84
\\
xA4
\"
"
},
// Lead byte without trail byte.
{
"abc
\xC3
"
,
"
\"
abc
\\
xC3
\"
"
},
// 3-byte lead byte, single-byte character, orphan trail byte.
{
"x
\xE2\x70\x94
"
,
"
\"
x
\\
xE2p
\\
x94
\"
"
},
// Truncated 3-byte character.
{
"
\xE2\x80
"
,
"
\"\\
xE2
\\
x80
\"
"
},
// Truncated 3-byte character followed by valid 2-byte char.
{
"
\xE2\x80\xC3\x84
"
,
"
\"\\
xE2
\\
x80
\\
xC3
\\
x84
\"
"
},
// Truncated 3-byte character followed by a single-byte character.
{
"
\xE2\x80\x7A
"
,
"
\"\\
xE2
\\
x80z
\"
"
},
// 3-byte lead byte followed by valid 3-byte character.
{
"
\xE2\xE2\x80\x94
"
,
"
\"\\
xE2
\\
xE2
\\
x80
\\
x94
\"
"
},
// 4-byte lead byte followed by valid 3-byte character.
{
"
\xF0\xE2\x80\x94
"
,
"
\"\\
xF0
\\
xE2
\\
x80
\\
x94
\"
"
},
// Truncated 4-byte character.
{
"
\xF0\xE2\x80
"
,
"
\"\\
xF0
\\
xE2
\\
x80
\"
"
},
// Invalid UTF-8 byte sequences embedded in other chars.
{
"abc
\xE2\x80\x94\xC3\x74
xyc"
,
"
\"
abc
\\
xE2
\\
x80
\\
x94
\\
xC3txyc
\"
"
},
{
"abc
\xC3\x84\xE2\x80\xC3\x84
xyz"
,
"
\"
abc
\\
xC3
\\
x84
\\
xE2
\\
x80
\\
xC3
\\
x84xyz
\"
"
},
// Non-shortest UTF-8 byte sequences are also ill-formed.
// The classics: xC0, xC1 lead byte.
{
"
\xC0\x80
"
,
"
\"\\
xC0
\\
x80
\"
"
},
{
"
\xC1\x81
"
,
"
\"\\
xC1
\\
x81
\"
"
},
// Non-shortest sequences.
{
"
\xE0\x80\x80
"
,
"
\"\\
xE0
\\
x80
\\
x80
\"
"
},
{
"
\xf0\x80\x80\x80
"
,
"
\"\\
xF0
\\
x80
\\
x80
\\
x80
\"
"
},
// Last valid code point before surrogate range, should be printed as text,
// too.
{
"
\xED\x9F\xBF
"
,
"
\"\\
xED
\\
x9F
\\
xBF
\"\n
As Text:
\"
\"
"
},
// Start of surrogate lead. Surrogates are not printed as text.
{
"
\xED\xA0\x80
"
,
"
\"\\
xED
\\
xA0
\\
x80
\"
"
},
// Last non-private surrogate lead.
{
"
\xED\xAD\xBF
"
,
"
\"\\
xED
\\
xAD
\\
xBF
\"
"
},
// First private-use surrogate lead.
{
"
\xED\xAE\x80
"
,
"
\"\\
xED
\\
xAE
\\
x80
\"
"
},
// Last private-use surrogate lead.
{
"
\xED\xAF\xBF
"
,
"
\"\\
xED
\\
xAF
\\
xBF
\"
"
},
// Mid-point of surrogate trail.
{
"
\xED\xB3\xBF
"
,
"
\"\\
xED
\\
xB3
\\
xBF
\"
"
},
// First valid code point after surrogate range, should be printed as text,
// too.
{
"
\xEE\x80\x80
"
,
"
\"\\
xEE
\\
x80
\\
x80
\"\n
As Text:
\"
\"
"
}
};
for
(
int
i
=
0
;
i
<
int
(
sizeof
(
kTestdata
)
/
sizeof
(
kTestdata
[
0
]));
++
i
)
{
EXPECT_PRINT_TO_STRING_
(
kTestdata
[
i
][
0
],
kTestdata
[
i
][
1
]);
}
}
#undef EXPECT_PRINT_TO_STRING_
TEST
(
UniversalTersePrintTest
,
WorksForNonReference
)
{
...
...
@@ -1693,5 +1765,17 @@ TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsTersely) {
#endif // GTEST_HAS_STD_TUPLE_
#if GTEST_HAS_ABSL
TEST
(
PrintOptionalTest
,
Basic
)
{
absl
::
optional
<
int
>
value
;
EXPECT_EQ
(
"(nullopt)"
,
PrintToString
(
value
));
value
=
{
7
};
EXPECT_EQ
(
"(7)"
,
PrintToString
(
value
));
EXPECT_EQ
(
"(1.1)"
,
PrintToString
(
absl
::
optional
<
double
>
{
1.1
}));
EXPECT_EQ
(
"(
\"
A
\"
)"
,
PrintToString
(
absl
::
optional
<
std
::
string
>
{
"A"
}));
}
#endif // GTEST_HAS_ABSL
}
// namespace gtest_printers_test
}
// namespace testing
googletest/test/gtest-typed-test2_test.cc
View file @
f11a8f91
...
...
@@ -31,7 +31,7 @@
#include <vector>
#include "
test/
gtest-typed-test_test.h"
#include "gtest-typed-test_test.h"
#include "gtest/gtest.h"
#if GTEST_HAS_TYPED_TEST_P
...
...
googletest/test/gtest-typed-test_test.cc
View file @
f11a8f91
...
...
@@ -29,7 +29,7 @@
//
// Author: wan@google.com (Zhanyong Wan)
#include "
test/
gtest-typed-test_test.h"
#include "gtest-typed-test_test.h"
#include <set>
#include <vector>
...
...
googletest/test/gtest_assert_by_exception_test.cc
0 → 100644
View file @
f11a8f91
// Copyright 2009, 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: wan@google.com (Zhanyong Wan)
// Tests Google Test's assert-by-exception mode with exceptions enabled.
#include "gtest/gtest.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdexcept>
class
ThrowListener
:
public
testing
::
EmptyTestEventListener
{
void
OnTestPartResult
(
const
testing
::
TestPartResult
&
result
)
override
{
if
(
result
.
type
()
==
testing
::
TestPartResult
::
kFatalFailure
)
{
throw
testing
::
AssertionException
(
result
);
}
}
};
// Prints the given failure message and exits the program with
// non-zero. We use this instead of a Google Test assertion to
// indicate a failure, as the latter is been tested and cannot be
// relied on.
void
Fail
(
const
char
*
msg
)
{
printf
(
"FAILURE: %s
\n
"
,
msg
);
fflush
(
stdout
);
exit
(
1
);
}
static
void
AssertFalse
()
{
ASSERT_EQ
(
2
,
3
)
<<
"Expected failure"
;
}
// Tests that an assertion failure throws a subclass of
// std::runtime_error.
TEST
(
Test
,
Test
)
{
// A successful assertion shouldn't throw.
try
{
EXPECT_EQ
(
3
,
3
);
}
catch
(...)
{
Fail
(
"A successful assertion wrongfully threw."
);
}
// A successful assertion shouldn't throw.
try
{
EXPECT_EQ
(
3
,
4
);
}
catch
(...)
{
Fail
(
"A failed non-fatal assertion wrongfully threw."
);
}
// A failed assertion should throw.
try
{
AssertFalse
();
}
catch
(
const
testing
::
AssertionException
&
e
)
{
if
(
strstr
(
e
.
what
(),
"Expected failure"
)
!=
NULL
)
throw
;
printf
(
"%s"
,
"A failed assertion did throw an exception of the right type, "
"but the message is incorrect. Instead of containing
\"
Expected "
"failure
\"
, it is:
\n
"
);
Fail
(
e
.
what
());
}
catch
(...)
{
Fail
(
"A failed assertion threw the wrong type of exception."
);
}
Fail
(
"A failed assertion should've thrown but didn't."
);
}
int
kTestForContinuingTest
=
0
;
TEST
(
Test
,
Test2
)
{
// FIXME(sokolov): how to force Test2 to be after Test?
kTestForContinuingTest
=
1
;
}
int
main
(
int
argc
,
char
**
argv
)
{
testing
::
InitGoogleTest
(
&
argc
,
argv
);
testing
::
UnitTest
::
GetInstance
()
->
listeners
().
Append
(
new
ThrowListener
);
int
result
=
RUN_ALL_TESTS
();
if
(
result
==
0
)
{
printf
(
"RUN_ALL_TESTS returned %d
\n
"
,
result
);
Fail
(
"Expected failure instead."
);
}
if
(
kTestForContinuingTest
==
0
)
{
Fail
(
"Should have continued with other tests, but did not."
);
}
return
0
;
}
googletest/test/gtest_break_on_failure_unittest.py
View file @
f11a8f91
...
...
@@ -40,10 +40,8 @@ Google Test) with different environments and command line flags.
__author__
=
'wan@google.com (Zhanyong Wan)'
import
gtest_test_utils
import
os
import
sys
import
gtest_test_utils
# Constants.
...
...
googletest/test/gtest_catch_exceptions_test.py
View file @
f11a8f91
...
...
@@ -37,8 +37,6 @@ Google Test) and verifies their output.
__author__
=
'vladl@google.com (Vlad Losev)'
import
os
import
gtest_test_utils
# Constants.
...
...
googletest/test/gtest_color_test.py
View file @
f11a8f91
...
...
@@ -36,8 +36,7 @@ __author__ = 'wan@google.com (Zhanyong Wan)'
import
os
import
gtest_test_utils
IS_WINDOWS
=
os
.
name
=
'nt'
IS_WINDOWS
=
os
.
name
==
'nt'
COLOR_ENV_VAR
=
'GTEST_COLOR'
COLOR_FLAG
=
'gtest_color'
...
...
googletest/test/gtest_env_var_test.py
View file @
f11a8f91
...
...
@@ -47,8 +47,8 @@ environ = os.environ.copy()
def
AssertEq
(
expected
,
actual
):
if
expected
!=
actual
:
print
(
'Expected: %s'
%
(
expected
,)
)
print
(
' Actual: %s'
%
(
actual
,)
)
print
'Expected: %s'
%
(
expected
,)
print
' Actual: %s'
%
(
actual
,)
raise
AssertionError
...
...
@@ -92,7 +92,7 @@ class GTestEnvVarTest(gtest_test_utils.TestCase):
TestFlag
(
'print_time'
,
'0'
,
'1'
)
TestFlag
(
'repeat'
,
'999'
,
'1'
)
TestFlag
(
'throw_on_failure'
,
'1'
,
'0'
)
TestFlag
(
'death_test_style'
,
'threadsafe'
,
'fast'
)
TestFlag
(
'death_test_style'
,
'fast'
,
'threadsafe'
)
TestFlag
(
'catch_exceptions'
,
'0'
,
'1'
)
if
IS_LINUX
:
...
...
googletest/test/gtest_filter_unittest.py
View file @
f11a8f91
...
...
@@ -44,12 +44,8 @@ __author__ = 'wan@google.com (Zhanyong Wan)'
import
os
import
re
try
:
from
sets
import
Set
as
set
# For Python 2.3 compatibility
except
ImportError
:
pass
import
sets
import
sys
import
gtest_test_utils
# Constants.
...
...
@@ -59,10 +55,12 @@ import gtest_test_utils
# script in a subprocess to print whether the variable is STILL in
# os.environ. We then use 'eval' to parse the child's output so that an
# exception is thrown if the input is anything other than 'True' nor 'False'.
os
.
environ
[
'EMPTY_VAR'
]
=
''
child
=
gtest_test_utils
.
Subprocess
(
[
sys
.
executable
,
'-c'
,
'import os; print(
\'
EMPTY_VAR
\'
in os.environ)'
])
CAN_PASS_EMPTY_ENV
=
eval
(
child
.
output
)
CAN_PASS_EMPTY_ENV
=
False
if
sys
.
executable
:
os
.
environ
[
'EMPTY_VAR'
]
=
''
child
=
gtest_test_utils
.
Subprocess
(
[
sys
.
executable
,
'-c'
,
'import os; print
\'
EMPTY_VAR
\'
in os.environ'
])
CAN_PASS_EMPTY_ENV
=
eval
(
child
.
output
)
# Check if this platform can unset environment variables in child processes.
...
...
@@ -71,11 +69,14 @@ CAN_PASS_EMPTY_ENV = eval(child.output)
# is NO LONGER in os.environ.
# We use 'eval' to parse the child's output so that an exception
# is thrown if the input is neither 'True' nor 'False'.
os
.
environ
[
'UNSET_VAR'
]
=
'X'
del
os
.
environ
[
'UNSET_VAR'
]
child
=
gtest_test_utils
.
Subprocess
(
[
sys
.
executable
,
'-c'
,
'import os; print(
\'
UNSET_VAR
\'
not in os.environ)'
])
CAN_UNSET_ENV
=
eval
(
child
.
output
)
CAN_UNSET_ENV
=
False
if
sys
.
executable
:
os
.
environ
[
'UNSET_VAR'
]
=
'X'
del
os
.
environ
[
'UNSET_VAR'
]
child
=
gtest_test_utils
.
Subprocess
(
[
sys
.
executable
,
'-c'
,
'import os; print
\'
UNSET_VAR
\'
not in os.environ'
])
CAN_UNSET_ENV
=
eval
(
child
.
output
)
# Checks if we should test with an empty filter. This doesn't
...
...
@@ -97,7 +98,7 @@ SHARD_STATUS_FILE_ENV_VAR = 'GTEST_SHARD_STATUS_FILE'
FILTER_FLAG
=
'gtest_filter'
# The command line flag for including disabled tests.
ALSO_RUN_DISABED_TESTS_FLAG
=
'gtest_also_run_disabled_tests'
ALSO_RUN_DISAB
L
ED_TESTS_FLAG
=
'gtest_also_run_disabled_tests'
# Command to run the gtest_filter_unittest_ program.
COMMAND
=
gtest_test_utils
.
GetTestExecutablePath
(
'gtest_filter_unittest_'
)
...
...
@@ -246,14 +247,14 @@ class GTestFilterUnitTest(gtest_test_utils.TestCase):
for
slice_var
in
list_of_sets
:
full_partition
.
extend
(
slice_var
)
self
.
assertEqual
(
len
(
set_var
),
len
(
full_partition
))
self
.
assertEqual
(
set
(
set_var
),
set
(
full_partition
))
self
.
assertEqual
(
set
s
.
Set
(
set_var
),
set
s
.
Set
(
full_partition
))
def
AdjustForParameterizedTests
(
self
,
tests_to_run
):
"""Adjust tests_to_run in case value parameterized tests are disabled."""
global
param_tests_present
if
not
param_tests_present
:
return
list
(
set
(
tests_to_run
)
-
set
(
PARAM_TESTS
))
return
list
(
set
s
.
Set
(
tests_to_run
)
-
set
s
.
Set
(
PARAM_TESTS
))
else
:
return
tests_to_run
...
...
@@ -294,6 +295,7 @@ class GTestFilterUnitTest(gtest_test_utils.TestCase):
Runs all shards of gtest_filter_unittest_ with the given filter, and
verifies that the right set of tests were run. The union of tests run
on each shard should be identical to tests_to_run, without duplicates.
If check_exit_0, .
Args:
gtest_filter: A filter to apply to the tests.
...
...
@@ -339,7 +341,7 @@ class GTestFilterUnitTest(gtest_test_utils.TestCase):
tests_to_run
=
self
.
AdjustForParameterizedTests
(
tests_to_run
)
# Construct the command line.
args
=
[
'--%s'
%
ALSO_RUN_DISABED_TESTS_FLAG
]
args
=
[
'--%s'
%
ALSO_RUN_DISAB
L
ED_TESTS_FLAG
]
if
gtest_filter
is
not
None
:
args
.
append
(
'--%s=%s'
%
(
FILTER_FLAG
,
gtest_filter
))
...
...
googletest/test/gtest_list_tests_unittest.py
View file @
f11a8f91
...
...
@@ -39,9 +39,8 @@ Google Test) the command line flags.
__author__
=
'phanna@google.com (Patrick Hanna)'
import
gtest_test_utils
import
re
import
gtest_test_utils
# Constants.
...
...
@@ -123,6 +122,7 @@ def Run(args):
# The unit test.
class
GTestListTestsUnitTest
(
gtest_test_utils
.
TestCase
):
"""Tests using the --gtest_list_tests flag to list all tests."""
...
...
googletest/test/gtest_output_test.py
View file @
f11a8f91
...
...
@@ -31,6 +31,7 @@
"""Tests the text output of Google C++ Testing Framework.
SYNOPSIS
gtest_output_test.py --build_dir=BUILD/DIR --gengolden
# where BUILD/DIR contains the built gtest_output_test_ file.
...
...
@@ -51,6 +52,7 @@ import gtest_test_utils
GENGOLDEN_FLAG
=
'--gengolden'
CATCH_EXCEPTIONS_ENV_VAR_NAME
=
'GTEST_CATCH_EXCEPTIONS'
IS_LINUX
=
os
.
name
==
'posix'
and
os
.
uname
()[
0
]
==
'Linux'
IS_WINDOWS
=
os
.
name
==
'nt'
# TODO(vladl@google.com): remove the _lin suffix.
...
...
@@ -99,7 +101,8 @@ def RemoveLocations(test_output):
'FILE_NAME:#: '.
"""
return
re
.
sub
(
r
'.*[/\\](.+)(\:\d+|\(\d+\))\: '
,
r
'\1:#: '
,
test_output
)
return
re
.
sub
(
r
'.*[/\\]((gtest_output_test_|gtest).cc)(\:\d+|\(\d+\))\: '
,
r
'\1:#: '
,
test_output
)
def
RemoveStackTraceDetails
(
output
):
...
...
@@ -249,11 +252,12 @@ test_list = GetShellCommandOutput(COMMAND_LIST_TESTS)
SUPPORTS_DEATH_TESTS
=
'DeathTest'
in
test_list
SUPPORTS_TYPED_TESTS
=
'TypedTest'
in
test_list
SUPPORTS_THREADS
=
'ExpectFailureWithThreadsTest'
in
test_list
SUPPORTS_STACK_TRACES
=
False
SUPPORTS_STACK_TRACES
=
IS_LINUX
CAN_GENERATE_GOLDEN_FILE
=
(
SUPPORTS_DEATH_TESTS
and
SUPPORTS_TYPED_TESTS
and
SUPPORTS_THREADS
and
SUPPORTS_STACK_TRACES
and
not
IS_WINDOWS
)
class
GTestOutputTest
(
gtest_test_utils
.
TestCase
):
...
...
@@ -279,7 +283,7 @@ class GTestOutputTest(gtest_test_utils.TestCase):
def
testOutput
(
self
):
output
=
GetOutputOfAllCommands
()
golden_file
=
open
(
GOLDEN_PATH
,
'r'
)
golden_file
=
open
(
GOLDEN_PATH
,
'r
b
'
)
# A mis-configured source control system can cause \r appear in EOL
# sequences when we read the golden file irrespective of an operating
# system used. Therefore, we need to strip those \r's from newlines
...
...
@@ -330,9 +334,9 @@ if __name__ == '__main__':
else
:
message
=
(
"""Unable to write a golden file when compiled in an environment
that does not support all the required features (death tests,
typed tests,
and multiple threads). Please generate the golden file using a binary built
with those features enabled
."""
)
that does not support all the required features (death tests,
typed tests, stack traces, and multiple threads).
Please build this test and generate the golden file using Blaze on Linux
."""
)
sys
.
stderr
.
write
(
message
)
sys
.
exit
(
1
)
...
...
googletest/test/gtest_output_test_.cc
View file @
f11a8f91
...
...
@@ -168,6 +168,16 @@ void SubWithTrace(int n) {
SubWithoutTrace
(
n
);
}
TEST
(
SCOPED_TRACETest
,
AcceptedValues
)
{
SCOPED_TRACE
(
"literal string"
);
SCOPED_TRACE
(
std
::
string
(
"std::string"
));
SCOPED_TRACE
(
1337
);
// streamable type
const
char
*
null_value
=
NULL
;
SCOPED_TRACE
(
null_value
);
ADD_FAILURE
()
<<
"Just checking that all these values work fine."
;
}
// Tests that SCOPED_TRACE() obeys lexical scopes.
TEST
(
SCOPED_TRACETest
,
ObeysScopes
)
{
printf
(
"(expected to fail)
\n
"
);
...
...
@@ -315,6 +325,13 @@ TEST(SCOPED_TRACETest, WorksConcurrently) {
}
#endif // GTEST_IS_THREADSAFE
// Tests basic functionality of the ScopedTrace utility (most of its features
// are already tested in SCOPED_TRACETest).
TEST
(
ScopedTraceTest
,
WithExplicitFileAndLine
)
{
testing
::
ScopedTrace
trace
(
"explicit_file.cc"
,
123
,
"expected trace message"
);
ADD_FAILURE
()
<<
"Check that the trace is attached to a particular location."
;
}
TEST
(
DisabledTestsWarningTest
,
DISABLED_AlsoRunDisabledTestsFlagSuppressesWarning
)
{
// This test body is intentionally empty. Its sole purpose is for
...
...
googletest/test/gtest_output_test_golden_lin.txt
View file @
f11a8f91
...
...
@@ -8,7 +8,7 @@ gtest_output_test_.cc:#: Failure
Expected equality of these values:
2
3
[0;32m[==========] [mRunning 6
6
tests from
29
test cases.
[0;32m[==========] [mRunning 6
8
tests from
30
test cases.
[0;32m[----------] [mGlobal test environment set-up.
FooEnvironment::SetUp() called.
BarEnvironment::SetUp() called.
...
...
@@ -95,7 +95,17 @@ i == 3
gtest_output_test_.cc:#: Failure
Expected: (3) >= (a[i]), actual: 3 vs 6
[0;31m[ FAILED ] [mLoggingTest.InterleavingLoggingAndAssertions
[0;32m[----------] [m6 tests from SCOPED_TRACETest
[0;32m[----------] [m7 tests from SCOPED_TRACETest
[0;32m[ RUN ] [mSCOPED_TRACETest.AcceptedValues
gtest_output_test_.cc:#: Failure
Failed
Just checking that all these values work fine.
Google Test trace:
gtest_output_test_.cc:#: (null)
gtest_output_test_.cc:#: 1337
gtest_output_test_.cc:#: std::string
gtest_output_test_.cc:#: literal string
[0;31m[ FAILED ] [mSCOPED_TRACETest.AcceptedValues
[0;32m[ RUN ] [mSCOPED_TRACETest.ObeysScopes
(expected to fail)
gtest_output_test_.cc:#: Failure
...
...
@@ -212,6 +222,14 @@ gtest_output_test_.cc:#: Failure
Failed
Expected failure #6 (in thread A, no trace alive).
[0;31m[ FAILED ] [mSCOPED_TRACETest.WorksConcurrently
[0;32m[----------] [m1 test from ScopedTraceTest
[0;32m[ RUN ] [mScopedTraceTest.WithExplicitFileAndLine
gtest_output_test_.cc:#: Failure
Failed
Check that the trace is attached to a particular location.
Google Test trace:
explicit_file.cc:123: expected trace message
[0;31m[ FAILED ] [mScopedTraceTest.WithExplicitFileAndLine
[0;32m[----------] [m1 test from NonFatalFailureInFixtureConstructorTest
[0;32m[ RUN ] [mNonFatalFailureInFixtureConstructorTest.FailureInConstructor
(expecting 5 failures)
...
...
@@ -466,7 +484,7 @@ Expected equality of these values:
Which is: '\0'
Expected failure
[0;31m[ FAILED ] [mUnsigned/TypedTestP/0.Failure, where TypeParam = unsigned char
[0;32m[----------] [m2 tests from Unsigned/TypedTestP/1, where TypeParam = unsigned
int
[0;32m[----------] [m2 tests from Unsigned/TypedTestP/1, where TypeParam = unsigned
[0;32m[ RUN ] [mUnsigned/TypedTestP/1.Success
[0;32m[ OK ] [mUnsigned/TypedTestP/1.Success
[0;32m[ RUN ] [mUnsigned/TypedTestP/1.Failure
...
...
@@ -477,7 +495,7 @@ Expected equality of these values:
TypeParam()
Which is: 0
Expected failure
[0;31m[ FAILED ] [mUnsigned/TypedTestP/1.Failure, where TypeParam = unsigned
int
[0;31m[ FAILED ] [mUnsigned/TypedTestP/1.Failure, where TypeParam = unsigned
[0;32m[----------] [m4 tests from ExpectFailureTest
[0;32m[ RUN ] [mExpectFailureTest.ExpectFatalFailure
(expecting 1 failure)
...
...
@@ -636,21 +654,23 @@ FooEnvironment::TearDown() called.
gtest_output_test_.cc:#: Failure
Failed
Expected fatal failure.
[0;32m[==========] [m6
6
tests from
29
test cases ran.
[0;32m[==========] [m6
8
tests from
30
test cases ran.
[0;32m[ PASSED ] [m22 tests.
[0;31m[ FAILED ] [m4
4
tests, listed below:
[0;31m[ FAILED ] [m4
6
tests, listed below:
[0;31m[ FAILED ] [mNonfatalFailureTest.EscapesStringOperands
[0;31m[ FAILED ] [mNonfatalFailureTest.DiffForLongStrings
[0;31m[ FAILED ] [mFatalFailureTest.FatalFailureInSubroutine
[0;31m[ FAILED ] [mFatalFailureTest.FatalFailureInNestedSubroutine
[0;31m[ FAILED ] [mFatalFailureTest.NonfatalFailureInSubroutine
[0;31m[ FAILED ] [mLoggingTest.InterleavingLoggingAndAssertions
[0;31m[ FAILED ] [mSCOPED_TRACETest.AcceptedValues
[0;31m[ FAILED ] [mSCOPED_TRACETest.ObeysScopes
[0;31m[ FAILED ] [mSCOPED_TRACETest.WorksInLoop
[0;31m[ FAILED ] [mSCOPED_TRACETest.WorksInSubroutine
[0;31m[ FAILED ] [mSCOPED_TRACETest.CanBeNested
[0;31m[ FAILED ] [mSCOPED_TRACETest.CanBeRepeated
[0;31m[ FAILED ] [mSCOPED_TRACETest.WorksConcurrently
[0;31m[ FAILED ] [mScopedTraceTest.WithExplicitFileAndLine
[0;31m[ FAILED ] [mNonFatalFailureInFixtureConstructorTest.FailureInConstructor
[0;31m[ FAILED ] [mFatalFailureInFixtureConstructorTest.FailureInConstructor
[0;31m[ FAILED ] [mNonFatalFailureInSetUpTest.FailureInSetUp
...
...
@@ -673,7 +693,7 @@ Expected fatal failure.
[0;31m[ FAILED ] [mExpectFatalFailureTest.FailsWhenStatementThrows
[0;31m[ FAILED ] [mTypedTest/0.Failure, where TypeParam = int
[0;31m[ FAILED ] [mUnsigned/TypedTestP/0.Failure, where TypeParam = unsigned char
[0;31m[ FAILED ] [mUnsigned/TypedTestP/1.Failure, where TypeParam = unsigned
int
[0;31m[ FAILED ] [mUnsigned/TypedTestP/1.Failure, where TypeParam = unsigned
[0;31m[ FAILED ] [mExpectFailureTest.ExpectFatalFailure
[0;31m[ FAILED ] [mExpectFailureTest.ExpectNonFatalFailure
[0;31m[ FAILED ] [mExpectFailureTest.ExpectFatalFailureOnAllThreads
...
...
@@ -684,7 +704,7 @@ Expected fatal failure.
[0;31m[ FAILED ] [mPrintingFailingParams/FailingParamTest.Fails/0, where GetParam() = 2
[0;31m[ FAILED ] [mPrintingStrings/ParamTest.Failure/a, where GetParam() = "a"
4
4
FAILED TESTS
4
6
FAILED TESTS
[0;33m YOU HAVE 1 DISABLED TEST
[mNote: Google Test filter = FatalFailureTest.*:LoggingTest.*
...
...
googletest/test/gtest_pred_impl_unittest.cc
View file @
f11a8f91
...
...
@@ -27,7 +27,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// This file is AUTOMATICALLY GENERATED on
10/31
/201
1
by command
// This file is AUTOMATICALLY GENERATED on
01/02
/201
8
by command
// 'gen_gtest_pred_impl.py 5'. DO NOT EDIT BY HAND!
// Regression test for gtest_pred_impl.h
...
...
googletest/test/gtest_prod_test.cc
View file @
f11a8f91
...
...
@@ -29,10 +29,10 @@
//
// Author: wan@google.com (Zhanyong Wan)
//
// Unit test for
include/
gtest/gtest_prod.h.
// Unit test for gtest/gtest_prod.h.
#include "production.h"
#include "gtest/gtest.h"
#include "test/production.h"
// Tests that private members can be accessed from a TEST declared as
// a friend of the class.
...
...
googletest/test/gtest_repeat_test.cc
View file @
f11a8f91
...
...
@@ -67,7 +67,7 @@ namespace {
// Used for verifying that global environment set-up and tear-down are
// inside the gtest_repeat loop.
// inside the
--
gtest_repeat loop.
int
g_environment_set_up_count
=
0
;
int
g_environment_tear_down_count
=
0
;
...
...
googletest/test/gtest_test_utils.py
View file @
f11a8f91
#!/usr/bin/env python
#
# Copyright 2006, Google Inc.
# All rights reserved.
#
...
...
@@ -30,19 +28,24 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""Unit test utilities for Google C++ Testing Framework."""
# Suppresses the 'Import not at the top of the file' lint complaint.
# pylint: disable-msg=C6204
__author__
=
'wan@google.com (Zhanyong Wan)'
import
atexit
import
os
import
shutil
import
sys
IS_LINUX
=
os
.
name
==
'posix'
and
os
.
uname
()[
0
]
==
'Linux'
IS_WINDOWS
=
os
.
name
==
'nt'
IS_CYGWIN
=
os
.
name
==
'posix'
and
'CYGWIN'
in
os
.
uname
()[
0
]
import
atexit
import
shutil
import
tempfile
import
unittest
_test_module
=
unittest
# Suppresses the 'Import not at the top of the file' lint complaint.
# pylint: disable-msg=C6204
try
:
import
subprocess
_SUBPROCESS_MODULE_AVAILABLE
=
True
...
...
@@ -53,9 +56,6 @@ except:
GTEST_OUTPUT_VAR_NAME
=
'GTEST_OUTPUT'
IS_WINDOWS
=
os
.
name
==
'nt'
IS_CYGWIN
=
os
.
name
==
'posix'
and
'CYGWIN'
in
os
.
uname
()[
0
]
# The environment variable for specifying the path to the premature-exit file.
PREMATURE_EXIT_FILE_ENV_VAR
=
'TEST_PREMATURE_EXIT_FILE'
...
...
@@ -145,8 +145,6 @@ atexit.register(_RemoveTempDir)
def
GetTempDir
():
"""Returns a directory for temporary files."""
global
_temp_dir
if
not
_temp_dir
:
_temp_dir
=
tempfile
.
mkdtemp
()
...
...
@@ -178,7 +176,7 @@ def GetTestExecutablePath(executable_name, build_dir=None):
'Unable to find the test binary "%s". Please make sure to provide
\n
'
'a path to the binary via the --build_dir flag or the BUILD_DIR
\n
'
'environment variable.'
%
path
)
sys
.
stdout
.
write
(
message
)
print
>>
sys
.
stderr
,
message
sys
.
exit
(
1
)
return
path
...
...
@@ -229,7 +227,7 @@ class Subprocess:
combined in a string.
"""
# The subprocess module is the prefer
r
able way of running programs
# The subprocess module is the preferable way of running programs
# since it is available and behaves consistently on all platforms,
# including Windows. But it is only available starting in python 2.4.
# In earlier python versions, we revert to the popen2 module, which is
...
...
googletest/test/gtest_throw_on_failure_test.py
View file @
f11a8f91
...
...
@@ -70,7 +70,7 @@ def SetEnvVar(env_var, value):
def
Run
(
command
):
"""Runs a command; returns True/False if its exit code is/isn't 0."""
print
(
'Running "%s". . .'
%
' '
.
join
(
command
)
)
print
'Running "%s". . .'
%
' '
.
join
(
command
)
p
=
gtest_test_utils
.
Subprocess
(
command
)
return
p
.
exited
and
p
.
exit_code
==
0
...
...
googletest/test/gtest_uninitialized_test.py
View file @
f11a8f91
...
...
@@ -33,9 +33,9 @@
__author__
=
'wan@google.com (Zhanyong Wan)'
import
os
import
gtest_test_utils
COMMAND
=
gtest_test_utils
.
GetTestExecutablePath
(
'gtest_uninitialized_test_'
)
...
...
@@ -46,8 +46,8 @@ def Assert(condition):
def
AssertEq
(
expected
,
actual
):
if
expected
!=
actual
:
print
(
'Expected: %s'
%
(
expected
,)
)
print
(
' Actual: %s'
%
(
actual
,)
)
print
'Expected: %s'
%
(
expected
,)
print
' Actual: %s'
%
(
actual
,)
raise
AssertionError
...
...
@@ -56,8 +56,8 @@ def TestExitCodeAndOutput(command):
# Verifies that 'command' exits with code 1.
p
=
gtest_test_utils
.
Subprocess
(
command
)
Assert
(
p
.
exited
)
Assert
Eq
(
1
,
p
.
exit_code
)
if
p
.
exited
and
p
.
exit_code
==
0
:
Assert
(
'IMPORTANT NOTICE'
in
p
.
output
);
Assert
(
'InitGoogleTest'
in
p
.
output
)
...
...
Prev
1
2
3
4
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment