Home | History | Annotate | Download | only in test
      1 #!/usr/bin/env python
      2 #
      3 # Copyright 2007, 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 
     32 """Negative compilation test for Google Test."""
     33 
     34 __author__ = 'wan (at] google.com (Zhanyong Wan)'
     35 
     36 import os
     37 import sys
     38 import unittest
     39 
     40 
     41 class GTestNCTest(unittest.TestCase):
     42   """Negative compilation test for Google Test."""
     43 
     44   def testCompilerError(self):
     45     """Verifies that erroneous code leads to expected compiler
     46     messages."""
     47 
     48     # Defines a list of test specs, where each element is a tuple
     49     # (test name, list of regexes for matching the compiler errors).
     50     test_specs = [
     51       ('CANNOT_IGNORE_RUN_ALL_TESTS_RESULT',
     52        [r'ignoring return value']),
     53 
     54       ('USER_CANNOT_INCLUDE_GTEST_INTERNAL_INL_H',
     55        [r'must not be included except by Google Test itself']),
     56 
     57       ('CATCHES_DECLARING_SETUP_IN_TEST_FIXTURE_WITH_TYPO',
     58        [r'Setup_should_be_spelled_SetUp']),
     59 
     60       ('CATCHES_CALLING_SETUP_IN_TEST_WITH_TYPO',
     61        [r'Setup_should_be_spelled_SetUp']),
     62 
     63       ('CATCHES_DECLARING_SETUP_IN_ENVIRONMENT_WITH_TYPO',
     64        [r'Setup_should_be_spelled_SetUp']),
     65 
     66       ('CATCHES_CALLING_SETUP_IN_ENVIRONMENT_WITH_TYPO',
     67        [r'Setup_should_be_spelled_SetUp']),
     68 
     69       ('CATCHES_WRONG_CASE_IN_TYPED_TEST_P',
     70        [r'BarTest.*was not declared']),
     71 
     72       ('CATCHES_WRONG_CASE_IN_REGISTER_TYPED_TEST_CASE_P',
     73        [r'BarTest.*was not declared']),
     74 
     75       ('CATCHES_WRONG_CASE_IN_INSTANTIATE_TYPED_TEST_CASE_P',
     76        [r'BarTest.*not declared']),
     77 
     78       ('CATCHES_INSTANTIATE_TYPED_TESET_CASE_P_WITH_SAME_NAME_PREFIX',
     79        [r'redefinition of.*My.*FooTest']),
     80 
     81       ('STATIC_ASSERT_TYPE_EQ_IS_NOT_A_TYPE',
     82        [r'StaticAssertTypeEq.* does not name a type']),
     83 
     84       ('STATIC_ASSERT_TYPE_EQ_WORKS_IN_NAMESPACE',
     85        [r'StaticAssertTypeEq.*int.*const int']),
     86 
     87       ('STATIC_ASSERT_TYPE_EQ_WORKS_IN_CLASS',
     88        [r'StaticAssertTypeEq.*int.*bool']),
     89 
     90       ('STATIC_ASSERT_TYPE_EQ_WORKS_IN_FUNCTION',
     91        [r'StaticAssertTypeEq.*const int.*int']),
     92 
     93       ('SANITY',
     94        None)
     95       ]
     96 
     97     # TODO(wan (at] google.com): verify that the test specs are satisfied.
     98 
     99 
    100 if __name__ == '__main__':
    101   unittest.main()
    102