Merge pull request #1417 from gennadiycivil/master
merges, cl/155419551 and others
This commit is contained in:
commit
3c5e064ca0
|
@ -687,6 +687,9 @@ class GTEST_API_ TestInfo {
|
||||||
// Returns the line where this test is defined.
|
// Returns the line where this test is defined.
|
||||||
int line() const { return location_.line; }
|
int line() const { return location_.line; }
|
||||||
|
|
||||||
|
// Return true if this test should not be run because it's in another shard.
|
||||||
|
bool is_in_another_shard() const { return is_in_another_shard_; }
|
||||||
|
|
||||||
// Returns true if this test should run, that is if the test is not
|
// Returns true if this test should run, that is if the test is not
|
||||||
// disabled (or it is disabled but the also_run_disabled_tests flag has
|
// disabled (or it is disabled but the also_run_disabled_tests flag has
|
||||||
// been specified) and its full name matches the user-specified filter.
|
// been specified) and its full name matches the user-specified filter.
|
||||||
|
@ -707,10 +710,9 @@ class GTEST_API_ TestInfo {
|
||||||
|
|
||||||
// Returns true iff this test will appear in the XML report.
|
// Returns true iff this test will appear in the XML report.
|
||||||
bool is_reportable() const {
|
bool is_reportable() const {
|
||||||
// The XML report includes tests matching the filter.
|
// The XML report includes tests matching the filter, excluding those
|
||||||
// In the future, we may trim tests that are excluded because of
|
// run in other shards.
|
||||||
// sharding.
|
return matches_filter_ && !is_in_another_shard_;
|
||||||
return matches_filter_;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the result of the test.
|
// Returns the result of the test.
|
||||||
|
@ -774,6 +776,7 @@ class GTEST_API_ TestInfo {
|
||||||
bool is_disabled_; // True iff this test is disabled
|
bool is_disabled_; // True iff this test is disabled
|
||||||
bool matches_filter_; // True if this test matches the
|
bool matches_filter_; // True if this test matches the
|
||||||
// user-specified filter.
|
// user-specified filter.
|
||||||
|
bool is_in_another_shard_; // Will be run in another shard.
|
||||||
internal::TestFactoryBase* const factory_; // The factory that creates
|
internal::TestFactoryBase* const factory_; // The factory that creates
|
||||||
// the test object
|
// the test object
|
||||||
|
|
||||||
|
|
|
@ -4813,10 +4813,11 @@ int UnitTestImpl::FilterTests(ReactionToSharding shard_tests) {
|
||||||
(GTEST_FLAG(also_run_disabled_tests) || !is_disabled) &&
|
(GTEST_FLAG(also_run_disabled_tests) || !is_disabled) &&
|
||||||
matches_filter;
|
matches_filter;
|
||||||
|
|
||||||
const bool is_selected = is_runnable &&
|
const bool is_in_another_shard =
|
||||||
(shard_tests == IGNORE_SHARDING_PROTOCOL ||
|
shard_tests != IGNORE_SHARDING_PROTOCOL &&
|
||||||
ShouldRunTestOnShard(total_shards, shard_index,
|
!ShouldRunTestOnShard(total_shards, shard_index, num_runnable_tests);
|
||||||
num_runnable_tests));
|
test_info->is_in_another_shard_ = is_in_another_shard;
|
||||||
|
const bool is_selected = is_runnable && !is_in_another_shard;
|
||||||
|
|
||||||
num_runnable_tests += is_runnable;
|
num_runnable_tests += is_runnable;
|
||||||
num_selected_tests += is_selected;
|
num_selected_tests += is_selected;
|
||||||
|
|
|
@ -67,7 +67,7 @@ namespace {
|
||||||
|
|
||||||
|
|
||||||
// Used for verifying that global environment set-up and tear-down are
|
// 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_set_up_count = 0;
|
||||||
int g_environment_tear_down_count = 0;
|
int g_environment_tear_down_count = 0;
|
||||||
|
|
|
@ -36,7 +36,6 @@ __author__ = 'wan@google.com (Zhanyong Wan)'
|
||||||
import os
|
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_')
|
||||||
|
|
||||||
|
|
||||||
|
@ -57,8 +56,8 @@ def TestExitCodeAndOutput(command):
|
||||||
|
|
||||||
# Verifies that 'command' exits with code 1.
|
# Verifies that 'command' exits with code 1.
|
||||||
p = gtest_test_utils.Subprocess(command)
|
p = gtest_test_utils.Subprocess(command)
|
||||||
Assert(p.exited)
|
if p.exited and p.exit_code == 0:
|
||||||
AssertEq(1, p.exit_code)
|
Assert('IMPORTANT NOTICE' in p.output);
|
||||||
Assert('InitGoogleTest' in p.output)
|
Assert('InitGoogleTest' in p.output)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -34,8 +34,8 @@
|
||||||
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 testing::InitGoogleTest() being
|
// RUN_ALL_TESTS() is called without
|
||||||
// called first.
|
// testing::InitGoogleTest() being called first.
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
|
|
@ -34,9 +34,9 @@
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
// Verifies that the command line flag variables can be accessed
|
// Verifies that the command line flag variables can be accessed in
|
||||||
// in code once <gtest/gtest.h> has been #included.
|
// code once "gtest/gtest.h" has been
|
||||||
// Do not move it after other #includes.
|
// #included. Do not move it after other gtest #includes.
|
||||||
TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded) {
|
TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded) {
|
||||||
bool dummy = testing::GTEST_FLAG(also_run_disabled_tests)
|
bool dummy = testing::GTEST_FLAG(also_run_disabled_tests)
|
||||||
|| testing::GTEST_FLAG(break_on_failure)
|
|| testing::GTEST_FLAG(break_on_failure)
|
||||||
|
|
|
@ -31,8 +31,6 @@
|
||||||
|
|
||||||
"""Unit test for the gtest_xml_output module"""
|
"""Unit test for the gtest_xml_output module"""
|
||||||
|
|
||||||
__author__ = 'eefacm@gmail.com (Sean Mcafee)'
|
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import errno
|
import errno
|
||||||
import os
|
import os
|
||||||
|
@ -43,12 +41,16 @@ from xml.dom import minidom, Node
|
||||||
import gtest_test_utils
|
import gtest_test_utils
|
||||||
import gtest_xml_test_utils
|
import gtest_xml_test_utils
|
||||||
|
|
||||||
|
|
||||||
GTEST_FILTER_FLAG = '--gtest_filter'
|
GTEST_FILTER_FLAG = '--gtest_filter'
|
||||||
GTEST_LIST_TESTS_FLAG = '--gtest_list_tests'
|
GTEST_LIST_TESTS_FLAG = '--gtest_list_tests'
|
||||||
GTEST_OUTPUT_FLAG = "--gtest_output"
|
GTEST_OUTPUT_FLAG = '--gtest_output'
|
||||||
GTEST_DEFAULT_OUTPUT_FILE = "test_detail.xml"
|
GTEST_DEFAULT_OUTPUT_FILE = 'test_detail.xml'
|
||||||
GTEST_PROGRAM_NAME = "gtest_xml_output_unittest_"
|
GTEST_PROGRAM_NAME = 'gtest_xml_output_unittest_'
|
||||||
|
|
||||||
|
# The environment variables for test sharding.
|
||||||
|
TOTAL_SHARDS_ENV_VAR = 'GTEST_TOTAL_SHARDS'
|
||||||
|
SHARD_INDEX_ENV_VAR = 'GTEST_SHARD_INDEX'
|
||||||
|
SHARD_STATUS_FILE_ENV_VAR = 'GTEST_SHARD_STATUS_FILE'
|
||||||
|
|
||||||
SUPPORTS_STACK_TRACES = False
|
SUPPORTS_STACK_TRACES = False
|
||||||
|
|
||||||
|
@ -141,6 +143,19 @@ EXPECTED_FILTERED_TEST_XML = """<?xml version="1.0" encoding="UTF-8"?>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
</testsuites>"""
|
</testsuites>"""
|
||||||
|
|
||||||
|
EXPECTED_SHARDED_TEST_XML = """<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<testsuites tests="3" failures="0" disabled="0" errors="0" time="*" timestamp="*" name="AllTests" ad_hoc_property="42">
|
||||||
|
<testsuite name="SuccessfulTest" tests="1" failures="0" disabled="0" errors="0" time="*">
|
||||||
|
<testcase name="Succeeds" status="run" time="*" classname="SuccessfulTest"/>
|
||||||
|
</testsuite>
|
||||||
|
<testsuite name="NoFixtureTest" tests="1" failures="0" disabled="0" errors="0" time="*">
|
||||||
|
<testcase name="RecordProperty" status="run" time="*" classname="NoFixtureTest" key="1"/>
|
||||||
|
</testsuite>
|
||||||
|
<testsuite name="Single/ValueParamTest" tests="1" failures="0" disabled="0" errors="0" time="*">
|
||||||
|
<testcase name="AnotherTestThatHasValueParamAttribute/1" value_param="42" status="run" time="*" classname="Single/ValueParamTest" />
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>"""
|
||||||
|
|
||||||
EXPECTED_EMPTY_XML = """<?xml version="1.0" encoding="UTF-8"?>
|
EXPECTED_EMPTY_XML = """<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<testsuites tests="0" failures="0" disabled="0" errors="0" time="*"
|
<testsuites tests="0" failures="0" disabled="0" errors="0" time="*"
|
||||||
timestamp="*" name="AllTests">
|
timestamp="*" name="AllTests">
|
||||||
|
@ -182,7 +197,7 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase):
|
||||||
Runs a test program that generates an empty XML output, and checks if
|
Runs a test program that generates an empty XML output, and checks if
|
||||||
the timestamp attribute in the testsuites tag is valid.
|
the timestamp attribute in the testsuites tag is valid.
|
||||||
"""
|
"""
|
||||||
actual = self._GetXmlOutput('gtest_no_test_unittest', [], 0)
|
actual = self._GetXmlOutput('gtest_no_test_unittest', [], {}, 0)
|
||||||
date_time_str = actual.documentElement.getAttributeNode('timestamp').value
|
date_time_str = actual.documentElement.getAttributeNode('timestamp').value
|
||||||
# datetime.strptime() is only available in Python 2.5+ so we have to
|
# datetime.strptime() is only available in Python 2.5+ so we have to
|
||||||
# parse the expected datetime manually.
|
# parse the expected datetime manually.
|
||||||
|
@ -212,8 +227,7 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase):
|
||||||
'gtest_no_test_unittest')
|
'gtest_no_test_unittest')
|
||||||
try:
|
try:
|
||||||
os.remove(output_file)
|
os.remove(output_file)
|
||||||
except OSError:
|
except OSError, e:
|
||||||
e = sys.exc_info()[1]
|
|
||||||
if e.errno != errno.ENOENT:
|
if e.errno != errno.ENOENT:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
@ -263,7 +277,22 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase):
|
||||||
self._TestXmlOutput(GTEST_PROGRAM_NAME, EXPECTED_FILTERED_TEST_XML, 0,
|
self._TestXmlOutput(GTEST_PROGRAM_NAME, EXPECTED_FILTERED_TEST_XML, 0,
|
||||||
extra_args=['%s=SuccessfulTest.*' % GTEST_FILTER_FLAG])
|
extra_args=['%s=SuccessfulTest.*' % GTEST_FILTER_FLAG])
|
||||||
|
|
||||||
def _GetXmlOutput(self, gtest_prog_name, extra_args, expected_exit_code):
|
def testShardedTestXmlOutput(self):
|
||||||
|
"""Verifies XML output when run using multiple shards.
|
||||||
|
|
||||||
|
Runs a test program that executes only one shard and verifies that tests
|
||||||
|
from other shards do not show up in the XML output.
|
||||||
|
"""
|
||||||
|
|
||||||
|
self._TestXmlOutput(
|
||||||
|
GTEST_PROGRAM_NAME,
|
||||||
|
EXPECTED_SHARDED_TEST_XML,
|
||||||
|
0,
|
||||||
|
extra_env={SHARD_INDEX_ENV_VAR: '0',
|
||||||
|
TOTAL_SHARDS_ENV_VAR: '10'})
|
||||||
|
|
||||||
|
def _GetXmlOutput(self, gtest_prog_name, extra_args, extra_env,
|
||||||
|
expected_exit_code):
|
||||||
"""
|
"""
|
||||||
Returns the xml output generated by running the program gtest_prog_name.
|
Returns the xml output generated by running the program gtest_prog_name.
|
||||||
Furthermore, the program's exit code must be expected_exit_code.
|
Furthermore, the program's exit code must be expected_exit_code.
|
||||||
|
@ -274,7 +303,11 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase):
|
||||||
|
|
||||||
command = ([gtest_prog_path, '%s=xml:%s' % (GTEST_OUTPUT_FLAG, xml_path)] +
|
command = ([gtest_prog_path, '%s=xml:%s' % (GTEST_OUTPUT_FLAG, xml_path)] +
|
||||||
extra_args)
|
extra_args)
|
||||||
p = gtest_test_utils.Subprocess(command)
|
environ_copy = os.environ.copy()
|
||||||
|
if extra_env:
|
||||||
|
environ_copy.update(extra_env)
|
||||||
|
p = gtest_test_utils.Subprocess(command, env=environ_copy)
|
||||||
|
|
||||||
if p.terminated_by_signal:
|
if p.terminated_by_signal:
|
||||||
self.assert_(False,
|
self.assert_(False,
|
||||||
'%s was killed by signal %d' % (gtest_prog_name, p.signal))
|
'%s was killed by signal %d' % (gtest_prog_name, p.signal))
|
||||||
|
@ -288,7 +321,7 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase):
|
||||||
return actual
|
return actual
|
||||||
|
|
||||||
def _TestXmlOutput(self, gtest_prog_name, expected_xml,
|
def _TestXmlOutput(self, gtest_prog_name, expected_xml,
|
||||||
expected_exit_code, extra_args=None):
|
expected_exit_code, extra_args=None, extra_env=None):
|
||||||
"""
|
"""
|
||||||
Asserts that the XML document generated by running the program
|
Asserts that the XML document generated by running the program
|
||||||
gtest_prog_name matches expected_xml, a string containing another
|
gtest_prog_name matches expected_xml, a string containing another
|
||||||
|
@ -297,7 +330,7 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
actual = self._GetXmlOutput(gtest_prog_name, extra_args or [],
|
actual = self._GetXmlOutput(gtest_prog_name, extra_args or [],
|
||||||
expected_exit_code)
|
extra_env or {}, expected_exit_code)
|
||||||
expected = minidom.parseString(expected_xml)
|
expected = minidom.parseString(expected_xml)
|
||||||
self.NormalizeXml(actual.documentElement)
|
self.NormalizeXml(actual.documentElement)
|
||||||
self.AssertEquivalentNodes(expected.documentElement,
|
self.AssertEquivalentNodes(expected.documentElement,
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
#
|
|
||||||
# Copyright 2006, Google Inc.
|
# Copyright 2006, Google Inc.
|
||||||
# All rights reserved.
|
# All rights reserved.
|
||||||
#
|
#
|
||||||
|
@ -31,15 +29,12 @@
|
||||||
|
|
||||||
"""Unit test utilities for gtest_xml_output"""
|
"""Unit test utilities for gtest_xml_output"""
|
||||||
|
|
||||||
__author__ = 'eefacm@gmail.com (Sean Mcafee)'
|
import os
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
import gtest_test_utils
|
||||||
from xml.dom import minidom, Node
|
from xml.dom import minidom, Node
|
||||||
|
|
||||||
import gtest_test_utils
|
|
||||||
|
|
||||||
|
|
||||||
GTEST_OUTPUT_FLAG = '--gtest_output'
|
|
||||||
GTEST_DEFAULT_OUTPUT_FILE = 'test_detail.xml'
|
GTEST_DEFAULT_OUTPUT_FILE = 'test_detail.xml'
|
||||||
|
|
||||||
class GTestXMLTestCase(gtest_test_utils.TestCase):
|
class GTestXMLTestCase(gtest_test_utils.TestCase):
|
||||||
|
@ -101,7 +96,7 @@ class GTestXMLTestCase(gtest_test_utils.TestCase):
|
||||||
self.assertEquals(
|
self.assertEquals(
|
||||||
len(expected_children), len(actual_children),
|
len(expected_children), len(actual_children),
|
||||||
'number of child elements differ in element ' + actual_node.tagName)
|
'number of child elements differ in element ' + actual_node.tagName)
|
||||||
for child_id, child in expected_children.items():
|
for child_id, child in expected_children.iteritems():
|
||||||
self.assert_(child_id in actual_children,
|
self.assert_(child_id in actual_children,
|
||||||
'<%s> is not in <%s> (in element %s)' %
|
'<%s> is not in <%s> (in element %s)' %
|
||||||
(child_id, actual_children, actual_node.tagName))
|
(child_id, actual_children, actual_node.tagName))
|
||||||
|
@ -187,8 +182,8 @@ class GTestXMLTestCase(gtest_test_utils.TestCase):
|
||||||
# Replaces the source line information with a normalized form.
|
# Replaces the source line information with a normalized form.
|
||||||
cdata = re.sub(source_line_pat, '\\1*\n', child.nodeValue)
|
cdata = re.sub(source_line_pat, '\\1*\n', child.nodeValue)
|
||||||
# Removes the actual stack trace.
|
# Removes the actual stack trace.
|
||||||
child.nodeValue = re.sub(r'\nStack trace:\n(.|\n)*',
|
child.nodeValue = re.sub(r'Stack trace:\n(.|\n)*',
|
||||||
'', cdata)
|
'Stack trace:\n*', cdata)
|
||||||
for child in element.childNodes:
|
for child in element.childNodes:
|
||||||
if child.nodeType == Node.ELEMENT_NODE:
|
if child.nodeType == Node.ELEMENT_NODE:
|
||||||
self.NormalizeXml(child)
|
self.NormalizeXml(child)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user