Skip to content

Instantly share code, notes, and snippets.

@aciidgh
Last active June 22, 2016 16:56
Show Gist options
  • Save aciidgh/72166bb088469ca952060bae114c2719 to your computer and use it in GitHub Desktop.
Save aciidgh/72166bb088469ca952060bae114c2719 to your computer and use it in GitHub Desktop.
import json
import os
import pipes
import subprocess
import sys
import lit.Test
import lit.TestRunner
import lit.formats.base
import lit.util
class XCTestFormat(lit.formats.base.TestFormat):
def __init__(self, tests_dir, bundle_test_finder_path):
self.tests_dir = tests_dir
self.bundle_test_finder_path = bundle_test_finder_path
def getTestsInDirectory(self, testSuite, path_in_suite,
litConfig, localConfig):
# We ignore the discovery path. C'est la vie.
# Find all of the tests in the bundle.
st = os.path.join(self.tests_dir, "swift-test")
data = subprocess.check_output([st, "-l"]).rstrip().split('\n')
for test in data:
if test is None:
continue
yield lit.Test.Test(testSuite, [test], localConfig)
def execute(self, test, litConfig):
specifier = test.path_in_suite[0]
st = os.path.join(self.tests_dir, 'swift-test')
cmd = [st, '-s', specifier]
print cmd
if litConfig.noExecute:
return lit.Test.PASS, ''
out, err, exitCode = lit.util.executeCommand(
cmd, env=test.config.environment)
# If the test completed succesfully, ensure it was actually run.
if exitCode == 0 and 'Executed 1 test' not in err:
msg = ('unexpected XCTest output (test was not run):\n\n%s\n%s%s' %
(' '.join(map(pipes.quote, cmd)), out, err))
return lit.Test.UNRESOLVED, msg
if exitCode:
err += "Exit Status: %d" % (exitCode,)
return lit.Test.FAIL, out + err
passing_test_line = """Test Suite 'Selected tests' passed"""
if passing_test_line not in err:
msg = ('Unable to find %r in XCTest output:\n\n%s%s' %
(passing_test_line, out, err))
return lit.Test.UNRESOLVED, msg
return lit.Test.PASS,''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment