/thirdparty/breakpad/third_party/protobuf/protobuf/gtest/test/gtest_list_tests_unittest.py

http://github.com/tomahawk-player/tomahawk · Python · 177 lines · 143 code · 2 blank · 32 comment · 0 complexity · 7de66bd5e77452d1fb64fb328f64ee55 MD5 · raw file

  1. #!/usr/bin/env python
  2. #
  3. # Copyright 2006, Google Inc.
  4. # All rights reserved.
  5. #
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions are
  8. # met:
  9. #
  10. # * Redistributions of source code must retain the above copyright
  11. # notice, this list of conditions and the following disclaimer.
  12. # * Redistributions in binary form must reproduce the above
  13. # copyright notice, this list of conditions and the following disclaimer
  14. # in the documentation and/or other materials provided with the
  15. # distribution.
  16. # * Neither the name of Google Inc. nor the names of its
  17. # contributors may be used to endorse or promote products derived from
  18. # this software without specific prior written permission.
  19. #
  20. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. """Unit test for Google Test's --gtest_list_tests flag.
  32. A user can ask Google Test to list all tests by specifying the
  33. --gtest_list_tests flag. This script tests such functionality
  34. by invoking gtest_list_tests_unittest_ (a program written with
  35. Google Test) the command line flags.
  36. """
  37. __author__ = 'phanna@google.com (Patrick Hanna)'
  38. import gtest_test_utils
  39. # Constants.
  40. # The command line flag for enabling/disabling listing all tests.
  41. LIST_TESTS_FLAG = 'gtest_list_tests'
  42. # Path to the gtest_list_tests_unittest_ program.
  43. EXE_PATH = gtest_test_utils.GetTestExecutablePath('gtest_list_tests_unittest_')
  44. # The expected output when running gtest_list_tests_unittest_ with
  45. # --gtest_list_tests
  46. EXPECTED_OUTPUT_NO_FILTER = """FooDeathTest.
  47. Test1
  48. Foo.
  49. Bar1
  50. Bar2
  51. DISABLED_Bar3
  52. Abc.
  53. Xyz
  54. Def
  55. FooBar.
  56. Baz
  57. FooTest.
  58. Test1
  59. DISABLED_Test2
  60. Test3
  61. """
  62. # The expected output when running gtest_list_tests_unittest_ with
  63. # --gtest_list_tests and --gtest_filter=Foo*.
  64. EXPECTED_OUTPUT_FILTER_FOO = """FooDeathTest.
  65. Test1
  66. Foo.
  67. Bar1
  68. Bar2
  69. DISABLED_Bar3
  70. FooBar.
  71. Baz
  72. FooTest.
  73. Test1
  74. DISABLED_Test2
  75. Test3
  76. """
  77. # Utilities.
  78. def Run(args):
  79. """Runs gtest_list_tests_unittest_ and returns the list of tests printed."""
  80. return gtest_test_utils.Subprocess([EXE_PATH] + args,
  81. capture_stderr=False).output
  82. # The unit test.
  83. class GTestListTestsUnitTest(gtest_test_utils.TestCase):
  84. """Tests using the --gtest_list_tests flag to list all tests."""
  85. def RunAndVerify(self, flag_value, expected_output, other_flag):
  86. """Runs gtest_list_tests_unittest_ and verifies that it prints
  87. the correct tests.
  88. Args:
  89. flag_value: value of the --gtest_list_tests flag;
  90. None if the flag should not be present.
  91. expected_output: the expected output after running command;
  92. other_flag: a different flag to be passed to command
  93. along with gtest_list_tests;
  94. None if the flag should not be present.
  95. """
  96. if flag_value is None:
  97. flag = ''
  98. flag_expression = 'not set'
  99. elif flag_value == '0':
  100. flag = '--%s=0' % LIST_TESTS_FLAG
  101. flag_expression = '0'
  102. else:
  103. flag = '--%s' % LIST_TESTS_FLAG
  104. flag_expression = '1'
  105. args = [flag]
  106. if other_flag is not None:
  107. args += [other_flag]
  108. output = Run(args)
  109. msg = ('when %s is %s, the output of "%s" is "%s".' %
  110. (LIST_TESTS_FLAG, flag_expression, ' '.join(args), output))
  111. if expected_output is not None:
  112. self.assert_(output == expected_output, msg)
  113. else:
  114. self.assert_(output != EXPECTED_OUTPUT_NO_FILTER, msg)
  115. def testDefaultBehavior(self):
  116. """Tests the behavior of the default mode."""
  117. self.RunAndVerify(flag_value=None,
  118. expected_output=None,
  119. other_flag=None)
  120. def testFlag(self):
  121. """Tests using the --gtest_list_tests flag."""
  122. self.RunAndVerify(flag_value='0',
  123. expected_output=None,
  124. other_flag=None)
  125. self.RunAndVerify(flag_value='1',
  126. expected_output=EXPECTED_OUTPUT_NO_FILTER,
  127. other_flag=None)
  128. def testOverrideNonFilterFlags(self):
  129. """Tests that --gtest_list_tests overrides the non-filter flags."""
  130. self.RunAndVerify(flag_value='1',
  131. expected_output=EXPECTED_OUTPUT_NO_FILTER,
  132. other_flag='--gtest_break_on_failure')
  133. def testWithFilterFlags(self):
  134. """Tests that --gtest_list_tests takes into account the
  135. --gtest_filter flag."""
  136. self.RunAndVerify(flag_value='1',
  137. expected_output=EXPECTED_OUTPUT_FILTER_FOO,
  138. other_flag='--gtest_filter=Foo*')
  139. if __name__ == '__main__':
  140. gtest_test_utils.Main()