gtest_list_tests_unittest.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # Copyright 2006, Google Inc.
00004 # All rights reserved.
00005 #
00006 # Redistribution and use in source and binary forms, with or without
00007 # modification, are permitted provided that the following conditions are
00008 # met:
00009 #
00010 #     * Redistributions of source code must retain the above copyright
00011 # notice, this list of conditions and the following disclaimer.
00012 #     * Redistributions in binary form must reproduce the above
00013 # copyright notice, this list of conditions and the following disclaimer
00014 # in the documentation and/or other materials provided with the
00015 # distribution.
00016 #     * Neither the name of Google Inc. nor the names of its
00017 # contributors may be used to endorse or promote products derived from
00018 # this software without specific prior written permission.
00019 #
00020 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00021 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00022 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00023 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00024 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00025 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00026 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00027 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00028 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00029 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00030 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00031 
00032 """Unit test for Google Test's --gtest_list_tests flag.
00033 
00034 A user can ask Google Test to list all tests by specifying the
00035 --gtest_list_tests flag.  This script tests such functionality
00036 by invoking gtest_list_tests_unittest_ (a program written with
00037 Google Test) the command line flags.
00038 """
00039 
00040 __author__ = 'phanna@google.com (Patrick Hanna)'
00041 
00042 import gtest_test_utils
00043 import re
00044 
00045 
00046 # Constants.
00047 
00048 # The command line flag for enabling/disabling listing all tests.
00049 LIST_TESTS_FLAG = 'gtest_list_tests'
00050 
00051 # Path to the gtest_list_tests_unittest_ program.
00052 EXE_PATH = gtest_test_utils.GetTestExecutablePath('gtest_list_tests_unittest_')
00053 
00054 # The expected output when running gtest_list_tests_unittest_ with
00055 # --gtest_list_tests
00056 EXPECTED_OUTPUT_NO_FILTER_RE = re.compile(r"""FooDeathTest\.
00057   Test1
00058 Foo\.
00059   Bar1
00060   Bar2
00061   DISABLED_Bar3
00062 Abc\.
00063   Xyz
00064   Def
00065 FooBar\.
00066   Baz
00067 FooTest\.
00068   Test1
00069   DISABLED_Test2
00070   Test3
00071 TypedTest/0\.  # TypeParam = (VeryLo{245}|class VeryLo{239})\.\.\.
00072   TestA
00073   TestB
00074 TypedTest/1\.  # TypeParam = int\s*\*
00075   TestA
00076   TestB
00077 TypedTest/2\.  # TypeParam = .*MyArray<bool,\s*42>
00078   TestA
00079   TestB
00080 My/TypeParamTest/0\.  # TypeParam = (VeryLo{245}|class VeryLo{239})\.\.\.
00081   TestA
00082   TestB
00083 My/TypeParamTest/1\.  # TypeParam = int\s*\*
00084   TestA
00085   TestB
00086 My/TypeParamTest/2\.  # TypeParam = .*MyArray<bool,\s*42>
00087   TestA
00088   TestB
00089 MyInstantiation/ValueParamTest\.
00090   TestA/0  # GetParam\(\) = one line
00091   TestA/1  # GetParam\(\) = two\\nlines
00092   TestA/2  # GetParam\(\) = a very\\nlo{241}\.\.\.
00093   TestB/0  # GetParam\(\) = one line
00094   TestB/1  # GetParam\(\) = two\\nlines
00095   TestB/2  # GetParam\(\) = a very\\nlo{241}\.\.\.
00096 """)
00097 
00098 # The expected output when running gtest_list_tests_unittest_ with
00099 # --gtest_list_tests and --gtest_filter=Foo*.
00100 EXPECTED_OUTPUT_FILTER_FOO_RE = re.compile(r"""FooDeathTest\.
00101   Test1
00102 Foo\.
00103   Bar1
00104   Bar2
00105   DISABLED_Bar3
00106 FooBar\.
00107   Baz
00108 FooTest\.
00109   Test1
00110   DISABLED_Test2
00111   Test3
00112 """)
00113 
00114 # Utilities.
00115 
00116 
00117 def Run(args):
00118   """Runs gtest_list_tests_unittest_ and returns the list of tests printed."""
00119 
00120   return gtest_test_utils.Subprocess([EXE_PATH] + args,
00121                                      capture_stderr=False).output
00122 
00123 
00124 # The unit test.
00125 
00126 class GTestListTestsUnitTest(gtest_test_utils.TestCase):
00127   """Tests using the --gtest_list_tests flag to list all tests."""
00128 
00129   def RunAndVerify(self, flag_value, expected_output_re, other_flag):
00130     """Runs gtest_list_tests_unittest_ and verifies that it prints
00131     the correct tests.
00132 
00133     Args:
00134       flag_value:         value of the --gtest_list_tests flag;
00135                           None if the flag should not be present.
00136       expected_output_re: regular expression that matches the expected
00137                           output after running command;
00138       other_flag:         a different flag to be passed to command
00139                           along with gtest_list_tests;
00140                           None if the flag should not be present.
00141     """
00142 
00143     if flag_value is None:
00144       flag = ''
00145       flag_expression = 'not set'
00146     elif flag_value == '0':
00147       flag = '--%s=0' % LIST_TESTS_FLAG
00148       flag_expression = '0'
00149     else:
00150       flag = '--%s' % LIST_TESTS_FLAG
00151       flag_expression = '1'
00152 
00153     args = [flag]
00154 
00155     if other_flag is not None:
00156       args += [other_flag]
00157 
00158     output = Run(args)
00159 
00160     if expected_output_re:
00161       self.assert_(
00162           expected_output_re.match(output),
00163           ('when %s is %s, the output of "%s" is "%s",\n'
00164            'which does not match regex "%s"' %
00165            (LIST_TESTS_FLAG, flag_expression, ' '.join(args), output,
00166             expected_output_re.pattern)))
00167     else:
00168       self.assert_(
00169           not EXPECTED_OUTPUT_NO_FILTER_RE.match(output),
00170           ('when %s is %s, the output of "%s" is "%s"'%
00171            (LIST_TESTS_FLAG, flag_expression, ' '.join(args), output)))
00172 
00173   def testDefaultBehavior(self):
00174     """Tests the behavior of the default mode."""
00175 
00176     self.RunAndVerify(flag_value=None,
00177                       expected_output_re=None,
00178                       other_flag=None)
00179 
00180   def testFlag(self):
00181     """Tests using the --gtest_list_tests flag."""
00182 
00183     self.RunAndVerify(flag_value='0',
00184                       expected_output_re=None,
00185                       other_flag=None)
00186     self.RunAndVerify(flag_value='1',
00187                       expected_output_re=EXPECTED_OUTPUT_NO_FILTER_RE,
00188                       other_flag=None)
00189 
00190   def testOverrideNonFilterFlags(self):
00191     """Tests that --gtest_list_tests overrides the non-filter flags."""
00192 
00193     self.RunAndVerify(flag_value='1',
00194                       expected_output_re=EXPECTED_OUTPUT_NO_FILTER_RE,
00195                       other_flag='--gtest_break_on_failure')
00196 
00197   def testWithFilterFlags(self):
00198     """Tests that --gtest_list_tests takes into account the
00199     --gtest_filter flag."""
00200 
00201     self.RunAndVerify(flag_value='1',
00202                       expected_output_re=EXPECTED_OUTPUT_FILTER_FOO_RE,
00203                       other_flag='--gtest_filter=Foo*')
00204 
00205 
00206 if __name__ == '__main__':
00207   gtest_test_utils.Main()


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Sat Jun 8 2019 18:24:55