Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add carton init with template test. Supports #99 #221

Merged
merged 2 commits into from
Feb 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions Tests/CartonCommandTests/InitCommandTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,85 @@ final class InitCommandTests: XCTestCase {
// finally, clean up
try packageDirectory.delete()
}

func testInitWithTokamakTemplate() throws {
// given I've created a directory
let package = "fusion"
let packageDirectory = testFixturesDirectory.appending(component: package)

// it's ok if there is nothing to delete
do { try packageDirectory.delete() } catch {}

try packageDirectory.mkdir()

XCTAssertTrue(packageDirectory.exists, "Did not create \(package) directory")

AssertExecuteCommand(
command: "carton init --template tokamak",
cwd: packageDirectory.url
)

// Confirm that the files are actually in the folder
XCTAssertTrue(packageDirectory.ls().contains("Package.swift"), "Package.swift does not exist")
XCTAssertTrue(packageDirectory.ls().contains("README.md"), "README.md does not exist")
XCTAssertTrue(packageDirectory.ls().contains(".gitignore"), ".gitignore does not exist")
XCTAssertTrue(packageDirectory.ls().contains("Sources"), "Sources does not exist")
XCTAssertTrue(
packageDirectory.ls().contains("Sources/\(package)"),
"Sources/\(package) does not exist"
)
XCTAssertTrue(
packageDirectory.ls().contains("Sources/\(package)/main.swift"),
"Sources/\(package)/main.swift does not exist"
)
XCTAssertTrue(packageDirectory.ls().contains("Tests"), "Tests does not exist")
XCTAssertTrue(
packageDirectory.ls().contains("Tests/LinuxMain.swift"),
"Tests/LinuxMain.swift does not exist"
)
XCTAssertTrue(
packageDirectory.ls().contains("Tests/\(package)Tests"),
"Tests/\(package)Tests does not exist"
)
XCTAssertTrue(
packageDirectory.ls().contains("Tests/\(package)Tests/\(package)Tests.swift"),
"Tests/\(package)Tests/\(package)Tests.swift does not exist"
)
XCTAssertTrue(
packageDirectory.ls().contains("Tests/\(package)Tests/XCTestManifests.swift"),
"Tests/\(package)Tests/XCTestManifests.swift does not exist"
)

let actualTemplateSource = try String(contentsOfFile: packageDirectory
.appending(components: "Sources", package, "main.swift").pathString)

XCTAssertEqual(expectedTemplateSource, actualTemplateSource, "Template Sources do not match")

// finally, clean up
try packageDirectory.delete()
}

let expectedTemplateSource =
"""
import TokamakDOM

struct TokamakApp: App {
var body: some Scene {
WindowGroup("Tokamak App") {
ContentView()
}
}
}

struct ContentView: View {
var body: some View {
Text("Hello, world!")
}
}

// @main attribute is not supported in SwiftPM apps.
// See https://bugs.swift.org/browse/SR-12683 for more details.
TokamakApp.main()

"""
}