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
fc437ef4
Unverified
Commit
fc437ef4
authored
Mar 12, 2018
by
Bernhard Bauer
Committed by
GitHub
Mar 12, 2018
Browse files
Merge branch 'master' into upstream_188748737
parents
7b70413e
abc6e943
Changes
64
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
1834 additions
and
224 deletions
+1834
-224
googletest/src/gtest-filepath.cc
googletest/src/gtest-filepath.cc
+1
-1
googletest/src/gtest-internal-inl.h
googletest/src/gtest-internal-inl.h
+6
-2
googletest/src/gtest-port.cc
googletest/src/gtest-port.cc
+30
-12
googletest/src/gtest-printers.cc
googletest/src/gtest-printers.cc
+88
-6
googletest/src/gtest-typed-test.cc
googletest/src/gtest-typed-test.cc
+1
-0
googletest/src/gtest.cc
googletest/src/gtest.cc
+481
-69
googletest/test/BUILD.bazel
googletest/test/BUILD.bazel
+17
-0
googletest/test/gtest-death-test_test.cc
googletest/test/gtest-death-test_test.cc
+5
-1
googletest/test/gtest-param-test_test.cc
googletest/test/gtest-param-test_test.cc
+54
-9
googletest/test/gtest-printers_test.cc
googletest/test/gtest-printers_test.cc
+93
-9
googletest/test/gtest_all_test.cc
googletest/test/gtest_all_test.cc
+12
-12
googletest/test/gtest_assert_by_exception_test.cc
googletest/test/gtest_assert_by_exception_test.cc
+119
-0
googletest/test/gtest_env_var_test_.cc
googletest/test/gtest_env_var_test_.cc
+1
-0
googletest/test/gtest_json_outfiles_test.py
googletest/test/gtest_json_outfiles_test.py
+162
-0
googletest/test/gtest_json_output_unittest.py
googletest/test/gtest_json_output_unittest.py
+611
-0
googletest/test/gtest_json_test_utils.py
googletest/test/gtest_json_test_utils.py
+60
-0
googletest/test/gtest_main_unittest.cc
googletest/test/gtest_main_unittest.cc
+2
-2
googletest/test/gtest_uninitialized_test.py
googletest/test/gtest_uninitialized_test.py
+0
-1
googletest/test/gtest_uninitialized_test_.cc
googletest/test/gtest_uninitialized_test_.cc
+1
-1
googletest/test/gtest_unittest.cc
googletest/test/gtest_unittest.cc
+90
-99
No files found.
googletest/src/gtest-filepath.cc
View file @
fc437ef4
...
@@ -128,7 +128,7 @@ FilePath FilePath::RemoveExtension(const char* extension) const {
...
@@ -128,7 +128,7 @@ FilePath FilePath::RemoveExtension(const char* extension) const {
return
*
this
;
return
*
this
;
}
}
// Returns a pointer to the last occurence of a valid path separator in
// Returns a pointer to the last occur
r
ence of a valid path separator in
// the FilePath. On Windows, for example, both '/' and '\' are valid path
// the FilePath. On Windows, for example, both '/' and '\' are valid path
// separators. Returns NULL if no path separator was found.
// separators. Returns NULL if no path separator was found.
const
char
*
FilePath
::
FindLastPathSeparator
()
const
{
const
char
*
FilePath
::
FindLastPathSeparator
()
const
{
...
...
googletest/src/gtest-internal-inl.h
View file @
fc437ef4
...
@@ -59,7 +59,7 @@
...
@@ -59,7 +59,7 @@
# include <windows.h> // NOLINT
# include <windows.h> // NOLINT
#endif // GTEST_OS_WINDOWS
#endif // GTEST_OS_WINDOWS
#include "gtest/gtest.h"
// NOLINT
#include "gtest/gtest.h"
#include "gtest/gtest-spi.h"
#include "gtest/gtest-spi.h"
namespace
testing
{
namespace
testing
{
...
@@ -86,6 +86,7 @@ const char kFilterFlag[] = "filter";
...
@@ -86,6 +86,7 @@ const char kFilterFlag[] = "filter";
const
char
kListTestsFlag
[]
=
"list_tests"
;
const
char
kListTestsFlag
[]
=
"list_tests"
;
const
char
kOutputFlag
[]
=
"output"
;
const
char
kOutputFlag
[]
=
"output"
;
const
char
kPrintTimeFlag
[]
=
"print_time"
;
const
char
kPrintTimeFlag
[]
=
"print_time"
;
const
char
kPrintUTF8Flag
[]
=
"print_utf8"
;
const
char
kRandomSeedFlag
[]
=
"random_seed"
;
const
char
kRandomSeedFlag
[]
=
"random_seed"
;
const
char
kRepeatFlag
[]
=
"repeat"
;
const
char
kRepeatFlag
[]
=
"repeat"
;
const
char
kShuffleFlag
[]
=
"shuffle"
;
const
char
kShuffleFlag
[]
=
"shuffle"
;
...
@@ -166,6 +167,7 @@ class GTestFlagSaver {
...
@@ -166,6 +167,7 @@ class GTestFlagSaver {
list_tests_
=
GTEST_FLAG
(
list_tests
);
list_tests_
=
GTEST_FLAG
(
list_tests
);
output_
=
GTEST_FLAG
(
output
);
output_
=
GTEST_FLAG
(
output
);
print_time_
=
GTEST_FLAG
(
print_time
);
print_time_
=
GTEST_FLAG
(
print_time
);
print_utf8_
=
GTEST_FLAG
(
print_utf8
);
random_seed_
=
GTEST_FLAG
(
random_seed
);
random_seed_
=
GTEST_FLAG
(
random_seed
);
repeat_
=
GTEST_FLAG
(
repeat
);
repeat_
=
GTEST_FLAG
(
repeat
);
shuffle_
=
GTEST_FLAG
(
shuffle
);
shuffle_
=
GTEST_FLAG
(
shuffle
);
...
@@ -187,6 +189,7 @@ class GTestFlagSaver {
...
@@ -187,6 +189,7 @@ class GTestFlagSaver {
GTEST_FLAG
(
list_tests
)
=
list_tests_
;
GTEST_FLAG
(
list_tests
)
=
list_tests_
;
GTEST_FLAG
(
output
)
=
output_
;
GTEST_FLAG
(
output
)
=
output_
;
GTEST_FLAG
(
print_time
)
=
print_time_
;
GTEST_FLAG
(
print_time
)
=
print_time_
;
GTEST_FLAG
(
print_utf8
)
=
print_utf8_
;
GTEST_FLAG
(
random_seed
)
=
random_seed_
;
GTEST_FLAG
(
random_seed
)
=
random_seed_
;
GTEST_FLAG
(
repeat
)
=
repeat_
;
GTEST_FLAG
(
repeat
)
=
repeat_
;
GTEST_FLAG
(
shuffle
)
=
shuffle_
;
GTEST_FLAG
(
shuffle
)
=
shuffle_
;
...
@@ -208,6 +211,7 @@ class GTestFlagSaver {
...
@@ -208,6 +211,7 @@ class GTestFlagSaver {
bool
list_tests_
;
bool
list_tests_
;
std
::
string
output_
;
std
::
string
output_
;
bool
print_time_
;
bool
print_time_
;
bool
print_utf8_
;
internal
::
Int32
random_seed_
;
internal
::
Int32
random_seed_
;
internal
::
Int32
repeat_
;
internal
::
Int32
repeat_
;
bool
shuffle_
;
bool
shuffle_
;
...
@@ -1020,7 +1024,7 @@ class TestResultAccessor {
...
@@ -1020,7 +1024,7 @@ class TestResultAccessor {
#if GTEST_CAN_STREAM_RESULTS_
#if GTEST_CAN_STREAM_RESULTS_
// Streams test results to the given port on the given host machine.
// Streams test results to the given port on the given host machine.
class
GTEST_API_
StreamingListener
:
public
EmptyTestEventListener
{
class
StreamingListener
:
public
EmptyTestEventListener
{
public:
public:
// Abstract base class for writing strings to a socket.
// Abstract base class for writing strings to a socket.
class
AbstractSocketWriter
{
class
AbstractSocketWriter
{
...
...
googletest/src/gtest-port.cc
View file @
fc437ef4
...
@@ -915,6 +915,7 @@ GTestLog::~GTestLog() {
...
@@ -915,6 +915,7 @@ GTestLog::~GTestLog() {
posix
::
Abort
();
posix
::
Abort
();
}
}
}
}
// Disable Microsoft deprecation warnings for POSIX functions called from
// Disable Microsoft deprecation warnings for POSIX functions called from
// this class (creat, dup, dup2, and close)
// this class (creat, dup, dup2, and close)
GTEST_DISABLE_MSC_WARNINGS_PUSH_
(
4996
)
GTEST_DISABLE_MSC_WARNINGS_PUSH_
(
4996
)
...
@@ -1007,8 +1008,7 @@ static CapturedStream* g_captured_stderr = NULL;
...
@@ -1007,8 +1008,7 @@ static CapturedStream* g_captured_stderr = NULL;
static
CapturedStream
*
g_captured_stdout
=
NULL
;
static
CapturedStream
*
g_captured_stdout
=
NULL
;
// Starts capturing an output stream (stdout/stderr).
// Starts capturing an output stream (stdout/stderr).
static
void
CaptureStream
(
int
fd
,
static
void
CaptureStream
(
int
fd
,
const
char
*
stream_name
,
const
char
*
stream_name
,
CapturedStream
**
stream
)
{
CapturedStream
**
stream
)
{
if
(
*
stream
!=
NULL
)
{
if
(
*
stream
!=
NULL
)
{
GTEST_LOG_
(
FATAL
)
<<
"Only one "
<<
stream_name
GTEST_LOG_
(
FATAL
)
<<
"Only one "
<<
stream_name
...
@@ -1049,6 +1049,10 @@ std::string GetCapturedStderr() {
...
@@ -1049,6 +1049,10 @@ std::string GetCapturedStderr() {
#endif // GTEST_HAS_STREAM_REDIRECTION
#endif // GTEST_HAS_STREAM_REDIRECTION
size_t
GetFileSize
(
FILE
*
file
)
{
size_t
GetFileSize
(
FILE
*
file
)
{
fseek
(
file
,
0
,
SEEK_END
);
fseek
(
file
,
0
,
SEEK_END
);
return
static_cast
<
size_t
>
(
ftell
(
file
));
return
static_cast
<
size_t
>
(
ftell
(
file
));
...
@@ -1077,22 +1081,36 @@ std::string ReadEntireFile(FILE* file) {
...
@@ -1077,22 +1081,36 @@ std::string ReadEntireFile(FILE* file) {
}
}
#if GTEST_HAS_DEATH_TEST
#if GTEST_HAS_DEATH_TEST
static
const
std
::
vector
<
std
::
string
>*
g_injected_test_argvs
=
NULL
;
// Owned.
static
const
::
std
::
vector
<
testing
::
internal
::
string
>*
g_injected_test_argvs
=
std
::
vector
<
std
::
string
>
GetInjectableArgvs
()
{
NULL
;
// Owned.
void
SetInjectableArgvs
(
const
::
std
::
vector
<
testing
::
internal
::
string
>*
argvs
)
{
if
(
g_injected_test_argvs
!=
argvs
)
delete
g_injected_test_argvs
;
g_injected_test_argvs
=
argvs
;
}
const
::
std
::
vector
<
testing
::
internal
::
string
>&
GetInjectableArgvs
()
{
if
(
g_injected_test_argvs
!=
NULL
)
{
if
(
g_injected_test_argvs
!=
NULL
)
{
return
*
g_injected_test_argvs
;
return
*
g_injected_test_argvs
;
}
}
return
GetArgvs
();
return
GetArgvs
();
}
}
void
SetInjectableArgvs
(
const
std
::
vector
<
std
::
string
>*
new_argvs
)
{
if
(
g_injected_test_argvs
!=
new_argvs
)
delete
g_injected_test_argvs
;
g_injected_test_argvs
=
new_argvs
;
}
void
SetInjectableArgvs
(
const
std
::
vector
<
std
::
string
>&
new_argvs
)
{
SetInjectableArgvs
(
new
std
::
vector
<
std
::
string
>
(
new_argvs
.
begin
(),
new_argvs
.
end
()));
}
#if GTEST_HAS_GLOBAL_STRING
void
SetInjectableArgvs
(
const
std
::
vector
<
::
string
>&
new_argvs
)
{
SetInjectableArgvs
(
new
std
::
vector
<
std
::
string
>
(
new_argvs
.
begin
(),
new_argvs
.
end
()));
}
#endif // GTEST_HAS_GLOBAL_STRING
void
ClearInjectableArgvs
()
{
delete
g_injected_test_argvs
;
g_injected_test_argvs
=
NULL
;
}
#endif // GTEST_HAS_DEATH_TEST
#endif // GTEST_HAS_DEATH_TEST
#if GTEST_OS_WINDOWS_MOBILE
#if GTEST_OS_WINDOWS_MOBILE
...
...
googletest/src/gtest-printers.cc
View file @
fc437ef4
...
@@ -43,12 +43,13 @@
...
@@ -43,12 +43,13 @@
// defines Foo.
// defines Foo.
#include "gtest/gtest-printers.h"
#include "gtest/gtest-printers.h"
#include <ctype.h>
#include <stdio.h>
#include <stdio.h>
#include <cctype>
#include <cwchar>
#include <cwchar>
#include <ostream> // NOLINT
#include <ostream> // NOLINT
#include <string>
#include <string>
#include "gtest/internal/gtest-port.h"
#include "gtest/internal/gtest-port.h"
#include "src/gtest-internal-inl.h"
namespace
testing
{
namespace
testing
{
...
@@ -123,7 +124,7 @@ namespace internal {
...
@@ -123,7 +124,7 @@ namespace internal {
// Depending on the value of a char (or wchar_t), we print it in one
// Depending on the value of a char (or wchar_t), we print it in one
// of three formats:
// of three formats:
// - as is if it's a printable ASCII (e.g. 'a', '2', ' '),
// - as is if it's a printable ASCII (e.g. 'a', '2', ' '),
// - as a hex
i
decimal escape sequence (e.g. '\x7F'), or
// - as a hex
a
decimal escape sequence (e.g. '\x7F'), or
// - as a special escape sequence (e.g. '\r', '\n').
// - as a special escape sequence (e.g. '\r', '\n').
enum
CharFormat
{
enum
CharFormat
{
kAsIs
,
kAsIs
,
...
@@ -230,7 +231,7 @@ void PrintCharAndCodeTo(Char c, ostream* os) {
...
@@ -230,7 +231,7 @@ void PrintCharAndCodeTo(Char c, ostream* os) {
return
;
return
;
*
os
<<
" ("
<<
static_cast
<
int
>
(
c
);
*
os
<<
" ("
<<
static_cast
<
int
>
(
c
);
// For more convenience, we print c's code again in hex
i
decimal,
// For more convenience, we print c's code again in hex
a
decimal,
// unless c was already printed in the form '\x##' or the code is in
// unless c was already printed in the form '\x##' or the code is in
// [1, 9].
// [1, 9].
if
(
format
==
kHexEscape
||
(
1
<=
c
&&
c
<=
9
))
{
if
(
format
==
kHexEscape
||
(
1
<=
c
&&
c
<=
9
))
{
...
@@ -262,11 +263,12 @@ template <typename CharType>
...
@@ -262,11 +263,12 @@ template <typename CharType>
GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_
GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_
GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_
GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_
static
void
PrintCharsAsStringTo
(
static
CharFormat
PrintCharsAsStringTo
(
const
CharType
*
begin
,
size_t
len
,
ostream
*
os
)
{
const
CharType
*
begin
,
size_t
len
,
ostream
*
os
)
{
const
char
*
const
kQuoteBegin
=
sizeof
(
CharType
)
==
1
?
"
\"
"
:
"L
\"
"
;
const
char
*
const
kQuoteBegin
=
sizeof
(
CharType
)
==
1
?
"
\"
"
:
"L
\"
"
;
*
os
<<
kQuoteBegin
;
*
os
<<
kQuoteBegin
;
bool
is_previous_hex
=
false
;
bool
is_previous_hex
=
false
;
CharFormat
print_format
=
kAsIs
;
for
(
size_t
index
=
0
;
index
<
len
;
++
index
)
{
for
(
size_t
index
=
0
;
index
<
len
;
++
index
)
{
const
CharType
cur
=
begin
[
index
];
const
CharType
cur
=
begin
[
index
];
if
(
is_previous_hex
&&
IsXDigit
(
cur
))
{
if
(
is_previous_hex
&&
IsXDigit
(
cur
))
{
...
@@ -276,8 +278,13 @@ static void PrintCharsAsStringTo(
...
@@ -276,8 +278,13 @@ static void PrintCharsAsStringTo(
*
os
<<
"
\"
"
<<
kQuoteBegin
;
*
os
<<
"
\"
"
<<
kQuoteBegin
;
}
}
is_previous_hex
=
PrintAsStringLiteralTo
(
cur
,
os
)
==
kHexEscape
;
is_previous_hex
=
PrintAsStringLiteralTo
(
cur
,
os
)
==
kHexEscape
;
// Remember if any characters required hex escaping.
if
(
is_previous_hex
)
{
print_format
=
kHexEscape
;
}
}
}
*
os
<<
"
\"
"
;
*
os
<<
"
\"
"
;
return
print_format
;
}
}
// Prints a (const) char/wchar_t array of 'len' elements, starting at address
// Prints a (const) char/wchar_t array of 'len' elements, starting at address
...
@@ -347,15 +354,90 @@ void PrintTo(const wchar_t* s, ostream* os) {
...
@@ -347,15 +354,90 @@ void PrintTo(const wchar_t* s, ostream* os) {
}
}
#endif // wchar_t is native
#endif // wchar_t is native
namespace
{
bool
ContainsUnprintableControlCodes
(
const
char
*
str
,
size_t
length
)
{
const
unsigned
char
*
s
=
reinterpret_cast
<
const
unsigned
char
*>
(
str
);
for
(
size_t
i
=
0
;
i
<
length
;
i
++
)
{
unsigned
char
ch
=
*
s
++
;
if
(
std
::
iscntrl
(
ch
))
{
switch
(
ch
)
{
case
'\t'
:
case
'\n'
:
case
'\r'
:
break
;
default:
return
true
;
}
}
}
return
false
;
}
bool
IsUTF8TrailByte
(
unsigned
char
t
)
{
return
0x80
<=
t
&&
t
<=
0xbf
;
}
bool
IsValidUTF8
(
const
char
*
str
,
size_t
length
)
{
const
unsigned
char
*
s
=
reinterpret_cast
<
const
unsigned
char
*>
(
str
);
for
(
size_t
i
=
0
;
i
<
length
;)
{
unsigned
char
lead
=
s
[
i
++
];
if
(
lead
<=
0x7f
)
{
continue
;
// single-byte character (ASCII) 0..7F
}
if
(
lead
<
0xc2
)
{
return
false
;
// trail byte or non-shortest form
}
else
if
(
lead
<=
0xdf
&&
(
i
+
1
)
<=
length
&&
IsUTF8TrailByte
(
s
[
i
]))
{
++
i
;
// 2-byte character
}
else
if
(
0xe0
<=
lead
&&
lead
<=
0xef
&&
(
i
+
2
)
<=
length
&&
IsUTF8TrailByte
(
s
[
i
])
&&
IsUTF8TrailByte
(
s
[
i
+
1
])
&&
// check for non-shortest form and surrogate
(
lead
!=
0xe0
||
s
[
i
]
>=
0xa0
)
&&
(
lead
!=
0xed
||
s
[
i
]
<
0xa0
))
{
i
+=
2
;
// 3-byte character
}
else
if
(
0xf0
<=
lead
&&
lead
<=
0xf4
&&
(
i
+
3
)
<=
length
&&
IsUTF8TrailByte
(
s
[
i
])
&&
IsUTF8TrailByte
(
s
[
i
+
1
])
&&
IsUTF8TrailByte
(
s
[
i
+
2
])
&&
// check for non-shortest form
(
lead
!=
0xf0
||
s
[
i
]
>=
0x90
)
&&
(
lead
!=
0xf4
||
s
[
i
]
<
0x90
))
{
i
+=
3
;
// 4-byte character
}
else
{
return
false
;
}
}
return
true
;
}
void
ConditionalPrintAsText
(
const
char
*
str
,
size_t
length
,
ostream
*
os
)
{
if
(
!
ContainsUnprintableControlCodes
(
str
,
length
)
&&
IsValidUTF8
(
str
,
length
))
{
*
os
<<
"
\n
As Text:
\"
"
<<
str
<<
"
\"
"
;
}
}
}
// anonymous namespace
// Prints a ::string object.
// Prints a ::string object.
#if GTEST_HAS_GLOBAL_STRING
#if GTEST_HAS_GLOBAL_STRING
void
PrintStringTo
(
const
::
string
&
s
,
ostream
*
os
)
{
void
PrintStringTo
(
const
::
string
&
s
,
ostream
*
os
)
{
PrintCharsAsStringTo
(
s
.
data
(),
s
.
size
(),
os
);
if
(
PrintCharsAsStringTo
(
s
.
data
(),
s
.
size
(),
os
)
==
kHexEscape
)
{
if
(
GTEST_FLAG
(
print_utf8
))
{
ConditionalPrintAsText
(
s
.
data
(),
s
.
size
(),
os
);
}
}
}
}
#endif // GTEST_HAS_GLOBAL_STRING
#endif // GTEST_HAS_GLOBAL_STRING
void
PrintStringTo
(
const
::
std
::
string
&
s
,
ostream
*
os
)
{
void
PrintStringTo
(
const
::
std
::
string
&
s
,
ostream
*
os
)
{
PrintCharsAsStringTo
(
s
.
data
(),
s
.
size
(),
os
);
if
(
PrintCharsAsStringTo
(
s
.
data
(),
s
.
size
(),
os
)
==
kHexEscape
)
{
if
(
GTEST_FLAG
(
print_utf8
))
{
ConditionalPrintAsText
(
s
.
data
(),
s
.
size
(),
os
);
}
}
}
}
// Prints a ::wstring object.
// Prints a ::wstring object.
...
...
googletest/src/gtest-typed-test.cc
View file @
fc437ef4
...
@@ -30,6 +30,7 @@
...
@@ -30,6 +30,7 @@
// Author: wan@google.com (Zhanyong Wan)
// Author: wan@google.com (Zhanyong Wan)
#include "gtest/gtest-typed-test.h"
#include "gtest/gtest-typed-test.h"
#include "gtest/gtest.h"
#include "gtest/gtest.h"
namespace
testing
{
namespace
testing
{
...
...
googletest/src/gtest.cc
View file @
fc437ef4
This diff is collapsed.
Click to expand it.
googletest/test/BUILD.bazel
View file @
fc437ef4
...
@@ -119,6 +119,16 @@ cc_test(
...
@@ -119,6 +119,16 @@ cc_test(
"//:gtest"
,
"//:gtest"
,
],
],
)
)
cc_test
(
name
=
"gtest_unittest"
,
size
=
"small"
,
srcs
=
[
"gtest_unittest.cc"
],
args
=
[
"--heap_check=strict"
],
shard_count
=
2
,
deps
=
[
"//:gtest_main"
],
)
# Py tests
# Py tests
py_library
(
py_library
(
...
@@ -219,6 +229,13 @@ py_test(
...
@@ -219,6 +229,13 @@ py_test(
deps
=
[
":gtest_test_utils"
],
deps
=
[
":gtest_test_utils"
],
)
)
cc_test
(
name
=
"gtest_assert_by_exception_test"
,
size
=
"small"
,
srcs
=
[
"gtest_assert_by_exception_test.cc"
],
deps
=
[
"//:gtest"
],
)
cc_binary
(
cc_binary
(
name
=
"gtest_throw_on_failure_test_"
,
name
=
"gtest_throw_on_failure_test_"
,
testonly
=
1
,
testonly
=
1
,
...
...
googletest/test/gtest-death-test_test.cc
View file @
fc437ef4
...
@@ -617,7 +617,11 @@ TEST_F(TestForDeathTest, ReturnIsFailure) {
...
@@ -617,7 +617,11 @@ TEST_F(TestForDeathTest, ReturnIsFailure) {
TEST_F
(
TestForDeathTest
,
TestExpectDebugDeath
)
{
TEST_F
(
TestForDeathTest
,
TestExpectDebugDeath
)
{
int
sideeffect
=
0
;
int
sideeffect
=
0
;
EXPECT_DEBUG_DEATH
(
DieInDebugElse12
(
&
sideeffect
),
"death.*DieInDebugElse12"
)
// Put the regex in a local variable to make sure we don't get an "unused"
// warning in opt mode.
const
char
*
regex
=
"death.*DieInDebugElse12"
;
EXPECT_DEBUG_DEATH
(
DieInDebugElse12
(
&
sideeffect
),
regex
)
<<
"Must accept a streamed message"
;
<<
"Must accept a streamed message"
;
# ifdef NDEBUG
# ifdef NDEBUG
...
...
googletest/test/gtest-param-test_test.cc
View file @
fc437ef4
...
@@ -41,8 +41,8 @@
...
@@ -41,8 +41,8 @@
# include <sstream>
# include <sstream>
# include <string>
# include <string>
# include <vector>
# include <vector>
# include "src/gtest-internal-inl.h" // for UnitTestOptions
# include "src/gtest-internal-inl.h" // for UnitTestOptions
# include "test/gtest-param-test_test.h"
# include "test/gtest-param-test_test.h"
using
::
std
::
vector
;
using
::
std
::
vector
;
...
@@ -536,6 +536,51 @@ TEST(CombineTest, CombineWithMaxNumberOfParameters) {
...
@@ -536,6 +536,51 @@ TEST(CombineTest, CombineWithMaxNumberOfParameters) {
VerifyGenerator
(
gen
,
expected_values
);
VerifyGenerator
(
gen
,
expected_values
);
}
}
#if GTEST_LANG_CXX11
class
NonDefaultConstructAssignString
{
public:
NonDefaultConstructAssignString
(
const
std
::
string
&
s
)
:
str_
(
s
)
{}
const
std
::
string
&
str
()
const
{
return
str_
;
}
private:
std
::
string
str_
;
// Not default constructible
NonDefaultConstructAssignString
();
// Not assignable
void
operator
=
(
const
NonDefaultConstructAssignString
&
);
};
TEST
(
CombineTest
,
NonDefaultConstructAssign
)
{
const
ParamGenerator
<
tuple
<
int
,
NonDefaultConstructAssignString
>
>
gen
=
Combine
(
Values
(
0
,
1
),
Values
(
NonDefaultConstructAssignString
(
"A"
),
NonDefaultConstructAssignString
(
"B"
)));
ParamGenerator
<
tuple
<
int
,
NonDefaultConstructAssignString
>
>::
iterator
it
=
gen
.
begin
();
EXPECT_EQ
(
0
,
std
::
get
<
0
>
(
*
it
));
EXPECT_EQ
(
"A"
,
std
::
get
<
1
>
(
*
it
).
str
());
++
it
;
EXPECT_EQ
(
0
,
std
::
get
<
0
>
(
*
it
));
EXPECT_EQ
(
"B"
,
std
::
get
<
1
>
(
*
it
).
str
());
++
it
;
EXPECT_EQ
(
1
,
std
::
get
<
0
>
(
*
it
));
EXPECT_EQ
(
"A"
,
std
::
get
<
1
>
(
*
it
).
str
());
++
it
;
EXPECT_EQ
(
1
,
std
::
get
<
0
>
(
*
it
));
EXPECT_EQ
(
"B"
,
std
::
get
<
1
>
(
*
it
).
str
());
++
it
;
EXPECT_TRUE
(
it
==
gen
.
end
());
}
#endif // GTEST_LANG_CXX11
# endif // GTEST_HAS_COMBINE
# endif // GTEST_HAS_COMBINE
// Tests that an generator produces correct sequence after being
// Tests that an generator produces correct sequence after being
...
@@ -839,8 +884,8 @@ class CustomFunctorNamingTest : public TestWithParam<std::string> {};
...
@@ -839,8 +884,8 @@ class CustomFunctorNamingTest : public TestWithParam<std::string> {};
TEST_P
(
CustomFunctorNamingTest
,
CustomTestNames
)
{}
TEST_P
(
CustomFunctorNamingTest
,
CustomTestNames
)
{}
struct
CustomParamNameFunctor
{
struct
CustomParamNameFunctor
{
std
::
string
operator
()(
const
::
testing
::
TestParamInfo
<
std
::
string
>&
inf
o
)
{
std
::
string
operator
()(
const
::
testing
::
TestParamInfo
<
std
::
string
>&
inf
)
{
return
inf
o
.
param
;
return
inf
.
param
;
}
}
};
};
...
@@ -857,8 +902,8 @@ INSTANTIATE_TEST_CASE_P(AllAllowedCharacters,
...
@@ -857,8 +902,8 @@ INSTANTIATE_TEST_CASE_P(AllAllowedCharacters,
CustomParamNameFunctor
());
CustomParamNameFunctor
());
inline
std
::
string
CustomParamNameFunction
(
inline
std
::
string
CustomParamNameFunction
(
const
::
testing
::
TestParamInfo
<
std
::
string
>&
inf
o
)
{
const
::
testing
::
TestParamInfo
<
std
::
string
>&
inf
)
{
return
inf
o
.
param
;
return
inf
.
param
;
}
}
class
CustomFunctionNamingTest
:
public
TestWithParam
<
std
::
string
>
{};
class
CustomFunctionNamingTest
:
public
TestWithParam
<
std
::
string
>
{};
...
@@ -876,11 +921,10 @@ INSTANTIATE_TEST_CASE_P(CustomParamNameFunction,
...
@@ -876,11 +921,10 @@ INSTANTIATE_TEST_CASE_P(CustomParamNameFunction,
class
CustomLambdaNamingTest
:
public
TestWithParam
<
std
::
string
>
{};
class
CustomLambdaNamingTest
:
public
TestWithParam
<
std
::
string
>
{};
TEST_P
(
CustomLambdaNamingTest
,
CustomTestNames
)
{}
TEST_P
(
CustomLambdaNamingTest
,
CustomTestNames
)
{}
INSTANTIATE_TEST_CASE_P
(
CustomParamNameLambda
,
INSTANTIATE_TEST_CASE_P
(
CustomParamNameLambda
,
CustomLambdaNamingTest
,
CustomLambdaNamingTest
,
Values
(
std
::
string
(
"LambdaName"
)),
Values
(
std
::
string
(
"LambdaName"
)),
[](
const
::
testing
::
TestParamInfo
<
std
::
string
>&
tp
inf
o
)
{
[](
const
::
testing
::
TestParamInfo
<
std
::
string
>&
inf
)
{
return
tp
inf
o
.
param
;
return
inf
.
param
;
});
});
#endif // GTEST_LANG_CXX11
#endif // GTEST_LANG_CXX11
...
@@ -1047,6 +1091,7 @@ TEST_F(ParameterizedDeathTest, GetParamDiesFromTestF) {
...
@@ -1047,6 +1091,7 @@ TEST_F(ParameterizedDeathTest, GetParamDiesFromTestF) {
INSTANTIATE_TEST_CASE_P
(
RangeZeroToFive
,
ParameterizedDerivedTest
,
Range
(
0
,
5
));
INSTANTIATE_TEST_CASE_P
(
RangeZeroToFive
,
ParameterizedDerivedTest
,
Range
(
0
,
5
));
int
main
(
int
argc
,
char
**
argv
)
{
int
main
(
int
argc
,
char
**
argv
)
{
// Used in TestGenerationTest test case.
// Used in TestGenerationTest test case.
AddGlobalTestEnvironment
(
TestGenerationTest
::
Environment
::
Instance
());
AddGlobalTestEnvironment
(
TestGenerationTest
::
Environment
::
Instance
());
...
...
googletest/test/gtest-printers_test.cc
View file @
fc437ef4
...
@@ -239,7 +239,7 @@ using ::testing::internal::UniversalTersePrint;
...
@@ -239,7 +239,7 @@ using ::testing::internal::UniversalTersePrint;
#if GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_
#if GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_
using
::
testing
::
internal
::
UniversalTersePrintTupleFieldsToStrings
;
using
::
testing
::
internal
::
UniversalTersePrintTupleFieldsToStrings
;
#endif
#endif
using
::
testing
::
internal
::
string
;
// The hash_* classes are not part of the C++ standard. STLport
// The hash_* classes are not part of the C++ standard. STLport
// defines them in namespace std. MSVC defines them in ::stdext. GCC
// defines them in namespace std. MSVC defines them in ::stdext. GCC
...
@@ -837,22 +837,22 @@ TEST(PrintTypeWithGenericStreamingTest, TypeImplicitlyConvertible) {
...
@@ -837,22 +837,22 @@ TEST(PrintTypeWithGenericStreamingTest, TypeImplicitlyConvertible) {
EXPECT_EQ
(
"AllowsGenericStreamingAndImplicitConversionTemplate"
,
Print
(
a
));
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
)
{
TEST
(
PrintString
V
ie
w
Test
,
SimpleString
V
ie
w
)
{
const
StringPiece
sp
=
"Hello"
;
const
::
absl
::
string_view
sp
=
"Hello"
;
EXPECT_EQ
(
"
\"
Hello
\"
"
,
Print
(
sp
));
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
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
));
EXPECT_EQ
(
"
\"
NUL (
\\
0) and
\\
r
\\
t
\"
"
,
Print
(
sp
));
}
}
#endif // GTEST_HAS_
STRING_PIECE_
#endif // GTEST_HAS_
ABSL
// Tests printing STL containers.
// Tests printing STL containers.
...
@@ -1327,7 +1327,7 @@ TEST(FormatForComparisonFailureMessageTest, FormatsNonCharArrayAsPointer) {
...
@@ -1327,7 +1327,7 @@ TEST(FormatForComparisonFailureMessageTest, FormatsNonCharArrayAsPointer) {
}
}
// Tests formatting a char pointer when it's compared with another pointer.
// 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.
// pointer.
// char pointer vs pointer
// char pointer vs pointer
...
@@ -1552,6 +1552,78 @@ TEST(PrintToStringTest, WorksForCharArrayWithEmbeddedNul) {
...
@@ -1552,6 +1552,78 @@ TEST(PrintToStringTest, WorksForCharArrayWithEmbeddedNul) {
EXPECT_PRINT_TO_STRING_
(
mutable_str_with_nul
,
"
\"
hello
\\
0 world
\"
"
);
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_
#undef EXPECT_PRINT_TO_STRING_
TEST
(
UniversalTersePrintTest
,
WorksForNonReference
)
{
TEST
(
UniversalTersePrintTest
,
WorksForNonReference
)
{
...
@@ -1693,5 +1765,17 @@ TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsTersely) {
...
@@ -1693,5 +1765,17 @@ TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsTersely) {
#endif // GTEST_HAS_STD_TUPLE_
#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 gtest_printers_test
}
// namespace testing
}
// namespace testing
googletest/test/gtest_all_test.cc
View file @
fc437ef4
...
@@ -33,15 +33,15 @@
...
@@ -33,15 +33,15 @@
//
//
// Sometimes it's desirable to build most of Google Test's own tests
// Sometimes it's desirable to build most of Google Test's own tests
// by compiling a single file. This file serves this purpose.
// by compiling a single file. This file serves this purpose.
#include "
test/
gtest-filepath_test.cc"
#include "gtest-filepath_test.cc"
#include "
test/
gtest-linked_ptr_test.cc"
#include "gtest-linked_ptr_test.cc"
#include "
test/
gtest-message_test.cc"
#include "gtest-message_test.cc"
#include "
test/
gtest-options_test.cc"
#include "gtest-options_test.cc"
#include "
test/
gtest-port_test.cc"
#include "gtest-port_test.cc"
#include "
test/
gtest_pred_impl_unittest.cc"
#include "gtest_pred_impl_unittest.cc"
#include "
test/
gtest_prod_test.cc"
#include "gtest_prod_test.cc"
#include "
test/
gtest-test-part_test.cc"
#include "gtest-test-part_test.cc"
#include "
test/
gtest-typed-test_test.cc"
#include "gtest-typed-test_test.cc"
#include "
test/
gtest-typed-test2_test.cc"
#include "gtest-typed-test2_test.cc"
#include "
test/
gtest_unittest.cc"
#include "gtest_unittest.cc"
#include "
test/
production.cc"
#include "production.cc"
googletest/test/gtest_assert_by_exception_test.cc
0 → 100644
View file @
fc437ef4
// 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_env_var_test_.cc
View file @
fc437ef4
...
@@ -35,6 +35,7 @@
...
@@ -35,6 +35,7 @@
#include "gtest/gtest.h"
#include "gtest/gtest.h"
#include <iostream>
#include <iostream>
#include "src/gtest-internal-inl.h"
#include "src/gtest-internal-inl.h"
using
::
std
::
cout
;
using
::
std
::
cout
;
...
...
googletest/test/gtest_json_outfiles_test.py
0 → 100644
View file @
fc437ef4
#!/usr/bin/env python
# Copyright 2018, 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.
"""Unit test for the gtest_json_output module."""
import
json
import
os
import
gtest_json_test_utils
import
gtest_test_utils
GTEST_OUTPUT_SUBDIR
=
'json_outfiles'
GTEST_OUTPUT_1_TEST
=
'gtest_xml_outfile1_test_'
GTEST_OUTPUT_2_TEST
=
'gtest_xml_outfile2_test_'
EXPECTED_1
=
{
u
'tests'
:
1
,
u
'failures'
:
0
,
u
'disabled'
:
0
,
u
'errors'
:
0
,
u
'time'
:
u
'*'
,
u
'timestamp'
:
u
'*'
,
u
'name'
:
u
'AllTests'
,
u
'testsuites'
:
[{
u
'name'
:
u
'PropertyOne'
,
u
'tests'
:
1
,
u
'failures'
:
0
,
u
'disabled'
:
0
,
u
'errors'
:
0
,
u
'time'
:
u
'*'
,
u
'testsuite'
:
[{
u
'name'
:
u
'TestSomeProperties'
,
u
'status'
:
u
'RUN'
,
u
'time'
:
u
'*'
,
u
'classname'
:
u
'PropertyOne'
,
u
'SetUpProp'
:
u
'1'
,
u
'TestSomeProperty'
:
u
'1'
,
u
'TearDownProp'
:
u
'1'
,
}],
}],
}
EXPECTED_2
=
{
u
'tests'
:
1
,
u
'failures'
:
0
,
u
'disabled'
:
0
,
u
'errors'
:
0
,
u
'time'
:
u
'*'
,
u
'timestamp'
:
u
'*'
,
u
'name'
:
u
'AllTests'
,
u
'testsuites'
:
[{
u
'name'
:
u
'PropertyTwo'
,
u
'tests'
:
1
,
u
'failures'
:
0
,
u
'disabled'
:
0
,
u
'errors'
:
0
,
u
'time'
:
u
'*'
,
u
'testsuite'
:
[{
u
'name'
:
u
'TestSomeProperties'
,
u
'status'
:
u
'RUN'
,
u
'time'
:
u
'*'
,
u
'classname'
:
u
'PropertyTwo'
,
u
'SetUpProp'
:
u
'2'
,
u
'TestSomeProperty'
:
u
'2'
,
u
'TearDownProp'
:
u
'2'
,
}],
}],
}
class
GTestJsonOutFilesTest
(
gtest_test_utils
.
TestCase
):
"""Unit test for Google Test's JSON output functionality."""
def
setUp
(
self
):
# We want the trailing '/' that the last "" provides in os.path.join, for
# telling Google Test to create an output directory instead of a single file
# for xml output.
self
.
output_dir_
=
os
.
path
.
join
(
gtest_test_utils
.
GetTempDir
(),
GTEST_OUTPUT_SUBDIR
,
''
)
self
.
DeleteFilesAndDir
()
def
tearDown
(
self
):
self
.
DeleteFilesAndDir
()
def
DeleteFilesAndDir
(
self
):
try
:
os
.
remove
(
os
.
path
.
join
(
self
.
output_dir_
,
GTEST_OUTPUT_1_TEST
+
'.json'
))
except
os
.
error
:
pass
try
:
os
.
remove
(
os
.
path
.
join
(
self
.
output_dir_
,
GTEST_OUTPUT_2_TEST
+
'.json'
))
except
os
.
error
:
pass
try
:
os
.
rmdir
(
self
.
output_dir_
)
except
os
.
error
:
pass
def
testOutfile1
(
self
):
self
.
_TestOutFile
(
GTEST_OUTPUT_1_TEST
,
EXPECTED_1
)
def
testOutfile2
(
self
):
self
.
_TestOutFile
(
GTEST_OUTPUT_2_TEST
,
EXPECTED_2
)
def
_TestOutFile
(
self
,
test_name
,
expected
):
gtest_prog_path
=
gtest_test_utils
.
GetTestExecutablePath
(
test_name
)
command
=
[
gtest_prog_path
,
'--gtest_output=json:%s'
%
self
.
output_dir_
]
p
=
gtest_test_utils
.
Subprocess
(
command
,
working_dir
=
gtest_test_utils
.
GetTempDir
())
self
.
assert_
(
p
.
exited
)
self
.
assertEquals
(
0
,
p
.
exit_code
)
# TODO(wan@google.com): libtool causes the built test binary to be
# named lt-gtest_xml_outfiles_test_ instead of
# gtest_xml_outfiles_test_. To account for this possibility, we
# allow both names in the following code. We should remove this
# hack when Chandler Carruth's libtool replacement tool is ready.
output_file_name1
=
test_name
+
'.json'
output_file1
=
os
.
path
.
join
(
self
.
output_dir_
,
output_file_name1
)
output_file_name2
=
'lt-'
+
output_file_name1
output_file2
=
os
.
path
.
join
(
self
.
output_dir_
,
output_file_name2
)
self
.
assert_
(
os
.
path
.
isfile
(
output_file1
)
or
os
.
path
.
isfile
(
output_file2
),
output_file1
)
if
os
.
path
.
isfile
(
output_file1
):
with
open
(
output_file1
)
as
f
:
actual
=
json
.
load
(
f
)
else
:
with
open
(
output_file2
)
as
f
:
actual
=
json
.
load
(
f
)
self
.
assertEqual
(
expected
,
gtest_json_test_utils
.
normalize
(
actual
))
if
__name__
==
'__main__'
:
os
.
environ
[
'GTEST_STACK_TRACE_DEPTH'
]
=
'0'
gtest_test_utils
.
Main
()
googletest/test/gtest_json_output_unittest.py
0 → 100644
View file @
fc437ef4
This diff is collapsed.
Click to expand it.
googletest/test/gtest_json_test_utils.py
0 → 100644
View file @
fc437ef4
This diff is collapsed.
Click to expand it.
googletest/test/gtest_main_unittest.cc
View file @
fc437ef4
...
@@ -41,5 +41,5 @@ TEST(GTestMainTest, ShouldSucceed) {
...
@@ -41,5 +41,5 @@ TEST(GTestMainTest, ShouldSucceed) {
}
// namespace
}
// namespace
// We are using the main() function defined in
src/
gtest_main.cc, so
// We are using the main() function defined in gtest_main.cc, so
we
//
we
don't define it here.
// don't define it here.
googletest/test/gtest_uninitialized_test.py
View file @
fc437ef4
...
@@ -33,7 +33,6 @@
...
@@ -33,7 +33,6 @@
__author__
=
'wan@google.com (Zhanyong Wan)'
__author__
=
'wan@google.com (Zhanyong Wan)'
import
os
import
gtest_test_utils
import
gtest_test_utils
COMMAND
=
gtest_test_utils
.
GetTestExecutablePath
(
'gtest_uninitialized_test_'
)
COMMAND
=
gtest_test_utils
.
GetTestExecutablePath
(
'gtest_uninitialized_test_'
)
...
...
googletest/test/gtest_uninitialized_test_.cc
View file @
fc437ef4
...
@@ -34,7 +34,7 @@
...
@@ -34,7 +34,7 @@
TEST
(
DummyTest
,
Dummy
)
{
TEST
(
DummyTest
,
Dummy
)
{
// This test doesn't verify anything. We just need it to create a
// This test doesn't verify anything. We just need it to create a
// realistic stage for testing the behavior of Google Test when
// realistic stage for testing the behavior of Google Test when
// RUN_ALL_TESTS() is called without
// RUN_ALL_TESTS() is called without
// testing::InitGoogleTest() being called first.
// testing::InitGoogleTest() being called first.
}
}
...
...
googletest/test/gtest_unittest.cc
View file @
fc437ef4
This diff is collapsed.
Click to expand it.
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