def testOutput(self):
        output = GetOutputOfAllCommands()

        golden_file = open(GOLDEN_PATH, 'rb')
        # 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
        # unconditionally.
        golden = ToUnixLineEnding(golden_file.read().decode())
        golden_file.close()

        # We want the test to pass regardless of certain features being
        # supported or not.

        # We still have to remove type name specifics in all cases.
        normalized_actual = RemoveTypeInfoDetails(output)
        normalized_golden = RemoveTypeInfoDetails(golden)

        if CAN_GENERATE_GOLDEN_FILE:
            self.assertEqual(
                normalized_golden, normalized_actual, '\n'.join(
                    difflib.unified_diff(normalized_golden.split('\n'),
                                         normalized_actual.split('\n'),
                                         'golden', 'actual')))
        else:
            normalized_actual = NormalizeToCurrentPlatform(
                RemoveTestCounts(normalized_actual))
            normalized_golden = NormalizeToCurrentPlatform(
                RemoveTestCounts(
                    self.RemoveUnsupportedTests(normalized_golden)))

            # This code is very handy when debugging golden file differences:
            if os.getenv('DEBUG_GTEST_OUTPUT_TEST'):
                open(
                    os.path.join(
                        gtest_test_utils.GetSourceDir(),
                        '_googletest-output-test_normalized_actual.txt'),
                    'wb').write(normalized_actual)
                open(
                    os.path.join(
                        gtest_test_utils.GetSourceDir(),
                        '_googletest-output-test_normalized_golden.txt'),
                    'wb').write(normalized_golden)

            self.assertEqual(normalized_golden, normalized_actual)
    'internal_skip_environment_and_ad_hoc_tests',
    '--gtest_filter=FatalFailureTest.*:LoggingTest.*'
])
COMMAND_WITH_DISABLED = ({}, [
    PROGRAM_PATH, '--gtest_also_run_disabled_tests',
    'internal_skip_environment_and_ad_hoc_tests', '--gtest_filter=*DISABLED_*'
])
COMMAND_WITH_SHARDING = ({
    'GTEST_SHARD_INDEX': '1',
    'GTEST_TOTAL_SHARDS': '2'
}, [
    PROGRAM_PATH, 'internal_skip_environment_and_ad_hoc_tests',
    '--gtest_filter=PassingTest.*'
])

GOLDEN_PATH = os.path.join(gtest_test_utils.GetSourceDir(), GOLDEN_NAME)


def ToUnixLineEnding(s):
    """Changes all Windows/Mac line endings in s to UNIX line endings."""

    return s.replace('\r\n', '\n').replace('\r', '\n')


def RemoveLocations(test_output):
    """Removes all file location info from a Google Test program's output.

  Args:
       test_output:  the output of a Google Test program.

  Returns:
Exemplo n.º 3
0
def GetSourceDir():
  """Returns the absolute path of the directory where the .py files are."""

  return gtest_test_utils.GetSourceDir()