Commit a9f380f5 by zhanyong.wan

Removes the Windows golden file (by Vlad Losev); implements test result…

Removes the Windows golden file (by Vlad Losev); implements test result streaming (by Nikhil Jindal and cleaned up by Zhanyong Wan).
parent b83585c4
...@@ -102,7 +102,6 @@ EXTRA_DIST += \ ...@@ -102,7 +102,6 @@ EXTRA_DIST += \
test/gtest_list_tests_unittest.py \ test/gtest_list_tests_unittest.py \
test/gtest_output_test.py \ test/gtest_output_test.py \
test/gtest_output_test_golden_lin.txt \ test/gtest_output_test_golden_lin.txt \
test/gtest_output_test_golden_win.txt \
test/gtest_shuffle_test.py \ test/gtest_shuffle_test.py \
test/gtest_test_utils.py \ test/gtest_test_utils.py \
test/gtest_throw_on_failure_test.py \ test/gtest_throw_on_failure_test.py \
......
...@@ -137,6 +137,11 @@ GTEST_DECLARE_int32_(stack_trace_depth); ...@@ -137,6 +137,11 @@ GTEST_DECLARE_int32_(stack_trace_depth);
// non-zero code otherwise. // non-zero code otherwise.
GTEST_DECLARE_bool_(throw_on_failure); GTEST_DECLARE_bool_(throw_on_failure);
// When this flag is set with a "host:port" string, on supported
// platforms test results are streamed to the specified port on
// the specified host machine.
GTEST_DECLARE_string_(stream_result_to);
// The upper limit for valid stack trace depths. // The upper limit for valid stack trace depths.
const int kMaxStackTraceDepth = 100; const int kMaxStackTraceDepth = 100;
...@@ -155,8 +160,6 @@ class WindowsDeathTest; ...@@ -155,8 +160,6 @@ class WindowsDeathTest;
class UnitTestImpl* GetUnitTestImpl(); class UnitTestImpl* GetUnitTestImpl();
void ReportFailureInUnknownLocation(TestPartResult::Type result_type, void ReportFailureInUnknownLocation(TestPartResult::Type result_type,
const String& message); const String& message);
class PrettyUnitTestResultPrinter;
class XmlUnitTestResultPrinter;
// Converts a streamable value to a String. A NULL pointer is // Converts a streamable value to a String. A NULL pointer is
// converted to "(null)". When the input value is a ::string, // converted to "(null)". When the input value is a ::string,
......
...@@ -537,6 +537,11 @@ ...@@ -537,6 +537,11 @@
#define GTEST_WIDE_STRING_USES_UTF16_ \ #define GTEST_WIDE_STRING_USES_UTF16_ \
(GTEST_OS_WINDOWS || GTEST_OS_CYGWIN || GTEST_OS_SYMBIAN || GTEST_OS_AIX) (GTEST_OS_WINDOWS || GTEST_OS_CYGWIN || GTEST_OS_SYMBIAN || GTEST_OS_AIX)
// Determines whether test results can be streamed to a socket.
#if GTEST_OS_LINUX
#define GTEST_CAN_STREAM_RESULTS_ 1
#endif
// Defines some utility macros. // Defines some utility macros.
// The GNU compiler emits a warning if nested "if" statements are followed by // The GNU compiler emits a warning if nested "if" statements are followed by
......
...@@ -93,6 +93,7 @@ const char kRandomSeedFlag[] = "random_seed"; ...@@ -93,6 +93,7 @@ const char kRandomSeedFlag[] = "random_seed";
const char kRepeatFlag[] = "repeat"; const char kRepeatFlag[] = "repeat";
const char kShuffleFlag[] = "shuffle"; const char kShuffleFlag[] = "shuffle";
const char kStackTraceDepthFlag[] = "stack_trace_depth"; const char kStackTraceDepthFlag[] = "stack_trace_depth";
const char kStreamResultToFlag[] = "stream_result_to";
const char kThrowOnFailureFlag[] = "throw_on_failure"; const char kThrowOnFailureFlag[] = "throw_on_failure";
// A valid random seed must be in [1, kMaxRandomSeed]. // A valid random seed must be in [1, kMaxRandomSeed].
...@@ -165,6 +166,7 @@ class GTestFlagSaver { ...@@ -165,6 +166,7 @@ class GTestFlagSaver {
repeat_ = GTEST_FLAG(repeat); repeat_ = GTEST_FLAG(repeat);
shuffle_ = GTEST_FLAG(shuffle); shuffle_ = GTEST_FLAG(shuffle);
stack_trace_depth_ = GTEST_FLAG(stack_trace_depth); stack_trace_depth_ = GTEST_FLAG(stack_trace_depth);
stream_result_to_ = GTEST_FLAG(stream_result_to);
throw_on_failure_ = GTEST_FLAG(throw_on_failure); throw_on_failure_ = GTEST_FLAG(throw_on_failure);
} }
...@@ -185,6 +187,7 @@ class GTestFlagSaver { ...@@ -185,6 +187,7 @@ class GTestFlagSaver {
GTEST_FLAG(repeat) = repeat_; GTEST_FLAG(repeat) = repeat_;
GTEST_FLAG(shuffle) = shuffle_; GTEST_FLAG(shuffle) = shuffle_;
GTEST_FLAG(stack_trace_depth) = stack_trace_depth_; GTEST_FLAG(stack_trace_depth) = stack_trace_depth_;
GTEST_FLAG(stream_result_to) = stream_result_to_;
GTEST_FLAG(throw_on_failure) = throw_on_failure_; GTEST_FLAG(throw_on_failure) = throw_on_failure_;
} }
private: private:
...@@ -205,6 +208,7 @@ class GTestFlagSaver { ...@@ -205,6 +208,7 @@ class GTestFlagSaver {
internal::Int32 repeat_; internal::Int32 repeat_;
bool shuffle_; bool shuffle_;
internal::Int32 stack_trace_depth_; internal::Int32 stack_trace_depth_;
String stream_result_to_;
bool throw_on_failure_; bool throw_on_failure_;
} GTEST_ATTRIBUTE_UNUSED_; } GTEST_ATTRIBUTE_UNUSED_;
...@@ -741,6 +745,12 @@ class GTEST_API_ UnitTestImpl { ...@@ -741,6 +745,12 @@ class GTEST_API_ UnitTestImpl {
// UnitTestOptions. Must not be called before InitGoogleTest. // UnitTestOptions. Must not be called before InitGoogleTest.
void ConfigureXmlOutput(); void ConfigureXmlOutput();
#if GTEST_CAN_STREAM_RESULTS_
// Initializes the event listener for streaming test results to a socket.
// Must not be called before InitGoogleTest.
void ConfigureStreamingOutput();
#endif
// Performs initialization dependent upon flag values obtained in // Performs initialization dependent upon flag values obtained in
// ParseGoogleTestFlagsOnly. Is called from InitGoogleTest after the call to // ParseGoogleTestFlagsOnly. Is called from InitGoogleTest after the call to
// ParseGoogleTestFlagsOnly. In case a user neglects to call InitGoogleTest // ParseGoogleTestFlagsOnly. In case a user neglects to call InitGoogleTest
......
...@@ -44,12 +44,13 @@ import re ...@@ -44,12 +44,13 @@ import re
import gtest_test_utils import gtest_test_utils
IS_LINUX = os.name == 'posix' and os.uname()[0] == 'Linux'
IS_WINDOWS = os.name == 'nt' IS_WINDOWS = os.name == 'nt'
PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath('gtest_help_test_') PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath('gtest_help_test_')
FLAG_PREFIX = '--gtest_' FLAG_PREFIX = '--gtest_'
CATCH_EXCEPTIONS_FLAG = FLAG_PREFIX + 'catch_exceptions'
DEATH_TEST_STYLE_FLAG = FLAG_PREFIX + 'death_test_style' DEATH_TEST_STYLE_FLAG = FLAG_PREFIX + 'death_test_style'
STREAM_RESULT_TO_FLAG = FLAG_PREFIX + 'stream_result_to'
UNKNOWN_FLAG = FLAG_PREFIX + 'unknown_flag_for_testing' UNKNOWN_FLAG = FLAG_PREFIX + 'unknown_flag_for_testing'
LIST_TESTS_FLAG = FLAG_PREFIX + 'list_tests' LIST_TESTS_FLAG = FLAG_PREFIX + 'list_tests'
INCORRECT_FLAG_VARIANTS = [re.sub('^--', '-', LIST_TESTS_FLAG), INCORRECT_FLAG_VARIANTS = [re.sub('^--', '-', LIST_TESTS_FLAG),
...@@ -72,7 +73,8 @@ HELP_REGEX = re.compile( ...@@ -72,7 +73,8 @@ HELP_REGEX = re.compile(
FLAG_PREFIX + r'print_time.*' + FLAG_PREFIX + r'print_time.*' +
FLAG_PREFIX + r'output=.*' + FLAG_PREFIX + r'output=.*' +
FLAG_PREFIX + r'break_on_failure.*' + FLAG_PREFIX + r'break_on_failure.*' +
FLAG_PREFIX + r'throw_on_failure.*', FLAG_PREFIX + r'throw_on_failure.*' +
FLAG_PREFIX + r'catch_exceptions.*',
re.DOTALL) re.DOTALL)
...@@ -109,10 +111,11 @@ class GTestHelpTest(gtest_test_utils.TestCase): ...@@ -109,10 +111,11 @@ class GTestHelpTest(gtest_test_utils.TestCase):
exit_code, output = RunWithFlag(flag) exit_code, output = RunWithFlag(flag)
self.assertEquals(0, exit_code) self.assertEquals(0, exit_code)
self.assert_(HELP_REGEX.search(output), output) self.assert_(HELP_REGEX.search(output), output)
if IS_WINDOWS:
self.assert_(CATCH_EXCEPTIONS_FLAG in output, output) if IS_LINUX:
self.assert_(STREAM_RESULT_TO_FLAG in output, output)
else: else:
self.assert_(CATCH_EXCEPTIONS_FLAG not in output, output) self.assert_(STREAM_RESULT_TO_FLAG not in output, output)
if SUPPORTS_DEATH_TESTS and not IS_WINDOWS: if SUPPORTS_DEATH_TESTS and not IS_WINDOWS:
self.assert_(DEATH_TEST_STYLE_FLAG in output, output) self.assert_(DEATH_TEST_STYLE_FLAG in output, output)
......
...@@ -52,10 +52,8 @@ CATCH_EXCEPTIONS_ENV_VAR_NAME = 'GTEST_CATCH_EXCEPTIONS' ...@@ -52,10 +52,8 @@ CATCH_EXCEPTIONS_ENV_VAR_NAME = 'GTEST_CATCH_EXCEPTIONS'
IS_WINDOWS = os.name == 'nt' IS_WINDOWS = os.name == 'nt'
if IS_WINDOWS: # TODO(vladl@google.com): remove the _lin suffix.
GOLDEN_NAME = 'gtest_output_test_golden_win.txt' GOLDEN_NAME = 'gtest_output_test_golden_lin.txt'
else:
GOLDEN_NAME = 'gtest_output_test_golden_lin.txt'
PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath('gtest_output_test_') PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath('gtest_output_test_')
...@@ -138,6 +136,20 @@ def RemoveTypeInfoDetails(test_output): ...@@ -138,6 +136,20 @@ def RemoveTypeInfoDetails(test_output):
return re.sub(r'unsigned int', 'unsigned', test_output) return re.sub(r'unsigned int', 'unsigned', test_output)
def NormalizeToCurrentPlatform(test_output):
"""Normalizes platform specific output details for easier comparison."""
if IS_WINDOWS:
# Removes the color information that is not present on Windows.
test_output = re.sub('\x1b\\[(0;3\d)?m', '', test_output)
# Changes failure message headers into the Windows format.
test_output = re.sub(r': Failure\n', r': error: ', test_output)
# Changes file(line_number) to file:line_number.
test_output = re.sub(r'((\w|\.)+)\((\d+)\):', r'\1:\3:', test_output)
return test_output
def RemoveTestCounts(output): def RemoveTestCounts(output):
"""Removes test counts from a Google Test program's output.""" """Removes test counts from a Google Test program's output."""
...@@ -240,7 +252,7 @@ SUPPORTS_STACK_TRACES = False ...@@ -240,7 +252,7 @@ SUPPORTS_STACK_TRACES = False
CAN_GENERATE_GOLDEN_FILE = (SUPPORTS_DEATH_TESTS and CAN_GENERATE_GOLDEN_FILE = (SUPPORTS_DEATH_TESTS and
SUPPORTS_TYPED_TESTS and SUPPORTS_TYPED_TESTS and
(SUPPORTS_THREADS or IS_WINDOWS)) SUPPORTS_THREADS)
class GTestOutputTest(gtest_test_utils.TestCase): class GTestOutputTest(gtest_test_utils.TestCase):
...@@ -284,9 +296,10 @@ class GTestOutputTest(gtest_test_utils.TestCase): ...@@ -284,9 +296,10 @@ class GTestOutputTest(gtest_test_utils.TestCase):
if CAN_GENERATE_GOLDEN_FILE: if CAN_GENERATE_GOLDEN_FILE:
self.assertEqual(normalized_golden, normalized_actual) self.assertEqual(normalized_golden, normalized_actual)
else: else:
normalized_actual = RemoveTestCounts(normalized_actual) normalized_actual = NormalizeToCurrentPlatform(
normalized_golden = RemoveTestCounts(self.RemoveUnsupportedTests( RemoveTestCounts(normalized_actual))
normalized_golden)) normalized_golden = NormalizeToCurrentPlatform(
RemoveTestCounts(self.RemoveUnsupportedTests(normalized_golden)))
# This code is very handy when debugging golden file differences: # This code is very handy when debugging golden file differences:
if os.getenv('DEBUG_GTEST_OUTPUT_TEST'): if os.getenv('DEBUG_GTEST_OUTPUT_TEST'):
...@@ -312,14 +325,9 @@ if __name__ == '__main__': ...@@ -312,14 +325,9 @@ if __name__ == '__main__':
else: else:
message = ( message = (
"""Unable to write a golden file when compiled in an environment """Unable to write a golden file when compiled in an environment
that does not support all the required features (death tests""") that does not support all the required features (death tests, typed tests,
if IS_WINDOWS: and multiple threads). Please generate the golden file using a binary built
message += ( with those features enabled.""")
"""\nand typed tests). Please check that you are using VC++ 8.0 SP1
or higher as your compiler.""")
else:
message += """\ntyped tests, and threads). Please generate the
golden file using a binary built with those features enabled."""
sys.stderr.write(message) sys.stderr.write(message)
sys.exit(1) sys.exit(1)
......
...@@ -52,6 +52,7 @@ TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded) { ...@@ -52,6 +52,7 @@ TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded) {
|| testing::GTEST_FLAG(show_internal_stack_frames) || testing::GTEST_FLAG(show_internal_stack_frames)
|| testing::GTEST_FLAG(shuffle) || testing::GTEST_FLAG(shuffle)
|| testing::GTEST_FLAG(stack_trace_depth) > 0 || testing::GTEST_FLAG(stack_trace_depth) > 0
|| testing::GTEST_FLAG(stream_result_to) != "unknown"
|| testing::GTEST_FLAG(throw_on_failure); || testing::GTEST_FLAG(throw_on_failure);
EXPECT_TRUE(dummy || !dummy); // Suppresses warning that dummy is unused. EXPECT_TRUE(dummy || !dummy); // Suppresses warning that dummy is unused.
} }
...@@ -125,6 +126,7 @@ using testing::GTEST_FLAG(repeat); ...@@ -125,6 +126,7 @@ using testing::GTEST_FLAG(repeat);
using testing::GTEST_FLAG(show_internal_stack_frames); using testing::GTEST_FLAG(show_internal_stack_frames);
using testing::GTEST_FLAG(shuffle); using testing::GTEST_FLAG(shuffle);
using testing::GTEST_FLAG(stack_trace_depth); using testing::GTEST_FLAG(stack_trace_depth);
using testing::GTEST_FLAG(stream_result_to);
using testing::GTEST_FLAG(throw_on_failure); using testing::GTEST_FLAG(throw_on_failure);
using testing::IsNotSubstring; using testing::IsNotSubstring;
using testing::IsSubstring; using testing::IsSubstring;
...@@ -1718,6 +1720,7 @@ class GTestFlagSaverTest : public Test { ...@@ -1718,6 +1720,7 @@ class GTestFlagSaverTest : public Test {
GTEST_FLAG(repeat) = 1; GTEST_FLAG(repeat) = 1;
GTEST_FLAG(shuffle) = false; GTEST_FLAG(shuffle) = false;
GTEST_FLAG(stack_trace_depth) = kMaxStackTraceDepth; GTEST_FLAG(stack_trace_depth) = kMaxStackTraceDepth;
GTEST_FLAG(stream_result_to) = "";
GTEST_FLAG(throw_on_failure) = false; GTEST_FLAG(throw_on_failure) = false;
} }
...@@ -1744,6 +1747,7 @@ class GTestFlagSaverTest : public Test { ...@@ -1744,6 +1747,7 @@ class GTestFlagSaverTest : public Test {
EXPECT_EQ(1, GTEST_FLAG(repeat)); EXPECT_EQ(1, GTEST_FLAG(repeat));
EXPECT_FALSE(GTEST_FLAG(shuffle)); EXPECT_FALSE(GTEST_FLAG(shuffle));
EXPECT_EQ(kMaxStackTraceDepth, GTEST_FLAG(stack_trace_depth)); EXPECT_EQ(kMaxStackTraceDepth, GTEST_FLAG(stack_trace_depth));
EXPECT_STREQ("", GTEST_FLAG(stream_result_to).c_str());
EXPECT_FALSE(GTEST_FLAG(throw_on_failure)); EXPECT_FALSE(GTEST_FLAG(throw_on_failure));
GTEST_FLAG(also_run_disabled_tests) = true; GTEST_FLAG(also_run_disabled_tests) = true;
...@@ -1759,6 +1763,7 @@ class GTestFlagSaverTest : public Test { ...@@ -1759,6 +1763,7 @@ class GTestFlagSaverTest : public Test {
GTEST_FLAG(repeat) = 100; GTEST_FLAG(repeat) = 100;
GTEST_FLAG(shuffle) = true; GTEST_FLAG(shuffle) = true;
GTEST_FLAG(stack_trace_depth) = 1; GTEST_FLAG(stack_trace_depth) = 1;
GTEST_FLAG(stream_result_to) = "localhost:1234";
GTEST_FLAG(throw_on_failure) = true; GTEST_FLAG(throw_on_failure) = true;
} }
private: private:
...@@ -5142,6 +5147,7 @@ struct Flags { ...@@ -5142,6 +5147,7 @@ struct Flags {
repeat(1), repeat(1),
shuffle(false), shuffle(false),
stack_trace_depth(kMaxStackTraceDepth), stack_trace_depth(kMaxStackTraceDepth),
stream_result_to(""),
throw_on_failure(false) {} throw_on_failure(false) {}
// Factory methods. // Factory methods.
...@@ -5242,6 +5248,14 @@ struct Flags { ...@@ -5242,6 +5248,14 @@ struct Flags {
return flags; return flags;
} }
// Creates a Flags struct where the GTEST_FLAG(stream_result_to) flag has
// the given value.
static Flags StreamResultTo(const char* stream_result_to) {
Flags flags;
flags.stream_result_to = stream_result_to;
return flags;
}
// Creates a Flags struct where the gtest_throw_on_failure flag has // Creates a Flags struct where the gtest_throw_on_failure flag has
// the given value. // the given value.
static Flags ThrowOnFailure(bool throw_on_failure) { static Flags ThrowOnFailure(bool throw_on_failure) {
...@@ -5263,6 +5277,7 @@ struct Flags { ...@@ -5263,6 +5277,7 @@ struct Flags {
Int32 repeat; Int32 repeat;
bool shuffle; bool shuffle;
Int32 stack_trace_depth; Int32 stack_trace_depth;
const char* stream_result_to;
bool throw_on_failure; bool throw_on_failure;
}; };
...@@ -5283,6 +5298,7 @@ class InitGoogleTestTest : public Test { ...@@ -5283,6 +5298,7 @@ class InitGoogleTestTest : public Test {
GTEST_FLAG(repeat) = 1; GTEST_FLAG(repeat) = 1;
GTEST_FLAG(shuffle) = false; GTEST_FLAG(shuffle) = false;
GTEST_FLAG(stack_trace_depth) = kMaxStackTraceDepth; GTEST_FLAG(stack_trace_depth) = kMaxStackTraceDepth;
GTEST_FLAG(stream_result_to) = "";
GTEST_FLAG(throw_on_failure) = false; GTEST_FLAG(throw_on_failure) = false;
} }
...@@ -5311,8 +5327,10 @@ class InitGoogleTestTest : public Test { ...@@ -5311,8 +5327,10 @@ class InitGoogleTestTest : public Test {
EXPECT_EQ(expected.random_seed, GTEST_FLAG(random_seed)); EXPECT_EQ(expected.random_seed, GTEST_FLAG(random_seed));
EXPECT_EQ(expected.repeat, GTEST_FLAG(repeat)); EXPECT_EQ(expected.repeat, GTEST_FLAG(repeat));
EXPECT_EQ(expected.shuffle, GTEST_FLAG(shuffle)); EXPECT_EQ(expected.shuffle, GTEST_FLAG(shuffle));
EXPECT_EQ(expected.throw_on_failure, GTEST_FLAG(throw_on_failure));
EXPECT_EQ(expected.stack_trace_depth, GTEST_FLAG(stack_trace_depth)); EXPECT_EQ(expected.stack_trace_depth, GTEST_FLAG(stack_trace_depth));
EXPECT_STREQ(expected.stream_result_to,
GTEST_FLAG(stream_result_to).c_str());
EXPECT_EQ(expected.throw_on_failure, GTEST_FLAG(throw_on_failure));
} }
// Parses a command line (specified by argc1 and argv1), then // Parses a command line (specified by argc1 and argv1), then
...@@ -5973,6 +5991,22 @@ TEST_F(InitGoogleTestTest, StackTraceDepth) { ...@@ -5973,6 +5991,22 @@ TEST_F(InitGoogleTestTest, StackTraceDepth) {
GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::StackTraceDepth(5), false); GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::StackTraceDepth(5), false);
} }
TEST_F(InitGoogleTestTest, StreamResultTo) {
const char* argv[] = {
"foo.exe",
"--gtest_stream_result_to=localhost:1234",
NULL
};
const char* argv2[] = {
"foo.exe",
NULL
};
GTEST_TEST_PARSING_FLAGS_(
argv, argv2, Flags::StreamResultTo("localhost:1234"), false);
}
// Tests parsing --gtest_throw_on_failure. // Tests parsing --gtest_throw_on_failure.
TEST_F(InitGoogleTestTest, ThrowOnFailureWithoutValue) { TEST_F(InitGoogleTestTest, ThrowOnFailureWithoutValue) {
const char* argv[] = { const char* argv[] = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment