Skip to content

Commit

Permalink
Add carton init with template test. Supports #99 (#221)
Browse files Browse the repository at this point in the history
* Added init with template test. Supports #99

* Moved expectedTemplateSource outside of test function.  Supports #99

Co-authored-by: thecb4 <cavelle@tehcb4.io>
  • Loading branch information
thecb4 and thecb4 authored Feb 14, 2021
1 parent 2385b04 commit 45850d6
Showing 1 changed file with 81 additions and 0 deletions.
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()
"""
}

0 comments on commit 45850d6

Please sign in to comment.