Add all existing tests to integration repo
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..eef29c1
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+*~
+*.pyc
+
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..26adda5
--- /dev/null
+++ b/README.md
@@ -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                              |
+
diff --git a/basic.py b/basic.py
new file mode 100644
index 0000000..20d4a83
--- /dev/null
+++ b/basic.py
@@ -0,0 +1,6 @@
+# Basic sanity check.
+#
+# RUN: %{swiftc} --version > %t.out
+# RUN: %{FileCheck} --input-file %t.out %s
+#
+# CHECK: Swift version
diff --git a/debugging-flags-SR85.py b/debugging-flags-SR85.py
new file mode 100644
index 0000000..c5ded84
--- /dev/null
+++ b/debugging-flags-SR85.py
@@ -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"
diff --git a/example-package-dealer.py b/example-package-dealer.py
new file mode 100644
index 0000000..a6732f9
--- /dev/null
+++ b/example-package-dealer.py
@@ -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
diff --git a/lit.cfg b/lit.cfg
new file mode 100644
index 0000000..985dad8
--- /dev/null
+++ b/lit.cfg
@@ -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)))
diff --git a/repl/test-repl-darwin.py b/repl/test-repl-darwin.py
new file mode 100644
index 0000000..6ef071b
--- /dev/null
+++ b/repl/test-repl-darwin.py
@@ -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"
diff --git a/repl/test-repl-glibc.py b/repl/test-repl-glibc.py
new file mode 100644
index 0000000..87972c5
--- /dev/null
+++ b/repl/test-repl-glibc.py
@@ -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"
diff --git a/swift-build-self-host.py b/swift-build-self-host.py
new file mode 100644
index 0000000..6438abd
--- /dev/null
+++ b/swift-build-self-host.py
@@ -0,0 +1,25 @@
+# Check that the package manager can build itself. This is really just testing
+# that the package manager included in this package is functional for a moderate
+# sized, real project.
+#
+# REQUIRES: have-swiftpm
+#
+# 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: cp -R %{swiftpm_srcdir} %t.dir/swiftpm
+
+# RUN: rm -rf %t.dir/swiftpm/.build
+# RUN: %{swift} build --chdir %t.dir/swiftpm > %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 'PackageDescription'
+
+# Verify that the build worked.
+#
+# RUN: test -x %t.dir/swiftpm/.build/debug/swift-build
diff --git a/swift-build.py b/swift-build.py
new file mode 100644
index 0000000..bfc2c46
--- /dev/null
+++ b/swift-build.py
@@ -0,0 +1,22 @@
+# Trivial test for Swift build.
+#
+# Make a sandbox dir.
+# RUN: rm -rf %t.dir
+# RUN: mkdir -p %t.dir/tool
+# RUN: touch %t.dir/tool/Package.swift
+# RUN: echo 'print("HI")' > %t.dir/tool/main.swift
+# RUN: %{swift} build --chdir %t.dir/tool -v > %t.build-log
+
+# Check the build log.
+#
+# RUN: %{FileCheck} --check-prefix CHECK-BUILD-LOG --input-file %t.build-log %s
+#
+# CHECK-BUILD-LOG: swiftc{{.*}} -module-name tool
+
+# Verify that the tool exists and works.
+#
+# RUN: test -x %t.dir/tool/.build/debug/tool
+# RUN: %t.dir/tool/.build/debug/tool > %t.out
+# RUN: %{FileCheck} --check-prefix CHECK-TOOL-OUTPUT --input-file %t.out %s
+#
+# CHECK-TOOL-OUTPUT: HI
diff --git a/swift-compiler.py b/swift-compiler.py
new file mode 100644
index 0000000..a0504d7
--- /dev/null
+++ b/swift-compiler.py
@@ -0,0 +1,21 @@
+#
+# RUN: rm -rf %t.dir
+# RUN: mkdir -p %t.dir
+# RUN: touch %t.dir/hello.swift
+# RUN: echo 'print("hello")' > %t.dir/hello.swift
+# RUN: %{swiftc} %t.dir/hello.swift -o %t.dir/hello
+
+# Check the file exists
+#
+# RUN: ls %t.dir/ > %t.listing
+# RUN: %{FileCheck} --check-prefix CHECK-FILE --input-file %t.listing %s
+#
+# CHECK-FILE: hello
+
+# Check the file runs
+#
+# RUN: %t.dir/hello > %t.output
+# RUN: %{FileCheck} --check-prefix CHECK-OUT --input-file %t.output %s
+#
+# CHECK-OUT: hello
+
diff --git a/swift-package-with-spaces.py b/swift-package-with-spaces.py
new file mode 100644
index 0000000..d2f0268
--- /dev/null
+++ b/swift-package-with-spaces.py
@@ -0,0 +1,23 @@
+# Check a package with spaces.
+#
+# Make a sandbox dir.
+# RUN: rm -rf %t.dir
+# RUN: mkdir -p %t.dir/more\ spaces/special\ tool
+# RUN: touch %t.dir/more\ spaces/special\ tool/Package.swift
+# RUN: echo 'foo()' > %t.dir/more\ spaces/special\ tool/main.swift
+# RUN: echo 'func foo() { print("HI") }' > %t.dir/more\ spaces/special\ tool/some\ file.swift
+# RUN: %{swift} build --chdir %t.dir/more\ spaces/special\ tool -v > %t.build-log
+
+# Check the build log.
+#
+# RUN: %{FileCheck} --check-prefix CHECK-BUILD-LOG --input-file %t.build-log %s
+#
+# CHECK-BUILD-LOG: swiftc{{.*}} -module-name specialtool {{.*}} "{{.*}}/more spaces/special tool/some file.swift"
+
+# Verify that the tool exists and works.
+#
+# RUN: test -x %t.dir/more\ spaces/special\ tool/.build/debug/special\ tool
+# RUN: %t.dir/more\ spaces/special\ tool/.build/debug/special\ tool > %t.out
+# RUN: %{FileCheck} --check-prefix CHECK-TOOL-OUTPUT --input-file %t.out %s
+#
+# CHECK-TOOL-OUTPUT: HI
diff --git a/test b/test
new file mode 100755
index 0000000..ec87c1e
--- /dev/null
+++ b/test
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+set -ex
+
+# Delegate to lit to actually test.
+python ../llvm/utils/lit/lit.py "$@"
diff --git a/test-c-library-swiftpm/test.py b/test-c-library-swiftpm/test.py
new file mode 100644
index 0000000..2530536
--- /dev/null
+++ b/test-c-library-swiftpm/test.py
@@ -0,0 +1,48 @@
+# Test swiftpm's ability to link C libraries
+#
+# Needs a common C lib on all our test machines first.
+# REQUIRES: have-zlib
+# REQUIRES: platform=Linux
+#
+# Make a sandbox dir. Copy our sources over.
+#
+# RUN: rm -rf %t.dir
+# RUN: mkdir -p %t.dir/
+# RUN: cp -R %S/testApp %t.dir/
+# RUN: cp -R %S/z %t.dir/
+
+# RUN: rm -rf %t.dir/.build
+
+# Create the git repo for the Z lib package
+# RUN: git -C %t.dir/z init
+# RUN: git -C %t.dir/z add .
+# RUN: git -C %t.dir/z config user.name "Test User"
+# RUN: git -C %t.dir/z config user.email "test@user.com"
+# RUN: git -C %t.dir/z commit -m "Creating package"
+# RUN: git -C %t.dir/z tag 1.0.0
+
+# RUN: %{swift} build --chdir %t.dir/testApp > %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 'testApp'
+
+# Verify that the build worked.
+#
+# RUN: test -x %t.dir/testApp/.build/debug/testApp
+# RUN: %t.dir/testApp/.build/debug/testApp > %t.out
+# RUN: %{FileCheck} --check-prefix CHECK-APP-OUTPUT --input-file %t.out %s
+#
+#
+# CHECK-APP-OUTPUT: gzFile_s(have: 0, next: 0x0000000000000000, pos: 0)
+# CHECK-APP-OUTPUT-NEXT: OK
+
+# Verify that another 'swift build' does nothing.
+#
+# RUN: %{swift} build --chdir %t.dir/testApp > %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
diff --git a/test-c-library-swiftpm/testApp/Package.swift b/test-c-library-swiftpm/testApp/Package.swift
new file mode 100644
index 0000000..9638892
--- /dev/null
+++ b/test-c-library-swiftpm/testApp/Package.swift
@@ -0,0 +1,7 @@
+import PackageDescription
+
+let package = Package(
+  dependencies: [
+    .Package(url: "../z", majorVersion: 1),
+  ]
+)
diff --git a/test-c-library-swiftpm/testApp/main.swift b/test-c-library-swiftpm/testApp/main.swift
new file mode 100644
index 0000000..e9a9eb1
--- /dev/null
+++ b/test-c-library-swiftpm/testApp/main.swift
@@ -0,0 +1,7 @@
+import Zlib
+
+let foo = gzFile_s()
+
+print(foo)
+print("OK")
+
diff --git a/test-c-library-swiftpm/z/Package.swift b/test-c-library-swiftpm/z/Package.swift
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test-c-library-swiftpm/z/Package.swift
diff --git a/test-c-library-swiftpm/z/module.modulemap b/test-c-library-swiftpm/z/module.modulemap
new file mode 100644
index 0000000..3554ac8
--- /dev/null
+++ b/test-c-library-swiftpm/z/module.modulemap
@@ -0,0 +1,5 @@
+module Zlib [system] {
+    header "/usr/include/zlib.h"
+    link "z"
+    export *
+}
diff --git a/test-foundation-package/main.swift b/test-foundation-package/main.swift
new file mode 100644
index 0000000..a168b06
--- /dev/null
+++ b/test-foundation-package/main.swift
@@ -0,0 +1,8 @@
+import Foundation
+
+let x = NSURL(fileURLWithPath: "/tmp")
+
+print ("Printing URL")
+print(x.path!)
+print ("Done printing URL")
+
diff --git a/test-foundation-package/test-foundation-package.py b/test-foundation-package/test-foundation-package.py
new file mode 100644
index 0000000..3e2450e
--- /dev/null
+++ b/test-foundation-package/test-foundation-package.py
@@ -0,0 +1,25 @@
+# Trivial test for importing Foundation
+#
+# 
+# Make a sandbox dir.
+# RUN: rm -rf %t.dir
+# RUN: mkdir -p %t.dir/tool
+# RUN: touch %t.dir/tool/Package.swift
+# RUN: cp %S/main.swift %t.dir/tool/main.swift
+# RUN: %{swift} build --chdir %t.dir/tool -v > %t.build-log
+
+# Check the build log.
+#
+# RUN: %{FileCheck} --check-prefix CHECK-BUILD-LOG --input-file %t.build-log %s
+#
+# CHECK-BUILD-LOG: swiftc{{.*}} -module-name tool
+
+# Verify that the tool exists and works.
+#
+# RUN: test -x %t.dir/tool/.build/debug/tool
+# RUN: %t.dir/tool/.build/debug/tool > %t.out
+# RUN: %{FileCheck} --check-prefix CHECK-TOOL-OUTPUT --input-file %t.out %s
+#
+# CHECK-TOOL-OUTPUT: Printing URL
+# CHECK-TOOL-OUTPUT-NEXT: /tmp
+# CHECK-TOOL-OUTPUT-NEXT: Done printing URL
diff --git a/test-import-glibc/import-glibc.swift b/test-import-glibc/import-glibc.swift
new file mode 100644
index 0000000..6b9515b
--- /dev/null
+++ b/test-import-glibc/import-glibc.swift
@@ -0,0 +1,3 @@
+import Glibc
+
+print("Hello Glibc")
diff --git a/test-import-glibc/test-import-glibc.py b/test-import-glibc/test-import-glibc.py
new file mode 100644
index 0000000..e60b9f0
--- /dev/null
+++ b/test-import-glibc/test-import-glibc.py
@@ -0,0 +1,21 @@
+# Test import of Glibc, on Linux.
+#
+# REQUIRES: platform=Linux
+
+# RUN: rm -rf %t.dir
+# RUN: mkdir %t.dir
+# RUN: cp %S/import-glibc.swift %t.dir/import-glibc.swift
+# RUN: %{swiftc} %t.dir/import-glibc.swift -o %t.dir/main
+
+# Check exists
+#
+# RUN: ls %t.dir/ > %t.dir/listing
+# RUN: %{FileCheck} --check-prefix CL --input-file %t.dir/listing %s
+# CL: main
+
+# Check file runs (it prints Hello Glibc)
+# 
+# RUN: %t.dir/main > %t.dir/out
+# RUN: %{FileCheck} --check-prefix CO --input-file %t.dir/out %s
+# CO: Hello Glibc
+
diff --git a/test-multi-compile-glibc/goodbye.swift b/test-multi-compile-glibc/goodbye.swift
new file mode 100644
index 0000000..6793088
--- /dev/null
+++ b/test-multi-compile-glibc/goodbye.swift
@@ -0,0 +1 @@
+hello()
diff --git a/test-multi-compile-glibc/hello.swift b/test-multi-compile-glibc/hello.swift
new file mode 100644
index 0000000..03a6bf2
--- /dev/null
+++ b/test-multi-compile-glibc/hello.swift
@@ -0,0 +1,5 @@
+import Glibc
+
+public func hello() {
+    print("hello")
+}
diff --git a/test-multi-compile-glibc/main.swift b/test-multi-compile-glibc/main.swift
new file mode 100644
index 0000000..6793088
--- /dev/null
+++ b/test-multi-compile-glibc/main.swift
@@ -0,0 +1 @@
+hello()
diff --git a/test-multi-compile-glibc/swift-multi-compile-glibc.py b/test-multi-compile-glibc/swift-multi-compile-glibc.py
new file mode 100644
index 0000000..39fc96c
--- /dev/null
+++ b/test-multi-compile-glibc/swift-multi-compile-glibc.py
@@ -0,0 +1,21 @@
+# Tests that multiple files are compiled correctly
+#
+# REQUIRES: platform=Linux
+# RUN: rm -rf %t.dir
+# RUN: mkdir %t.dir
+# RUN: cp %S/hello.swift %t.dir/hello.swift
+# RUN: cp %S/goodbye.swift %t.dir/main.swift
+# RUN: %{swiftc} %t.dir/hello.swift %t.dir/main.swift -o %t.dir/main
+
+# Check exists
+# 
+# RUN: ls %t.dir/ > %t.listing
+# RUN: %{FileCheck} --check-prefix CL --input-file %t.listing %s
+# CL: main
+
+# Check file runs
+# 
+# RUN: %t.dir/main > %t.out
+# RUN: %{FileCheck} --check-prefix CO --input-file %t.out %s
+# CO: hello
+
diff --git a/test-multi-compile/goodbye.swift b/test-multi-compile/goodbye.swift
new file mode 100644
index 0000000..6793088
--- /dev/null
+++ b/test-multi-compile/goodbye.swift
@@ -0,0 +1 @@
+hello()
diff --git a/test-multi-compile/hello.swift b/test-multi-compile/hello.swift
new file mode 100644
index 0000000..52ed6d6
--- /dev/null
+++ b/test-multi-compile/hello.swift
@@ -0,0 +1,3 @@
+public func hello() {
+    print("hello")
+}
diff --git a/test-multi-compile/main.swift b/test-multi-compile/main.swift
new file mode 100644
index 0000000..6793088
--- /dev/null
+++ b/test-multi-compile/main.swift
@@ -0,0 +1 @@
+hello()
diff --git a/test-multi-compile/swift-multi-compile.py b/test-multi-compile/swift-multi-compile.py
new file mode 100644
index 0000000..bc56d27
--- /dev/null
+++ b/test-multi-compile/swift-multi-compile.py
@@ -0,0 +1,20 @@
+# Tests that compiling multiple swift files works.
+#
+# RUN: rm -rf %t.dir
+# RUN: mkdir %t.dir
+# RUN: cp %S/hello.swift %t.dir/hello.swift
+# RUN: cp %S/goodbye.swift %t.dir/main.swift
+# RUN: %{swiftc} %t.dir/hello.swift %t.dir/main.swift -o %t.dir/main
+
+# Check exists
+# 
+# RUN: ls %t.dir/ > %t.listing
+# RUN: %{FileCheck} --check-prefix CL --input-file %t.listing %s
+# CL: main
+
+# Check file runs
+# 
+# RUN: %t.dir/main > %t.out
+# RUN: %{FileCheck} --check-prefix CO --input-file %t.out %s
+# CO: hello
+
diff --git a/test-static-lib/main.swift b/test-static-lib/main.swift
new file mode 100644
index 0000000..d4db48c
--- /dev/null
+++ b/test-static-lib/main.swift
@@ -0,0 +1,3 @@
+import staticLib
+
+hello()
diff --git a/test-static-lib/staticLib.swift b/test-static-lib/staticLib.swift
new file mode 100644
index 0000000..52ed6d6
--- /dev/null
+++ b/test-static-lib/staticLib.swift
@@ -0,0 +1,3 @@
+public func hello() {
+    print("hello")
+}
diff --git a/test-static-lib/test-static-lib.py b/test-static-lib/test-static-lib.py
new file mode 100644
index 0000000..fac6575
--- /dev/null
+++ b/test-static-lib/test-static-lib.py
@@ -0,0 +1,14 @@
+# Tests that creating a static lib and importing it into a file works
+
+# RUN: rm -rf %t.dir
+# RUN: mkdir %t.dir
+# RUN: cp %S/staticLib.swift %t.dir/staticLib.swift
+# RUN: cp %S/main.swift %t.dir/main.swift
+# RUN: %{swiftc} -emit-object %t.dir/staticLib.swift -module-name staticLib -parse-as-library -emit-module -emit-module-path %t.dir/staticLib.swiftmodule -o %t.dir/staticLib.o -force-single-frontend-invocation
+# RUN: ar -rs %t.dir/staticLib.a %t.dir/staticLib.o
+
+# Compile a swift program linking the static library
+# RUN: %{swiftc} -I %t.dir -L %t.dir %t.dir/main.swift -o %t.dir/mainWithLib -Xlinker %t.dir/staticLib.a
+# RUN: %t.dir/mainWithLib > %t.dir/output
+# RUN: %{FileCheck} --input-file %t.dir/output %s
+# CHECK: hello
diff --git a/test-xctest-package/main.swift b/test-xctest-package/main.swift
new file mode 100644
index 0000000..7295239
--- /dev/null
+++ b/test-xctest-package/main.swift
@@ -0,0 +1,11 @@
+import XCTest
+
+class MyXCTest : XCTestCase {
+    var allTests : [(String, () -> ())] {
+        return []
+    }
+}
+
+let x = MyXCTest()
+
+print("HI")
diff --git a/test-xctest-package/test-xctest-package.py b/test-xctest-package/test-xctest-package.py
new file mode 100644
index 0000000..3c0bd9a
--- /dev/null
+++ b/test-xctest-package/test-xctest-package.py
@@ -0,0 +1,28 @@
+# Trivial test for importing XCTest.
+#
+
+# This test doesn't work on Darwin yet, because the XCTest overlay isn't shipped
+# with the package, and can't be found:#
+#   <rdar://problem/23600043> Cannot import XCTest with swift from a downloadable package
+# REQUIRES: platform=Linux
+#
+# Make a sandbox dir.
+# RUN: rm -rf %t.dir
+# RUN: mkdir -p %t.dir/tool
+# RUN: touch %t.dir/tool/Package.swift
+# RUN: cp %S/main.swift %t.dir/tool/main.swift
+# RUN: %{swift} build --chdir %t.dir/tool -v > %t.build-log
+
+# Check the build log.
+#
+# RUN: %{FileCheck} --check-prefix CHECK-BUILD-LOG --input-file %t.build-log %s
+#
+# CHECK-BUILD-LOG: swiftc{{.*}} -module-name tool
+
+# Verify that the tool exists and works.
+#
+# RUN: test -x %t.dir/tool/.build/debug/tool
+# RUN: %t.dir/tool/.build/debug/tool > %t.out
+# RUN: %{FileCheck} --check-prefix CHECK-TOOL-OUTPUT --input-file %t.out %s
+#
+# CHECK-TOOL-OUTPUT: HI