diff --git a/lit.cfg b/lit.cfg index 464ad64..56375a4 100644 --- a/lit.cfg +++ b/lit.cfg @@ -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) ) diff --git a/litTest b/litTest old mode 100644 new mode 100755 diff --git a/not b/not new file mode 100755 index 0000000..825e0f7 --- /dev/null +++ b/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 diff --git a/swift-update-safety.md b/swift-update-safety.md new file mode 100644 index 0000000..dffc1a9 --- /dev/null +++ b/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 +```