Formatting
This commit is contained in:
parent
6a357225af
commit
8cb6f62ec9
|
@ -28,7 +28,6 @@
|
||||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
"""Unit test for Google Test's --gtest_list_tests flag.
|
"""Unit test for Google Test's --gtest_list_tests flag.
|
||||||
|
|
||||||
A user can ask Google Test to list all tests by specifying the
|
A user can ask Google Test to list all tests by specifying the
|
||||||
|
@ -42,13 +41,11 @@ This script tests such functionality by invoking gtest_list_output_unittest_
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import gtest_test_utils
|
import gtest_test_utils
|
||||||
import gtest_xml_test_utils
|
|
||||||
|
|
||||||
GTEST_LIST_TESTS_FLAG = '--gtest_list_tests'
|
GTEST_LIST_TESTS_FLAG = '--gtest_list_tests'
|
||||||
GTEST_OUTPUT_FLAG = '--gtest_output'
|
GTEST_OUTPUT_FLAG = '--gtest_output'
|
||||||
|
|
||||||
|
EXPECTED_XML = r"""<\?xml version="1.0" encoding="UTF-8"\?>
|
||||||
EXPECTED_XML = """<\?xml version="1.0" encoding="UTF-8"\?>
|
|
||||||
<testsuites tests="2" name="AllTests">
|
<testsuites tests="2" name="AllTests">
|
||||||
<testsuite name="FooTest" tests="2">
|
<testsuite name="FooTest" tests="2">
|
||||||
<testcase name="Test1" file=".*gtest_list_output_unittest_.cc" line="43" />
|
<testcase name="Test1" file=".*gtest_list_output_unittest_.cc" line="43" />
|
||||||
|
@ -57,7 +54,7 @@ EXPECTED_XML = """<\?xml version="1.0" encoding="UTF-8"\?>
|
||||||
</testsuites>
|
</testsuites>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
EXPECTED_JSON = """{
|
EXPECTED_JSON = r"""{
|
||||||
"tests": 2,
|
"tests": 2,
|
||||||
"name": "AllTests",
|
"name": "AllTests",
|
||||||
"testsuites": \[
|
"testsuites": \[
|
||||||
|
@ -81,10 +78,11 @@ EXPECTED_JSON = """{
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
class GTestListTestsOutputUnitTest(gtest_test_utils.TestCase):
|
class GTestListTestsOutputUnitTest(gtest_test_utils.TestCase):
|
||||||
|
"""Unit test for Google Test's list tests with output to file functionality.
|
||||||
"""
|
"""
|
||||||
Unit test for Google Test's list tests with output to file functionality.
|
|
||||||
"""
|
|
||||||
def testXml(self):
|
def testXml(self):
|
||||||
"""Verifies XML output for listing tests in a Google Test binary.
|
"""Verifies XML output for listing tests in a Google Test binary.
|
||||||
|
|
||||||
|
@ -100,22 +98,21 @@ class GTestListTestsOutputUnitTest(gtest_test_utils.TestCase):
|
||||||
tests that the XML output is expected.
|
tests that the XML output is expected.
|
||||||
"""
|
"""
|
||||||
self._TestOutput('json', EXPECTED_JSON)
|
self._TestOutput('json', EXPECTED_JSON)
|
||||||
def _GetOutput(self, format):
|
|
||||||
"""
|
|
||||||
Retrieves the content from the output file
|
|
||||||
"""
|
|
||||||
file_path = os.path.join(gtest_test_utils.GetTempDir(),
|
|
||||||
'test_out.' + format)
|
|
||||||
gtest_prog_path = gtest_test_utils.GetTestExecutablePath('gtest_list_output_unittest_')
|
|
||||||
|
|
||||||
command = ([gtest_prog_path,
|
def _GetOutput(self, out_format):
|
||||||
'%s=%s:%s' % (GTEST_OUTPUT_FLAG, format, file_path),
|
file_path = os.path.join(gtest_test_utils.GetTempDir(),
|
||||||
'--gtest_list_tests'])
|
'test_out.' + out_format)
|
||||||
|
gtest_prog_path = gtest_test_utils.GetTestExecutablePath(
|
||||||
|
'gtest_list_output_unittest_')
|
||||||
|
|
||||||
|
command = ([
|
||||||
|
gtest_prog_path,
|
||||||
|
'%s=%s:%s' % (GTEST_OUTPUT_FLAG, out_format, file_path),
|
||||||
|
'--gtest_list_tests'
|
||||||
|
])
|
||||||
environ_copy = os.environ.copy()
|
environ_copy = os.environ.copy()
|
||||||
p = gtest_test_utils.Subprocess(
|
p = gtest_test_utils.Subprocess(
|
||||||
command,
|
command, env=environ_copy, working_dir=gtest_test_utils.GetTempDir())
|
||||||
env=environ_copy,
|
|
||||||
working_dir=gtest_test_utils.GetTempDir())
|
|
||||||
|
|
||||||
self.assert_(p.exited)
|
self.assert_(p.exited)
|
||||||
self.assertEquals(0, p.exit_code)
|
self.assertEquals(0, p.exit_code)
|
||||||
|
@ -123,13 +120,8 @@ class GTestListTestsOutputUnitTest(gtest_test_utils.TestCase):
|
||||||
result = f.read()
|
result = f.read()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def _TestOutput(self, test_format, expected_output):
|
||||||
|
actual = self._GetOutput(test_format)
|
||||||
def _TestOutput(self, format, expected_output):
|
|
||||||
"""
|
|
||||||
Tests that the output is similar to the expected
|
|
||||||
"""
|
|
||||||
actual = self._GetOutput(format)
|
|
||||||
actual_lines = actual.splitlines()
|
actual_lines = actual.splitlines()
|
||||||
expected_lines = expected_output.splitlines()
|
expected_lines = expected_output.splitlines()
|
||||||
line_count = 0
|
line_count = 0
|
||||||
|
@ -140,9 +132,7 @@ class GTestListTestsOutputUnitTest(gtest_test_utils.TestCase):
|
||||||
expected_line_re.match(actual_line.strip()),
|
expected_line_re.match(actual_line.strip()),
|
||||||
('actual output of "%s",\n'
|
('actual output of "%s",\n'
|
||||||
'which does not match expected regex of "%s"\n'
|
'which does not match expected regex of "%s"\n'
|
||||||
'on line %d' %
|
'on line %d' % (actual, expected_output, line_count)))
|
||||||
(actual, expected_output, line_count))
|
|
||||||
)
|
|
||||||
line_count = line_count + 1
|
line_count = line_count + 1
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user