-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add all existing tests to integration repo
- Loading branch information
Mishal Awadah
committed
Dec 10, 2015
0 parents
commit db437d2
Showing
35 changed files
with
721 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
*~ | ||
*.pyc | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
Swift Package Tests | ||
=================== | ||
|
||
Automated tests for validating the downloadable Swift packages behave correctly. | ||
|
||
Usage | ||
----- | ||
|
||
You are expected to check this repository out as a peer of "llvm" in the | ||
swift-project. | ||
|
||
Run the tests using: | ||
|
||
./test -sv --param package-path=/path/to/downloadable-package . | ||
|
||
where the path is the unarchived package root path. | ||
|
||
Tests | ||
----- | ||
|
||
Here is a list of tests in the repository: | ||
|
||
| Test Name | Functionality | | ||
|--------------------------+------------------------------------------------------------------| | ||
| basic | check output of `swift --version` | | ||
| example-package-dealer | build the example package-dealer package | | ||
| repl | various REPL sanity checks, notably importing Darwin and Glibc | | ||
| swift-build-self-host | Use swift build to build itself | | ||
| swift-compiler | Compile a basic swift file | | ||
| test-c-library-swiftpm | Build a package that links a 3rd party library | | ||
| test-foundation-package | Build a package that imports Foundation | | ||
| test-import-glibc | Compile a source file importing and using Glibc | | ||
| test-multi-compile | Compile multiple source files into an executable | | ||
| test-multi-compile-glibc | Compile multiple source files importing Glibc into an executable | | ||
| test-static-lib | Compile multiple source files into a static library | | ||
| test-xctest-package | Build a package that imports XCTest | | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Basic sanity check. | ||
# | ||
# RUN: %{swiftc} --version > %t.out | ||
# RUN: %{FileCheck} --input-file %t.out %s | ||
# | ||
# CHECK: Swift version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Check that debugging can print variables. | ||
# https://bugs.swift.org/browse/SR-85 | ||
# | ||
# Make a sandbox dir. | ||
# RUN: rm -rf %t.dir | ||
# RUN: mkdir -p %t.dir/tool | ||
# RUN: touch %t.dir/tool/Package.swift | ||
# RUN: echo 'let foo = "bar"' > %t.dir/tool/main.swift | ||
# RUN: echo 'print(foo)' >> %t.dir/tool/main.swift | ||
# RUN: %{swift} build --chdir %t.dir/tool -v > %t.build-log | ||
|
||
# RUN: echo 'breakpoint set -f main.swift -l 2' > %t.dir/lldb.script | ||
# RUN: echo 'run' >> %t.dir/lldb.script | ||
# RUN: echo 'print foo' >> %t.dir/lldb.script | ||
# RUN: %{lldb} %t.dir/tool/.build/debug/tool --source %t.dir/lldb.script --batch &> %t.lldb.out | ||
# RUN: %{FileCheck} --check-prefix CHECK-LLDB-OUTPUT --input-file %t.lldb.out %s | ||
# | ||
# CHECK-LLDB-OUTPUT: (lldb) print foo | ||
# CHECK-LLDB-OUTPUT-NEXT: (String) $R0 = "bar" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Test the open source example packages. | ||
# | ||
# REQUIRES: have-network | ||
# | ||
# Make a sandbox dir. If you want to experiment with this test without waiting | ||
# for the clone, disable the first three lines here. | ||
# | ||
# RUN: rm -rf %t.dir | ||
# RUN: mkdir -p %t.dir/ | ||
# RUN: git clone https://github.com/apple/example-package-dealer %t.dir/dealer | ||
|
||
# RUN: rm -rf %t.dir/dealer/.build | ||
# RUN: %{swift} build --chdir %t.dir/dealer > %t.build-log | ||
|
||
# Check the build log. | ||
# | ||
# RUN: %{FileCheck} --check-prefix CHECK-BUILD-LOG --input-file %t.build-log %s | ||
# | ||
# CHECK-BUILD-LOG: Compiling Swift Module 'FisherYates' | ||
# CHECK-BUILD-LOG: Compiling Swift Module 'Dealer' | ||
|
||
# Verify that the build worked. | ||
# | ||
# RUN: test -x %t.dir/dealer/.build/debug/Dealer | ||
# RUN: %t.dir/dealer/.build/debug/Dealer > %t.out | ||
# RUN: %{FileCheck} --check-prefix CHECK-TOOL-OUTPUT --input-file %t.out %s | ||
# | ||
# We should get an example that is easier to test. | ||
# | ||
# CHECK-TOOL-OUTPUT: {{♡|♠|♢|♣}}{{[0-9JQKA]|10}} | ||
|
||
# Verify that the 'git status' is clean after a build. | ||
# | ||
# RUN: cd %t.dir/dealer && git status > %t.out | ||
# RUN: %{FileCheck} --check-prefix CHECK-GIT-STATUS --input-file %t.out %s | ||
# | ||
# CHECK-GIT-STATUS: nothing to commit, working directory clean | ||
|
||
# Verify that another 'swift build' does nothing. | ||
# | ||
# RUN: %{swift} build --chdir %t.dir/dealer > %t.rebuild-log | ||
# RUN: echo END-OF-INPUT >> %t.rebuild-log | ||
# RUN: %{FileCheck} --check-prefix CHECK-BUILD-LOG --input-file %t.build-log %s | ||
# | ||
# CHECK-REBUILD-LOG-NOT: Compiling |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
# -*- Python -*- | ||
|
||
import platform | ||
import os | ||
import subprocess | ||
|
||
import lit.formats | ||
|
||
# Configuration file for the 'lit' test runner. | ||
|
||
def which(command, paths = None): | ||
"""which(command, [paths]) - Look up the given command in the paths string | ||
(or the PATH environment variable, if unspecified).""" | ||
|
||
if paths is None: | ||
paths = os.environ.get('PATH','') | ||
|
||
# Check for absolute match first. | ||
if os.path.exists(command): | ||
return command | ||
|
||
# Would be nice if Python had a lib function for this. | ||
if not paths: | ||
paths = os.defpath | ||
|
||
# Get suffixes to search. | ||
pathext = os.environ.get('PATHEXT', '').split(os.pathsep) | ||
|
||
# Search the paths... | ||
for path in paths.split(os.pathsep): | ||
for ext in pathext: | ||
p = os.path.join(path, command + ext) | ||
if os.path.exists(p): | ||
return p | ||
|
||
return None | ||
|
||
### | ||
# Retrieve expected values from lit.site.cfg | ||
|
||
srcroot = os.path.dirname(os.path.abspath(__file__)) | ||
srcroot = os.path.normpath(srcroot) | ||
|
||
### | ||
# Basic Configuration Parameters | ||
|
||
# name: The name of this test suite. | ||
config.name = 'swift-package-tests' | ||
|
||
# testFormat: The test format to use to interpret tests. | ||
config.test_format = lit.formats.ShTest(execute_external = False) | ||
|
||
# suffixes: A list of file extensions to treat as test files. | ||
# | ||
# We override this in specific subdirectories to change what we test. | ||
config.suffixes = [".txt", ".py"] | ||
|
||
# excludes: A list of directories to exclude from the testsuite. The 'Inputs' | ||
# subdirectories contain auxiliary inputs for various tests in their parent | ||
# directories. | ||
config.excludes = ['Inputs'] | ||
|
||
# test_source_root: The root path where tests are located. | ||
config.test_source_root = os.path.join(srcroot) | ||
|
||
# test_source_root: The root path where tests are executing. | ||
config.test_exec_root = "/tmp/swift-package-tests" | ||
|
||
# We don't make use of this yet. | ||
# | ||
# FIXME: This is pretty compiler specific and probably should just be ripped out | ||
# of lit. | ||
config.target_triple = None | ||
|
||
# On Darwin, always push SDKROOT in the environment. | ||
# | ||
# FIXME: Eventually, when we use xcrun to launch the toolchain items, this | ||
# should go away. | ||
if platform.system() == "Darwin": | ||
config.environment["SDKROOT"] = subprocess.check_output( | ||
["xcrun", "--sdk", "macosx", "--show-sdk-path"]).strip() | ||
|
||
### | ||
|
||
# Use features like this in lit: | ||
# # REQUIRES: platform=<platform> | ||
# where <platform> is Linux or Darwin | ||
# Add a platform feature. | ||
config.available_features.add("platform="+platform.system()) | ||
|
||
# Check if 'pexpect' is available. | ||
have_pexpect = False | ||
try: | ||
import pexpect | ||
have_pexpect = True | ||
except ImportError as e: | ||
pass | ||
if have_pexpect: | ||
config.available_features.add("have-pexpect") | ||
else: | ||
lit_config.note("'pexpect' module unavailable, skipping related tests") | ||
|
||
# For tests that need access to the outside world, let them know if | ||
# that's possible | ||
if lit_config.params.get("have-network"): | ||
config.available_features.add("have-network") | ||
|
||
### | ||
|
||
# Get the package path. | ||
package_path = lit_config.params.get("package-path") | ||
if package_path is None: | ||
lit_config.fatal("'--param package-path=PATH' is required") | ||
package_path = os.path.abspath(package_path) | ||
# if platform.system() == "Darwin": | ||
# package_path = os.path.join(package_path, "Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain") | ||
lit_config.note("testing package: %r" % (package_path,)) | ||
|
||
# Find the path to FileCheck. We just pick any one out of the build directory. | ||
swift_build_path = os.path.join(srcroot, "..", "build") | ||
filecheck_path = lit_config.params.get("filecheck") | ||
if filecheck_path is None: | ||
for variant in os.listdir(swift_build_path): | ||
variant_path = os.path.join(swift_build_path, variant) | ||
for tree in os.listdir(variant_path): | ||
if tree.startswith("llvm-"): | ||
path = os.path.join(variant_path, tree, "bin", "FileCheck") | ||
if os.path.exists(path): | ||
filecheck_path = path | ||
break | ||
if filecheck_path is None: | ||
lit_config.fatal("unable to locate FileCheck, '--param filecheck=PATH' is required") | ||
|
||
# Use the default Swift src layout if swiftpm is not provided as a | ||
# param | ||
swiftpm_srcdir = lit_config.params.get("swiftpm-srcdir") | ||
if swiftpm_srcdir is None: | ||
swiftpm_srcdir = os.path.join(srcroot, "..", "swiftpm") | ||
if os.path.exists(swiftpm_srcdir): | ||
config.available_features.add("have-swiftpm") | ||
config.substitutions.append( ('%{swiftpm_srcdir}', swiftpm_srcdir) ) | ||
|
||
# Find the tools we need. | ||
lit_config.note("testing using 'FileCheck': %r" % (filecheck_path,)) | ||
|
||
swift_path = os.path.join(package_path, "usr", "bin", "swift") | ||
lit_config.note("testing using 'swift': %r" % (swift_path,)) | ||
|
||
swiftc_path = os.path.join(package_path, "usr", "bin", "swiftc") | ||
lit_config.note("testing using 'swiftc': %r" % (swiftc_path,)) | ||
|
||
lldb_path = os.path.join(package_path, "usr", "bin", "lldb") | ||
lit_config.note("testing using 'lldb': {}".format(lldb_path)) | ||
|
||
# Verify they exist. | ||
if not os.path.exists(swift_path): | ||
lit_config.fatal("swift does not exist!") | ||
if not os.path.exists(swiftc_path): | ||
lit_config.fatal("swiftc does not exist!") | ||
if not os.path.exists(filecheck_path): | ||
lit_config.fatal("filecheck does not exist!") | ||
if not os.path.exists(lldb_path): | ||
lit_config.fatal("lldb does not exist!") | ||
|
||
# Define our supported substitutions. | ||
config.substitutions.append( ('%{lldb}', lldb_path) ) | ||
config.substitutions.append( ('%{swift}', swift_path) ) | ||
config.substitutions.append( ('%{swiftc}', swiftc_path) ) | ||
config.substitutions.append( ('%{FileCheck}', filecheck_path) ) | ||
|
||
### | ||
|
||
# Protected against unquoted use of substitutions. | ||
for name in ('swift-build', 'FileCheck'): | ||
config.substitutions.append((' {0} '.format(name), | ||
' unquoted-command-name-{0} '.format(name))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Tests that importing Darwin works on OS X | ||
# | ||
# REQUIRES: magic | ||
# REQUIRES: platform=Darwin | ||
# REQUIRES: have-pexpect | ||
# | ||
# RUN: rm -rf %t.dir | ||
# RUN: mkdir %t.dir | ||
# RUN: python %s %{swift} > %t.dir/output.txt | ||
# RUN: %{FileCheck} --input-file %t.dir/output.txt %s | ||
# CHECK: OK | ||
|
||
import pexpect, sys, time | ||
|
||
swift = "swift" | ||
if len(sys.argv) > 1: | ||
swift = sys.argv[1] | ||
|
||
def debug(p): | ||
print 'before:' | ||
print p.before | ||
print '--' | ||
print 'after:' | ||
print p.after | ||
print '--' | ||
print p.match.groups() | ||
print '--' | ||
|
||
repl = pexpect.spawn(swift) | ||
|
||
repl.expect('(.*)Welcome to Apple Swift version (.*)\r\n') | ||
repl.sendline('print("hello, world")') | ||
|
||
repl.expect('\r\nhello, world.*\r\n') | ||
repl.sendline('import Foundation') | ||
|
||
repl.sendline(":type lookup FILE") | ||
try: | ||
repl.expect("init") | ||
except: | ||
debug(repl) | ||
|
||
print "OK" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Tests that importing Glibc works on Linux | ||
# | ||
# REQUIRES: platform=Linux | ||
# REQUIRES: have-pexpect | ||
# | ||
# RUN: rm -rf %t.dir | ||
# RUN: mkdir %t.dir | ||
# RUN: python %s %{swift} > %t.dir/output.txt | ||
# RUN: %{FileCheck} --input-file %t.dir/output.txt %s | ||
# CHECK: OK | ||
|
||
import pexpect, sys | ||
|
||
swift = "swift" | ||
if len(sys.argv) > 1: | ||
swift = sys.argv[1] | ||
|
||
repl = pexpect.spawn(swift) | ||
|
||
repl.expect('(.*)Welcome to Swift version (.*)\r\n') | ||
# print 'before (text up to pattern that was matched):' | ||
# print repl.before | ||
# print '--' | ||
# print 'after (what was actually matched by pattern):' | ||
# print repl.after | ||
# print '--' | ||
# print repl.match.groups() | ||
# print '--' | ||
|
||
# repl.expect("(.*)1>(.*)") | ||
repl.sendline('print("hello, world")') | ||
|
||
repl.expect('\r\nhello, world.*\r\n') | ||
# print 'before:' | ||
# print repl.before | ||
# print '--' | ||
# print 'after:' | ||
# print repl.after | ||
# print '--' | ||
# print repl.match.groups() | ||
# print '--' | ||
|
||
# repl.expect("(.*)2>(.*)") | ||
repl.sendline('import Glibc') | ||
|
||
# repl.expect("(.*)3>(.*)") | ||
|
||
repl.sendline(":type lookup FILE") | ||
repl.expect("init") | ||
# print 'before:' | ||
# print repl.before | ||
# print '--' | ||
# print 'after:' | ||
# print repl.after | ||
# print '--' | ||
# print repl.match.groups() | ||
# print '--' | ||
|
||
print "OK" |
Oops, something went wrong.