Skip to content

Commit

Permalink
Merge pull request #7 from ddunbar/test-for-PR373
Browse files Browse the repository at this point in the history
Add a test that `swift package update` checks for modified packages.
  • Loading branch information
tkremenek committed May 27, 2016
2 parents 58066bd + 572ab9f commit 205248d
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 0 deletions.
1 change: 1 addition & 0 deletions lit.cfg
Expand Up @@ -171,6 +171,7 @@ if not os.path.exists(lldb_path):
lit_config.fatal("lldb does not exist!")

# Define our supported substitutions.
config.substitutions.append( ('%{not}', os.path.join(srcroot, "not")) )
config.substitutions.append( ('%{lldb}', lldb_path) )
config.substitutions.append( ('%{swift}', swift_path) )
config.substitutions.append( ('%{swiftc}', swiftc_path) )
Expand Down
Empty file modified litTest 100644 → 100755
Empty file.
8 changes: 8 additions & 0 deletions not
@@ -0,0 +1,8 @@
#!/bin/sh

# Check that a command terminates with an error exit code.
if "$@"; then
echo "error: unexpected successful exit: " "$@" 1>&2
exit 1
fi
exit 0
72 changes: 72 additions & 0 deletions swift-update-safety.md
@@ -0,0 +1,72 @@
# Test the safety of `swift package update`.

Establish our sandbox.

```
RUN: rm -rf %t.dir
```

Create a dummy package.

```
RUN: mkdir -p %t.dir/Dep
RUN: %{swift} package -C %t.dir/Dep init=library
RUN: git -C %t.dir/Dep init
RUN: git -C %t.dir/Dep add -A
RUN: git -C %t.dir/Dep commit -m "Initial commit."
RUN: git -C %t.dir/Dep tag 1.0.0
```

Create the test package.

```
RUN: mkdir -p %t.dir/Cmd
RUN: %{swift} package -C %t.dir/Cmd init=executable
RUN: echo "import PackageDescription" > %t.dir/Cmd/Package.swift
RUN: echo "let package = Package(" >> %t.dir/Cmd/Package.swift
RUN: echo " name: \"Cmd\"," >> %t.dir/Cmd/Package.swift
RUN: echo " dependencies: [.Package(url: \"../Dep\", Version(1,0,0))]" >> %t.dir/Cmd/Package.swift
RUN: echo ")" >> %t.dir/Cmd/Package.swift
```

Build the test package.

```
RUN: mkdir -p %t.dir/Cmd
RUN: %{swift} build -C %t.dir/Cmd &> %t.build-log
RUN: %{FileCheck} --check-prefix CHECK-BUILD-LOG --input-file %t.build-log %s
CHECK-BUILD-LOG: Compile Swift Module 'Cmd'
```

Validate we can run `--update`.

```
RUN: %{swift} package -C %t.dir/Cmd update
```

Modify the sources of the dependency.

```
RUN: test -f %t.dir/Cmd/Packages/Dep-1.0.0/Sources/Dep.swift
RUN: echo "INVALID CODE" >> %t.dir/Cmd/Packages/Dep-1.0.0/Sources/Dep.swift
```

Validate that `--update` errors out.

```
RUN: %{not} %{swift} package -C %t.dir/Cmd update
```

Stage the changes we made and verify it is still an error.

```
RUN: git -C %t.dir/Cmd/Packages/Dep-1.0.0 add Sources/Dep.swift
RUN: %{not} %{swift} package -C %t.dir/Cmd update
```

Validate we still have our modified source.

```
RUN: grep "INVALID CODE" %t.dir/Cmd/Packages/Dep-1.0.0/Sources/Dep.swift
```

0 comments on commit 205248d

Please sign in to comment.