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.
    Furthermore, the program's exit code must be expected_exit_code.
    """
        xml_path = os.path.join(gtest_test_utils.GetTempDir(),
                                gtest_prog_name + 'out.xml')
        gtest_prog_path = gtest_test_utils.GetTestExecutablePath(
            gtest_prog_name)

        command = (
            [gtest_prog_path,
             '%s=xml:%s' % (GTEST_OUTPUT_FLAG, xml_path)] + extra_args)
        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:
            self.assert_(
                False,
                '%s was killed by signal %d' % (gtest_prog_name, p.signal))
        else:
            self.assert_(p.exited)
            self.assertEquals(
                expected_exit_code, p.exit_code,
                "'%s' exited with code %s, which doesn't match "
                'the expected exit code %s.' %
                (command, p.exit_code, expected_exit_code))
        actual = minidom.parse(xml_path)
        return actual
Example #2
0
    def _TestOutFile(self, test_name, expected_xml):
        gtest_prog_path = gtest_test_utils.GetTestExecutablePath(test_name)
        command = [gtest_prog_path, "--gtest_output=xml:%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)

        output_file_name1 = test_name + ".xml"
        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)

        expected = minidom.parseString(expected_xml)
        if os.path.isfile(output_file1):
            actual = minidom.parse(output_file1)
        else:
            actual = minidom.parse(output_file2)
        self.NormalizeXml(actual.documentElement)
        self.AssertEquivalentNodes(expected.documentElement,
                                   actual.documentElement)
        expected.unlink()
        actual.unlink()
  def _GetJsonOutput(self, gtest_prog_name, extra_args, expected_exit_code):
    """Returns the JSON output generated by running the program gtest_prog_name.

    Furthermore, the program's exit code must be expected_exit_code.

    Args:
      gtest_prog_name: Google Test binary name.
      extra_args: extra arguments to binary invocation.
      expected_exit_code: program's exit code.
    """
    json_path = os.path.join(gtest_test_utils.GetTempDir(),
                             gtest_prog_name + 'out.json')
    gtest_prog_path = gtest_test_utils.GetTestExecutablePath(gtest_prog_name)

    command = (
        [gtest_prog_path, '%s=json:%s' % (GTEST_OUTPUT_FLAG, json_path)] +
        extra_args
    )
    p = gtest_test_utils.Subprocess(command)
    if p.terminated_by_signal:
      self.assert_(False,
                   '%s was killed by signal %d' % (gtest_prog_name, p.signal))
    else:
      self.assert_(p.exited)
      self.assertEquals(expected_exit_code, p.exit_code,
                        "'%s' exited with code %s, which doesn't match "
                        'the expected exit code %s.'
                        % (command, p.exit_code, expected_exit_code))
    with open(json_path) as f:
      actual = json.load(f)
    return actual
def RunAndReturnOutput(args=None):
    """Runs the test program and returns its output."""

    return gtest_test_utils.Subprocess([
        gtest_test_utils.GetTestExecutablePath(
            'googletest-global-environment-unittest_')
    ] + (args or [])).output
Example #5
0
    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)

        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))
Example #6
0
def GetTestExecutablePath(executable_name):
    """Returns the absolute path of the test binary given its name.

  The function will print a message and abort the program if the resulting file
  doesn't exist.

  Args:
    executable_name: name of the test binary that the test script runs.

  Returns:
    The absolute path of the test binary.
  """

    return gtest_test_utils.GetTestExecutablePath(executable_name)
    def testDefaultOutputFile(self):
        """
    Confirms that Google Test produces an XML output file with the expected
    default name if no name is explicitly specified.
    """
        output_file = os.path.join(gtest_test_utils.GetTempDir(),
                                   GTEST_DEFAULT_OUTPUT_FILE)
        gtest_prog_path = gtest_test_utils.GetTestExecutablePath(
            'gtest_no_test_unittest')
        try:
            os.remove(output_file)
        except OSError:
            e = sys.exc_info()[1]
            if e.errno != errno.ENOENT:
                raise

        p = gtest_test_utils.Subprocess(
            [gtest_prog_path, '%s=xml' % GTEST_OUTPUT_FLAG],
            working_dir=gtest_test_utils.GetTempDir())
        self.assert_(p.exited)
        self.assertEquals(0, p.exit_code)
        self.assert_(os.path.isfile(output_file))
Example #8
0
    def _GetOutput(self, out_format):
        file_path = os.path.join(gtest_test_utils.GetTempDir(),
                                 '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()
        p = gtest_test_utils.Subprocess(
            command,
            env=environ_copy,
            working_dir=gtest_test_utils.GetTempDir())

        self.assertTrue(p.exited)
        self.assertEqual(0, p.exit_code)
        self.assertTrue(os.path.isfile(file_path))
        with open(file_path) as f:
            result = f.read()
        return result
Example #9
0
       gtest_help_test.py --build_dir=BUILD/DIR
         # where BUILD/DIR contains the built gtest_help_test_ file.
       gtest_help_test.py
"""

import os
import re
from googletest.test import gtest_test_utils


IS_LINUX = os.name == 'posix' and os.uname()[0] == 'Linux'
IS_GNUHURD = os.name == 'posix' and os.uname()[0] == 'GNU'
IS_GNUKFREEBSD = os.name == 'posix' and os.uname()[0] == 'GNU/kFreeBSD'
IS_WINDOWS = os.name == 'nt'

PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath('gtest_help_test_')
FLAG_PREFIX = '--gtest_'
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'
LIST_TESTS_FLAG = FLAG_PREFIX + 'list_tests'
INCORRECT_FLAG_VARIANTS = [re.sub('^--', '-', LIST_TESTS_FLAG),
                           re.sub('^--', '/', LIST_TESTS_FLAG),
                           re.sub('_', '-', LIST_TESTS_FLAG)]
INTERNAL_FLAG_FOR_TESTING = FLAG_PREFIX + 'internal_flag_for_testing'

SUPPORTS_DEATH_TESTS = "DeathTest" in gtest_test_utils.Subprocess(
    [PROGRAM_PATH, LIST_TESTS_FLAG]).output

# The help message must match this regex.
HELP_REGEX = re.compile(
Example #10
0
import sys
from googletest.test import gtest_test_utils

# The flag for generating the golden file
GENGOLDEN_FLAG = '--gengolden'
CATCH_EXCEPTIONS_ENV_VAR_NAME = 'GTEST_CATCH_EXCEPTIONS'

# The flag indicating stacktraces are not supported
NO_STACKTRACE_SUPPORT_FLAG = '--no_stacktrace_support'

IS_LINUX = os.name == 'posix' and os.uname()[0] == 'Linux'
IS_WINDOWS = os.name == 'nt'

GOLDEN_NAME = 'googletest-output-test-golden-lin.txt'

PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath(
    'googletest-output-test_')

# At least one command we exercise must not have the
# 'internal_skip_environment_and_ad_hoc_tests' argument.
COMMAND_LIST_TESTS = ({}, [PROGRAM_PATH, '--gtest_list_tests'])
COMMAND_WITH_COLOR = ({}, [PROGRAM_PATH, '--gtest_color=yes'])
COMMAND_WITH_TIME = ({}, [
    PROGRAM_PATH, '--gtest_print_time',
    '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 = ({
# 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.
"""Verifies that SetUpTestSuite and TearDownTestSuite errors are noticed."""

from googletest.test import gtest_test_utils

COMMAND = gtest_test_utils.GetTestExecutablePath(
    'googletest-setuptestsuite-test_')


class GTestSetUpTestSuiteTest(gtest_test_utils.TestCase):
    def testSetupErrorAndTearDownError(self):
        p = gtest_test_utils.Subprocess(COMMAND)
        self.assertNotEqual(p.exit_code, 0, msg=p.output)

        self.assertIn(
            '[  FAILED  ] SetupFailTest: SetUpTestSuite or TearDownTestSuite\n'
            '[  FAILED  ] TearDownFailTest: SetUpTestSuite or TearDownTestSuite\n'
            '\n'
            ' 2 FAILED TEST SUITES\n', p.output)


if __name__ == '__main__':
Example #12
0
# 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.
"""Verifies that Google Test warns the user when not initialized properly."""

from googletest.test import gtest_test_utils

COMMAND = gtest_test_utils.GetTestExecutablePath(
    'googletest-uninitialized-test_')


def Assert(condition):
    if not condition:
        raise AssertionError


def AssertEq(expected, actual):
    if expected != actual:
        print('Expected: %s' % (expected, ))
        print('  Actual: %s' % (actual, ))
        raise AssertionError


def TestExitCodeAndOutput(command):
# 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.
"""Verifies that Google Test correctly determines whether to use colors."""

import os
from googletest.test import gtest_test_utils

IS_WINDOWS = os.name == 'nt'

COLOR_ENV_VAR = 'GTEST_COLOR'
COLOR_FLAG = 'gtest_color'
COMMAND = gtest_test_utils.GetTestExecutablePath('googletest-color-test_')


def SetEnvVar(env_var, value):
    """Sets the env variable to 'value'; unsets it when 'value' is None."""

    if value is not None:
        os.environ[env_var] = value
    elif env_var in os.environ:
        del os.environ[env_var]


def UsesColor(term, color_env_var, color_flag):
    """Runs googletest-color-test_ and returns its exit code."""

    SetEnvVar('TERM', term)
BAZEL_FAIL_FAST_ENV_VAR = 'TESTBRIDGE_TEST_RUNNER_FAIL_FAST'

# The environment variable for specifying fail fast.
FAIL_FAST_ENV_VAR = 'GTEST_FAIL_FAST'

# The command line flag for specifying fail fast.
FAIL_FAST_FLAG = 'gtest_fail_fast'

# The command line flag to run disabled tests.
RUN_DISABLED_FLAG = 'gtest_also_run_disabled_tests'

# The command line flag for specifying a filter.
FILTER_FLAG = 'gtest_filter'

# Command to run the googletest-failfast-unittest_ program.
COMMAND = gtest_test_utils.GetTestExecutablePath(
    'googletest-failfast-unittest_')

# The command line flag to tell Google Test to output the list of tests it
# will run.
LIST_TESTS_FLAG = '--gtest_list_tests'

# Indicates whether Google Test supports death tests.
SUPPORTS_DEATH_TESTS = 'HasDeathTest' in gtest_test_utils.Subprocess(
    [COMMAND, LIST_TESTS_FLAG]).output

# Utilities.

environ = os.environ.copy()


def SetEnvVar(env_var, value):
This script invokes googletest-catch-exceptions-test_ and
googletest-catch-exceptions-ex-test_ (programs written with
Google Test) and verifies their output.
"""

from googletest.test import gtest_test_utils

# Constants.
FLAG_PREFIX = '--gtest_'
LIST_TESTS_FLAG = FLAG_PREFIX + 'list_tests'
NO_CATCH_EXCEPTIONS_FLAG = FLAG_PREFIX + 'catch_exceptions=0'
FILTER_FLAG = FLAG_PREFIX + 'filter'

# Path to the googletest-catch-exceptions-ex-test_ binary, compiled with
# exceptions enabled.
EX_EXE_PATH = gtest_test_utils.GetTestExecutablePath(
    'googletest-catch-exceptions-ex-test_')

# Path to the googletest-catch-exceptions-test_ binary, compiled with
# exceptions disabled.
EXE_PATH = gtest_test_utils.GetTestExecutablePath(
    'googletest-catch-exceptions-no-ex-test_')

environ = gtest_test_utils.environ
SetEnvVar = gtest_test_utils.SetEnvVar

# Tests in this file run a Google-Test-based test program and expect it
# to terminate prematurely.  Therefore they are incompatible with
# the premature-exit-file protocol by design.  Unset the
# premature-exit filepath to prevent Google Test from creating
# the file.
SetEnvVar(gtest_test_utils.PREMATURE_EXIT_FILE_ENV_VAR, None)
# The environment variable for specifying the test filters.
FILTER_ENV_VAR = 'GTEST_FILTER'

# 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'

# The command line flag for specifying the test filters.
FILTER_FLAG = 'gtest_filter'

# The command line flag for including disabled tests.
ALSO_RUN_DISABLED_TESTS_FLAG = 'gtest_also_run_disabled_tests'

# Command to run the googletest-filter-unittest_ program.
COMMAND = gtest_test_utils.GetTestExecutablePath('googletest-filter-unittest_')

# Regex for determining whether parameterized tests are enabled in the binary.
PARAM_TEST_REGEX = re.compile(r'/ParamTest')

# Regex for parsing test case names from Google Test's output.
TEST_CASE_REGEX = re.compile(r'^\[\-+\] \d+ tests? from (\w+(/\w+)?)')

# Regex for parsing test names from Google Test's output.
TEST_REGEX = re.compile(r'^\[\s*RUN\s*\].*\.(\w+(/\w+)?)')

# The command line flag to tell Google Test to output the list of tests it
# will run.
LIST_TESTS_FLAG = '--gtest_list_tests'

# Indicates whether Google Test supports death tests.
This script invokes googletest-throw-on-failure-test_ (a program written with
Google Test) with different environments and command line flags.
"""

import os
from googletest.test import gtest_test_utils


# Constants.

# The command line flag for enabling/disabling the throw-on-failure mode.
THROW_ON_FAILURE = 'gtest_throw_on_failure'

# Path to the googletest-throw-on-failure-test_ program, compiled with
# exceptions disabled.
EXE_PATH = gtest_test_utils.GetTestExecutablePath(
    'googletest-throw-on-failure-test_')


# Utilities.


def SetEnvVar(env_var, value):
  """Sets an environment variable to a given value; unsets it when the
  given value is None.
  """

  env_var = env_var.upper()
  if value is not None:
    os.environ[env_var] = value
  elif env_var in os.environ:
    del os.environ[env_var]
A user can ask Google Test to list all tests by specifying the
--gtest_list_tests flag.  This script tests such functionality
by invoking googletest-list-tests-unittest_ (a program written with
Google Test) the command line flags.
"""

import re
from googletest.test import gtest_test_utils

# Constants.

# The command line flag for enabling/disabling listing all tests.
LIST_TESTS_FLAG = 'gtest_list_tests'

# Path to the googletest-list-tests-unittest_ program.
EXE_PATH = gtest_test_utils.GetTestExecutablePath('googletest-list-tests-unittest_')

# The expected output when running googletest-list-tests-unittest_ with
# --gtest_list_tests
EXPECTED_OUTPUT_NO_FILTER_RE = re.compile(r"""FooDeathTest\.
  Test1
Foo\.
  Bar1
  Bar2
  DISABLED_Bar3
Abc\.
  Xyz
  Def
FooBar\.
  Baz
FooTest\.
Example #19
0
IS_WINDOWS = os.name == 'nt'

# The environment variable for enabling/disabling the break-on-failure mode.
BREAK_ON_FAILURE_ENV_VAR = 'GTEST_BREAK_ON_FAILURE'

# The command line flag for enabling/disabling the break-on-failure mode.
BREAK_ON_FAILURE_FLAG = 'gtest_break_on_failure'

# The environment variable for enabling/disabling the throw-on-failure mode.
THROW_ON_FAILURE_ENV_VAR = 'GTEST_THROW_ON_FAILURE'

# The environment variable for enabling/disabling the catch-exceptions mode.
CATCH_EXCEPTIONS_ENV_VAR = 'GTEST_CATCH_EXCEPTIONS'

# Path to the googletest-break-on-failure-unittest_ program.
EXE_PATH = gtest_test_utils.GetTestExecutablePath(
    'googletest-break-on-failure-unittest_')


environ = gtest_test_utils.environ
SetEnvVar = gtest_test_utils.SetEnvVar

# Tests in this file run a Google-Test-based test program and expect it
# to terminate prematurely.  Therefore they are incompatible with
# the premature-exit-file protocol by design.  Unset the
# premature-exit filepath to prevent Google Test from creating
# the file.
SetEnvVar(gtest_test_utils.PREMATURE_EXIT_FILE_ENV_VAR, None)


def Run(command):
  """Runs a command; returns 1 if it was killed by a signal, or 0 otherwise."""
                u'*',
            u'timestamp':
                u'*',
            u'classname':
                u'',
            u'failures': [{
                u'failure': u'gtest_no_test_unittest.cc:*\n'
                            u'Expected equality of these values:\n'
                            u'  1\n  2' + STACK_TRACE_TEMPLATE,
                u'type': u'',
            }]
        }]
    }],
}

GTEST_PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath(GTEST_PROGRAM_NAME)

SUPPORTS_TYPED_TESTS = 'TypedTest' in gtest_test_utils.Subprocess(
    [GTEST_PROGRAM_PATH, GTEST_LIST_TESTS_FLAG], capture_stderr=False).output


class GTestJsonOutputUnitTest(gtest_test_utils.TestCase):
  """Unit test for Google Test's JSON output functionality.
  """

  # This test currently breaks on platforms that do not support typed and
  # type-parameterized tests, so we don't run it under them.
  if SUPPORTS_TYPED_TESTS:

    def testNonEmptyJsonOutput(self):
      """Verifies JSON output for a Google Test binary with non-empty output.
# 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.
"""Verifies that test shuffling works."""

import os
from googletest.test import gtest_test_utils

# Command to run the googletest-shuffle-test_ program.
COMMAND = gtest_test_utils.GetTestExecutablePath('googletest-shuffle-test_')

# The environment variables for test sharding.
TOTAL_SHARDS_ENV_VAR = 'GTEST_TOTAL_SHARDS'
SHARD_INDEX_ENV_VAR = 'GTEST_SHARD_INDEX'

TEST_FILTER = 'A*.A:A*.B:C*'

ALL_TESTS = []
ACTIVE_TESTS = []
FILTERED_TESTS = []
SHARDED_TESTS = []

SHUFFLED_ALL_TESTS = []
SHUFFLED_ACTIVE_TESTS = []
SHUFFLED_FILTERED_TESTS = []
Example #22
0
# 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.
"""Tests Google Test's gtest skip in environment setup  behavior.

This script invokes gtest_skip_in_environment_setup_test_ and verifies its
output.
"""

import re

from googletest.test import gtest_test_utils

# Path to the gtest_skip_in_environment_setup_test binary
EXE_PATH = gtest_test_utils.GetTestExecutablePath('gtest_skip_test')

OUTPUT = gtest_test_utils.Subprocess([EXE_PATH]).output


# Test.
class SkipEntireEnvironmentTest(gtest_test_utils.TestCase):
    def testSkipEntireEnvironmentTest(self):
        self.assertIn('Skipped\nskipping single test\n', OUTPUT)
        skip_fixture = 'Skipped\nskipping all tests for this fixture\n'
        self.assertIsNotNone(
            re.search(skip_fixture + '.*' + skip_fixture,
                      OUTPUT,
                      flags=re.DOTALL), repr(OUTPUT))
        self.assertNotIn('FAILED', OUTPUT)
# "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.
"""Verifies that Google Test warns the user when not initialized properly."""

from googletest.test import gtest_test_utils

binary_name = 'googletest-param-test-invalid-name1-test_'
COMMAND = gtest_test_utils.GetTestExecutablePath(binary_name)


def Assert(condition):
    if not condition:
        raise AssertionError


def TestExitCodeAndOutput(command):
    """Runs the given command and verifies its exit code and output."""

    err = ('Parameterized test name \'"InvalidWithQuotes"\' is invalid')

    p = gtest_test_utils.Subprocess(command)
    Assert(p.terminated_by_signal)
Example #24
0
# 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.
"""Tests Google Test's gtest skip in environment setup  behavior.

This script invokes gtest_skip_in_environment_setup_test_ and verifies its
output.
"""

from googletest.test import gtest_test_utils

# Path to the gtest_skip_in_environment_setup_test binary
EXE_PATH = gtest_test_utils.GetTestExecutablePath(
    'gtest_skip_in_environment_setup_test')

OUTPUT = gtest_test_utils.Subprocess([EXE_PATH]).output


# Test.
class SkipEntireEnvironmentTest(gtest_test_utils.TestCase):
    def testSkipEntireEnvironmentTest(self):
        self.assertIn('Skipping the entire environment', OUTPUT)
        self.assertNotIn('FAILED', OUTPUT)


if __name__ == '__main__':
    gtest_test_utils.Main()
# 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.
"""Verifies that Google Test correctly parses environment variables."""

import os
from googletest.test import gtest_test_utils

IS_WINDOWS = os.name == 'nt'
IS_LINUX = os.name == 'posix' and os.uname()[0] == 'Linux'

COMMAND = gtest_test_utils.GetTestExecutablePath('googletest-env-var-test_')

environ = os.environ.copy()


def AssertEq(expected, actual):
    if expected != actual:
        print('Expected: %s' % (expected, ))
        print('  Actual: %s' % (actual, ))
        raise AssertionError


def SetEnvVar(env_var, value):
    """Sets the env variable to 'value'; unsets it when 'value' is None."""

    if value is not None: