Skip to content

Commit c204398

Browse files
committed
Add a couple swift package init tests.
- In particular, they check that the initial packages build and test without warnings. - Catches: https://bugs.swift.org/browse/SR-1606
1 parent e1052b0 commit c204398

File tree

3 files changed

+93
-2
lines changed

3 files changed

+93
-2
lines changed

lit.cfg

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ config.test_format = lit.formats.ShTest(execute_external = False)
5353
# suffixes: A list of file extensions to treat as test files.
5454
#
5555
# We override this in specific subdirectories to change what we test.
56-
config.suffixes = [".txt", ".py"]
56+
config.suffixes = [".txt", ".py", ".md"]
5757

5858
# excludes: A list of directories to exclude from the testsuite. The 'Inputs'
5959
# subdirectories contain auxiliary inputs for various tests in their parent
6060
# directories.
61-
config.excludes = ['Inputs']
61+
config.excludes = ['README.md', 'CONTRIBUTING.md', 'Inputs']
6262

6363
# test_source_root: The root path where tests are located.
6464
config.test_source_root = os.path.join(srcroot)
@@ -84,6 +84,7 @@ elif platform.system() == 'Darwin':
8484
#
8585
# FIXME: Eventually, when we use xcrun to launch the toolchain items, this
8686
# should go away.
87+
config.environment["HOME"] = os.getenv("HOME")
8788
if platform.system() == "Darwin":
8889
config.environment["SDKROOT"] = subprocess.check_output(
8990
["xcrun", "--sdk", "macosx", "--show-sdk-path"]).strip()

swift-package-init-exec.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Test `swift package init` (executable)
2+
3+
## Create a new package with an executable target.
4+
5+
```
6+
RUN: rm -rf %t.dir
7+
RUN: mkdir -p %t.dir/Project
8+
RUN: %{swift} package --chdir %t.dir/Project init=executable
9+
RUN: %{swift} build --chdir %t.dir/Project &> %t.build-log
10+
```
11+
12+
## Check the build log.
13+
14+
```
15+
RUN: %{FileCheck} --check-prefix CHECK-BUILD-LOG --input-file %t.build-log %s
16+
```
17+
18+
```
19+
CHECK-BUILD-LOG: Compile Swift Module 'Project'
20+
CHECK-BUILD-LOG: Linking {{.*}}Project
21+
```
22+
23+
## Verify that the tool was built and works.
24+
25+
```
26+
RUN: test -x %t.dir/Project/.build/debug/Project
27+
RUN: %t.dir/Project/.build/debug/Project > %t.out
28+
RUN: %{FileCheck} --check-prefix CHECK-TOOL-OUTPUT --input-file %t.out %s
29+
```
30+
31+
```
32+
CHECK-TOOL-OUTPUT: Hello, world!
33+
```
34+
35+
## Check there were no compile errors or warnings.
36+
37+
```
38+
RUN: %{FileCheck} --check-prefix CHECK-NO-WARNINGS-OR-ERRORS --input-file %t.build-log %s
39+
```
40+
41+
```
42+
CHECK-NO-WARNINGS-OR-ERRORS-NOT: warning
43+
CHECK-NO-WARNINGS-OR-ERRORS-NOT: error
44+
```

swift-package-init-lib.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
# Test `swift package init` (library)
3+
4+
## Create a new package with an executable target.
5+
6+
```
7+
RUN: rm -rf %t.dir
8+
RUN: mkdir -p %t.dir/Project
9+
RUN: %{swift} package --chdir %t.dir/Project init=library
10+
RUN: %{swift} build --chdir %t.dir/Project &> %t.build-log
11+
RUN: %{swift} test --chdir %t.dir/Project &> %t.test-log
12+
```
13+
14+
## Check the build log.
15+
16+
```
17+
RUN: %{FileCheck} --check-prefix CHECK-BUILD-LOG --input-file %t.build-log %s
18+
```
19+
20+
```
21+
CHECK-BUILD-LOG: Compile Swift Module 'Project'
22+
```
23+
24+
## Check the test log.
25+
26+
```
27+
RUN: %{FileCheck} --check-prefix CHECK-TEST-LOG --input-file %t.test-log %s
28+
```
29+
30+
```
31+
CHECK-TEST-LOG: Compile Swift Module 'ProjectTestSuite'
32+
CHECK-TEST-LOG: Test Suite 'All tests' passed
33+
CHECK-TEST-LOG-NEXT: Executed 1 test
34+
```
35+
36+
## Check there were no compile errors or warnings.
37+
38+
```
39+
RUN: %{FileCheck} --check-prefix CHECK-NO-WARNINGS-OR-ERRORS --input-file %t.build-log %s
40+
RUN: %{FileCheck} --check-prefix CHECK-NO-WARNINGS-OR-ERRORS --input-file %t.test-log %s
41+
```
42+
43+
```
44+
CHECK-NO-WARNINGS-OR-ERRORS-NOT: warning
45+
CHECK-NO-WARNINGS-OR-ERRORS-NOT: error
46+
```

0 commit comments

Comments
 (0)