Skip to content

Commit 205248d

Browse files
committed
Merge pull request #7 from ddunbar/test-for-PR373
Add a test that `swift package update` checks for modified packages.
2 parents 58066bd + 572ab9f commit 205248d

File tree

4 files changed

+81
-0
lines changed

4 files changed

+81
-0
lines changed

lit.cfg

+1
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ if not os.path.exists(lldb_path):
171171
lit_config.fatal("lldb does not exist!")
172172

173173
# Define our supported substitutions.
174+
config.substitutions.append( ('%{not}', os.path.join(srcroot, "not")) )
174175
config.substitutions.append( ('%{lldb}', lldb_path) )
175176
config.substitutions.append( ('%{swift}', swift_path) )
176177
config.substitutions.append( ('%{swiftc}', swiftc_path) )

litTest

100644100755
File mode changed.

not

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
3+
# Check that a command terminates with an error exit code.
4+
if "$@"; then
5+
echo "error: unexpected successful exit: " "$@" 1>&2
6+
exit 1
7+
fi
8+
exit 0

swift-update-safety.md

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Test the safety of `swift package update`.
2+
3+
Establish our sandbox.
4+
5+
```
6+
RUN: rm -rf %t.dir
7+
```
8+
9+
Create a dummy package.
10+
11+
```
12+
RUN: mkdir -p %t.dir/Dep
13+
RUN: %{swift} package -C %t.dir/Dep init=library
14+
RUN: git -C %t.dir/Dep init
15+
RUN: git -C %t.dir/Dep add -A
16+
RUN: git -C %t.dir/Dep commit -m "Initial commit."
17+
RUN: git -C %t.dir/Dep tag 1.0.0
18+
```
19+
20+
Create the test package.
21+
22+
```
23+
RUN: mkdir -p %t.dir/Cmd
24+
RUN: %{swift} package -C %t.dir/Cmd init=executable
25+
RUN: echo "import PackageDescription" > %t.dir/Cmd/Package.swift
26+
RUN: echo "let package = Package(" >> %t.dir/Cmd/Package.swift
27+
RUN: echo " name: \"Cmd\"," >> %t.dir/Cmd/Package.swift
28+
RUN: echo " dependencies: [.Package(url: \"../Dep\", Version(1,0,0))]" >> %t.dir/Cmd/Package.swift
29+
RUN: echo ")" >> %t.dir/Cmd/Package.swift
30+
```
31+
32+
Build the test package.
33+
34+
```
35+
RUN: mkdir -p %t.dir/Cmd
36+
RUN: %{swift} build -C %t.dir/Cmd &> %t.build-log
37+
RUN: %{FileCheck} --check-prefix CHECK-BUILD-LOG --input-file %t.build-log %s
38+
39+
CHECK-BUILD-LOG: Compile Swift Module 'Cmd'
40+
```
41+
42+
Validate we can run `--update`.
43+
44+
```
45+
RUN: %{swift} package -C %t.dir/Cmd update
46+
```
47+
48+
Modify the sources of the dependency.
49+
50+
```
51+
RUN: test -f %t.dir/Cmd/Packages/Dep-1.0.0/Sources/Dep.swift
52+
RUN: echo "INVALID CODE" >> %t.dir/Cmd/Packages/Dep-1.0.0/Sources/Dep.swift
53+
```
54+
55+
Validate that `--update` errors out.
56+
57+
```
58+
RUN: %{not} %{swift} package -C %t.dir/Cmd update
59+
```
60+
61+
Stage the changes we made and verify it is still an error.
62+
63+
```
64+
RUN: git -C %t.dir/Cmd/Packages/Dep-1.0.0 add Sources/Dep.swift
65+
RUN: %{not} %{swift} package -C %t.dir/Cmd update
66+
```
67+
68+
Validate we still have our modified source.
69+
70+
```
71+
RUN: grep "INVALID CODE" %t.dir/Cmd/Packages/Dep-1.0.0/Sources/Dep.swift
72+
```

0 commit comments

Comments
 (0)