Skip to content

Commit 3d11ea3

Browse files
committed
adds functional test that verifies show-dependencies includes traits output
- check for one of the traits included in dependencies in text output - verify the JSON format output includes each of the traits
1 parent d37615c commit 3d11ea3

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Tests/CommandsTests/PackageCommandTests.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,30 @@ class PackageCommandTestCase: CommandsBuildProviderTestCase {
660660
}
661661
}
662662

663+
func testShowDependenciesWithTraits() async throws {
664+
// swift test --filter CommandsTests.PackageCommandNativeTests/testShowDependenciesWithTraits # this specific test
665+
try await fixtureXCTest(name: "Traits") { fixturePath in
666+
667+
let packageRoot = fixturePath.appending("Example")
668+
let (textOutput, _) = try await self.execute(["show-dependencies", "--format=text"], packagePath: packageRoot)
669+
XCTAssert(textOutput.contains("(traits: Package3Trait3)"))
670+
671+
let (jsonOutput, _) = try await self.execute(["show-dependencies", "--format=json"], packagePath: packageRoot)
672+
let json = try JSON(bytes: ByteString(encodingAsUTF8: jsonOutput))
673+
guard case let .dictionary(contents) = json else { XCTFail("unexpected result"); return }
674+
guard case let .string(name)? = contents["name"] else { XCTFail("unexpected result"); return }
675+
XCTAssertEqual(name, "TraitsExample")
676+
677+
// verify the traits JSON entry lists each of the traits in the fixture
678+
guard case let .string(traitsProperty)? = contents["traits"] else { XCTFail("unexpected result"); return }
679+
XCTAssert(traitsProperty.contains("Package1"))
680+
XCTAssert(traitsProperty.contains("Package2"))
681+
XCTAssert(traitsProperty.contains("Package3"))
682+
XCTAssert(traitsProperty.contains("Package4"))
683+
XCTAssert(traitsProperty.contains("BuildCondition1"))
684+
}
685+
}
686+
663687
func testShowDependencies_dotFormat_sr12016() throws {
664688
// Confirm that SR-12016 is resolved.
665689
// See https://bugs.swift.org/browse/SR-12016

0 commit comments

Comments
 (0)