File: LitTests.py

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (48 lines) | stat: -rw-r--r-- 1,590 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""PyObjC Lit <-> XCTest Adaptor"""

import objc
import os
import re

import lit

# Ensure we have the appropriate environment variables
built_products_dir = os.environ.get("BUILT_PRODUCTS_DIR")
if not built_products_dir or not os.path.exists(built_products_dir):
   raise RuntimeError("invalid BUILT_PRODUCTS_DIR: %r" % (built_products_dir,))

test_paths = [os.path.join(built_products_dir, "tests")]
# Load the Lit test suite using the unittest style discovery.
try:
  import lit.LitTestCase
  test_suite = lit.LitTestCase.load_test_suite(test_paths)
except AttributeError:
  # Legacy way of loading tests.
  import lit.discovery
  test_suite = lit.discovery.load_test_suite(test_paths)

# Inject test methods for each test.
def injectTestMethod(klass, test):
    test_name = test.id()
    
    # Mangle the test name into a valid name.
    method_name = "test" + re.sub(r"[^A-Za-z_0-9]", "_", test_name)
    
    # Inject the method.
    def runTest(obj):
        print "Running Lit test: %s" % (test.id(),)
        result = test.defaultTestResult()
        test.run(result)
        
        # Report an XCTest failure, if the test failed.
        if not result.wasSuccessful():
            # Get the underlying Lit result object.
            lit_result = test._test.result
            obj.recordFailureWithDescription_inFile_atLine_expected_(lit_result.output, test._test.getSourcePath(), 1, True)

    objc.classAddMethod(klass, method_name, runTest)

# Inject a test method for each test.
klass = objc.lookUpClass("LitTests")
for test in test_suite:
    injectTestMethod(klass, test)