54 lines
2.2 KiB
Swift
54 lines
2.2 KiB
Swift
//
|
|
// SwiftGen
|
|
// Copyright © 2022 SwiftGen
|
|
// MIT Licence
|
|
//
|
|
|
|
@testable import SwiftGenCLI
|
|
import TestUtils
|
|
import XCTest
|
|
import Yams
|
|
|
|
final class ConfigInitTests: XCTestCase {
|
|
func testExampleConfigIsValid() {
|
|
do {
|
|
// Try to load the config generated by the template to validate that it parses
|
|
let content = Config.example(versionForDocLink: "develop", commentAllLines: false)
|
|
let config = try Config(content: content, env: [:], sourcePath: ".") { level, msg in
|
|
XCTFail("The template configuration generated a log message when parsing the config: \(level):\(msg)")
|
|
}
|
|
|
|
XCTAssertEqual(config.inputDir, "MyLib/Sources/")
|
|
XCTAssertEqual(config.outputDir, "MyLib/Generated/")
|
|
XCTAssertEqual(config.commandNames, ["strings", "xcassets", "ib"])
|
|
|
|
// Lint the config to check it doesn't have any lint errors other than the ones from placeholder values
|
|
let expectedErrors = [
|
|
Config.Message.doesntExist("input_dir: Input directory MyLib/Sources/"),
|
|
Config.Message.doesntExist("output_dir: Output directory MyLib/Generated/"),
|
|
Config.Message.doesntExist("strings.inputs: MyLib/Sources/Resources/Base.lproj"),
|
|
Config.Message.doesntExistIntermediatesNeeded("strings.outputs.output: MyLib/Generated"),
|
|
Config.Message.doesntExist("ib.inputs: MyLib/Sources"),
|
|
Config.Message.doesntExistIntermediatesNeeded("ib.outputs.output: MyLib/Generated"),
|
|
Config.Message.doesntExistIntermediatesNeeded("ib.outputs.output: MyLib/Generated"),
|
|
Config.Message.doesntExist("xcassets.inputs: MyLib/Sources/Main.xcassets"),
|
|
Config.Message.doesntExist("xcassets.inputs: MyLib/Sources/ProFeatures.xcassets"),
|
|
Config.Message.doesntExistIntermediatesNeeded("xcassets.outputs.output: MyLib/Generated")
|
|
]
|
|
config.lint { level, msg in
|
|
if (level == .error && expectedErrors.contains(msg)) || level == .info {
|
|
return
|
|
}
|
|
XCTFail(
|
|
"""
|
|
The template configuration generated a log message when linting the config:
|
|
"\(level): \(msg)"
|
|
"""
|
|
)
|
|
}
|
|
} catch let error {
|
|
XCTFail("The template configuration generated an error when processing the config: \(error)")
|
|
}
|
|
}
|
|
}
|