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 IS_LINUX = os.name == 'posix' and os.uname()[0] == 'Linux'
     42 if not IS_LINUX:
     43   sys.exit(0)  # Negative compilation tests are not supported on Windows & Mac.
     44 
     45 
     46 class GTestNCTest(unittest.TestCase):
     47   """Negative compilation test for Google Test."""
     48 
     49   def testCompilerError(self):
     50     """Verifies that erroneous code leads to expected compiler
     51     messages."""
     52 
     53     # Defines a list of test specs, where each element is a tuple
     54     # (test name, list of regexes for matching the compiler errors).
     55     test_specs = [
     56       ('CANNOT_IGNORE_RUN_ALL_TESTS_RESULT',
     57        [r'ignoring return value']),
     58 
     59       ('USER_CANNOT_INCLUDE_GTEST_INTERNAL_INL_H',
     60        [r'must not be included except by Google Test itself']),
     61 
     62       ('CATCHES_DECLARING_SETUP_IN_TEST_FIXTURE_WITH_TYPO',
     63        [r'Setup_should_be_spelled_SetUp']),
     64 
     65       ('CATCHES_CALLING_SETUP_IN_TEST_WITH_TYPO',
     66        [r'Setup_should_be_spelled_SetUp']),
     67 
     68       ('CATCHES_DECLARING_SETUP_IN_ENVIRONMENT_WITH_TYPO',
     69        [r'Setup_should_be_spelled_SetUp']),
     70 
     71       ('CATCHES_CALLING_SETUP_IN_ENVIRONMENT_WITH_TYPO',
     72        [r'Setup_should_be_spelled_SetUp']),
     73 
     74       ('CATCHES_WRONG_CASE_IN_TYPED_TEST_P',
     75        [r'BarTest.*was not declared']),
     76 
     77       ('CATCHES_WRONG_CASE_IN_REGISTER_TYPED_TEST_CASE_P',
     78        [r'BarTest.*was not declared']),
     79 
     80       ('CATCHES_WRONG_CASE_IN_INSTANTIATE_TYPED_TEST_CASE_P',
     81        [r'BarTest.*not declared']),
     82 
     83       ('CATCHES_INSTANTIATE_TYPED_TESET_CASE_P_WITH_SAME_NAME_PREFIX',
     84        [r'redefinition of.*My.*FooTest']),
     85 
     86       ('STATIC_ASSERT_TYPE_EQ_IS_NOT_A_TYPE',
     87        [r'StaticAssertTypeEq.* does not name a type']),
     88 
     89       ('STATIC_ASSERT_TYPE_EQ_WORKS_IN_NAMESPACE',
     90        [r'StaticAssertTypeEq.*int.*const int']),
     91 
     92       ('STATIC_ASSERT_TYPE_EQ_WORKS_IN_CLASS',
     93        [r'StaticAssertTypeEq.*int.*bool']),
     94 
     95       ('STATIC_ASSERT_TYPE_EQ_WORKS_IN_FUNCTION',
     96        [r'StaticAssertTypeEq.*const int.*int']),
     97 
     98       ('SANITY',
     99        None)
    100       ]
    101 
    102     # TODO(wan (at] google.com): verify that the test specs are satisfied.
    103 
    104 
    105 if __name__ == '__main__':
    106   unittest.main()
    107