def _TestOutFile(self, test_name, expected_xml): gtest_prog_path = os.path.join(gtest_test_utils.GetBuildDir(), test_name) command = "cd %s && %s --gtest_output=xml:%s &> /dev/null" % ( tempfile.mkdtemp(), gtest_prog_path, self.output_dir_) status = os.system(command) self.assertEquals(0, gtest_test_utils.GetExitStatus(status)) # TODO([email protected]): libtool causes the built test binary to be # named lt-gtest_xml_outfiles_test_ instead of # gtest_xml_outfiles_test_. To account for this possibillity, we # allow both names in the following code. We should remove this # hack when Chandler Carruth's libtool replacement tool is ready. 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._AssertEquivalentElements(expected.documentElement, actual.documentElement) expected.unlink() actual.unlink()
def _TestOutFile(self, test_name, expected_xml): gtest_prog_path = os.path.join(gtest_test_utils.GetBuildDir(), test_name) command = [gtest_prog_path, "--gtest_output=xml:%s" % self.output_dir_] p = gtest_test_utils.Subprocess(command, working_dir=tempfile.mkdtemp()) self.assert_(p.exited) self.assertEquals(0, p.exit_code) # TODO([email protected]): libtool causes the built test binary to be # named lt-gtest_xml_outfiles_test_ instead of # gtest_xml_outfiles_test_. To account for this possibillity, we # allow both names in the following code. We should remove this # hack when Chandler Carruth's libtool replacement tool is ready. 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 _TestXmlOutput(self, gtest_prog_name, expected_xml, expected_exit_code): """ Asserts that the XML document generated by running the program gtest_prog_name matches expected_xml, a string containing another XML document. Furthermore, the program's exit code must be expected_exit_code. """ xml_path = os.path.join(tempfile.mkdtemp(), gtest_prog_name + "out.xml") gtest_prog_path = os.path.join(gtest_test_utils.GetBuildDir(), gtest_prog_name) command = ("%s %s=xml:%s &> /dev/null" % (gtest_prog_path, GTEST_OUTPUT_FLAG, xml_path)) status = os.system(command) signal = status & 0xff self.assertEquals( 0, signal, "%s was killed by signal %d" % (gtest_prog_name, signal)) exit_code = status >> 8 self.assertEquals( expected_exit_code, exit_code, "'%s' exited with code %s, which doesn't match " "the expected exit code %s." % (command, exit_code, expected_exit_code)) expected = minidom.parseString(expected_xml) actual = minidom.parse(xml_path) self._NormalizeXml(actual.documentElement) self._AssertEquivalentElements(expected.documentElement, actual.documentElement) expected.unlink() actual.unlink()
def testDefaultOutputFile(self): """ Confirms that Google Test produces an XML output file with the expected default name if no name is explicitly specified. """ temp_dir = tempfile.mkdtemp() output_file = os.path.join(temp_dir, GTEST_DEFAULT_OUTPUT_FILE) gtest_prog_path = os.path.join(gtest_test_utils.GetBuildDir(), "gtest_no_test_unittest") try: os.remove(output_file) except OSError, e: if e.errno != errno.ENOENT: raise
def _TestXmlOutput(self, gtest_prog_name, expected_xml, expected_exit_code): """ Asserts that the XML document generated by running the program gtest_prog_name matches expected_xml, a string containing another XML document. Furthermore, the program's exit code must be expected_exit_code. """ xml_path = os.path.join(tempfile.mkdtemp(), gtest_prog_name + "out.xml") gtest_prog_path = os.path.join(gtest_test_utils.GetBuildDir(), gtest_prog_name) command = [ gtest_prog_path, "%s=xml:%s" % (GTEST_OUTPUT_FLAG, xml_path) ] 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)) expected = minidom.parseString(expected_xml) actual = minidom.parse(xml_path) self.NormalizeXml(actual.documentElement) self.AssertEquivalentNodes(expected.documentElement, actual.documentElement) expected.unlink() actual.unlink()
import unittest IS_WINDOWS = os.name == 'nt' IS_LINUX = os.name == 'posix' if IS_WINDOWS: BUILD_DIRS = [ 'build.dbg\\', 'build.opt\\', 'build.dbg8\\', 'build.opt8\\', ] COMMAND = 'gtest_uninitialized_test_.exe' if IS_LINUX: COMMAND = os.path.join(gtest_test_utils.GetBuildDir(), 'gtest_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
import os import signal import sys import unittest # Constants. # 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' # Path to the gtest_break_on_failure_unittest_ program. EXE_PATH = os.path.join(gtest_test_utils.GetBuildDir(), 'gtest_break_on_failure_unittest_'); # Utilities. def SetEnvVar(env_var, value): """Sets an environment variable to a given value; unsets it when the given value is None. """ if value is not None: os.environ[env_var] = value elif env_var in os.environ: del os.environ[env_var]
__author__ = '[email protected] (Zhanyong Wan)' import gtest_test_utils import os import re import unittest IS_WINDOWS = os.name == 'nt' if IS_WINDOWS: PROGRAM = 'gtest_help_test_.exe' else: PROGRAM = 'gtest_help_test_' PROGRAM_PATH = os.path.join(gtest_test_utils.GetBuildDir(), PROGRAM) FLAG_PREFIX = '--gtest_' CATCH_EXCEPTIONS_FLAG = FLAG_PREFIX + 'catch_exceptions' # The help message must match this regex. HELP_REGEX = re.compile( FLAG_PREFIX + r'list_tests.*' + FLAG_PREFIX + r'filter=.*' + FLAG_PREFIX + r'also_run_disabled_tests.*' + FLAG_PREFIX + r'repeat=.*' + FLAG_PREFIX + r'color=.*' + FLAG_PREFIX + r'print_time.*' + FLAG_PREFIX + r'output=.*' + FLAG_PREFIX + r'break_on_failure.*' + FLAG_PREFIX + r'throw_on_failure.*', re.DOTALL) def RunWithFlag(flag): """Runs gtest_help_test_ with the given flag.
# 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.""" __author__ = '[email protected] (Zhanyong Wan)' import gtest_test_utils import os import sys import unittest COLOR_ENV_VAR = 'GTEST_COLOR' COLOR_FLAG = 'gtest_color' COMMAND = os.path.join(gtest_test_utils.GetBuildDir(), 'gtest_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 gtest_color_test_ and returns its exit code.""" SetEnvVar('TERM', term)