Skip to content

Commit 1779745

Browse files
committed
Add a unit test for the package command plugin template
1 parent 15905c9 commit 1779745

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

Tests/WorkspaceTests/InitTests.swift

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift open source project
44
//
5-
// Copyright (c) 2014-2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014-2023 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See http://swift.org/LICENSE.txt for license information
@@ -149,6 +149,34 @@ class InitTests: XCTestCase {
149149
}
150150
}
151151

152+
func testInitPackageCommandPlugin() throws {
153+
try testWithTemporaryDirectory { tmpPath in
154+
let fs = localFileSystem
155+
let path = tmpPath.appending("MyCommandPlugin")
156+
let name = path.basename
157+
try fs.createDirectory(path)
158+
159+
// Create the package
160+
try InitPackage(
161+
name: name,
162+
packageType: .commandPlugin,
163+
destinationPath: path,
164+
fileSystem: localFileSystem
165+
).writePackageStructure()
166+
167+
// Verify basic file system content that we expect in the package
168+
let manifest = path.appending("Package.swift")
169+
XCTAssertFileExists(manifest)
170+
let manifestContents: String = try localFileSystem.readFileContents(manifest)
171+
XCTAssertMatch(manifestContents, .and(.contains(".plugin("), .contains("capability: .command(intent: .custom(verb")))
172+
173+
let source = path.appending("Plugins", "MyCommandPlugin", "plugin.swift")
174+
XCTAssertFileExists(source)
175+
let sourceContents: String = try localFileSystem.readFileContents(source)
176+
XCTAssertMatch(sourceContents, .contains("struct MyCommandPlugin: CommandPlugin"))
177+
}
178+
}
179+
152180
// MARK: Special case testing
153181

154182
func testInitPackageNonc99Directory() throws {

0 commit comments

Comments
 (0)