Skip to content

Add finer-grain reference tests for translation phase #103

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

Merged
merged 14 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ extension TestConfig {
}

/// Tests that the generator produces Swift files that match a reference.
class ReferenceTests: XCTestCase {
class FileBasedReferenceTests: XCTestCase {
override func setUp() {
super.setUp()
continueAfterFailure = false
Expand Down Expand Up @@ -82,10 +82,8 @@ class ReferenceTests: XCTestCase {
)

// Run the requested generator invocation
let diagnostics: any DiagnosticCollector = strictDiagnosticsCollector
let generatorPipeline = self.makeGeneratorPipeline(
config: referenceTest.asConfig,
diagnostics: diagnostics
config: referenceTest.asConfig
)
let generatedOutputSource = try generatorPipeline.run(input)

Expand Down Expand Up @@ -143,32 +141,8 @@ class ReferenceTests: XCTestCase {
}
}

struct StrictDiagnosticsCollector: DiagnosticCollector {
var test: XCTestCase

func emit(_ diagnostic: Diagnostic) {
print("Test emitted diagnostic: \(diagnostic.description)")
switch diagnostic.severity {
case .note:
// no need to fail, just print
break
case .warning, .error:
XCTFail("Failing with a diagnostic: \(diagnostic.description)")
}
}
}

extension ReferenceTests {

var strictDiagnosticsCollector: any DiagnosticCollector {
StrictDiagnosticsCollector(test: self)
}

private func makeGeneratorPipeline(
config: Config,
diagnostics: any DiagnosticCollector
) -> GeneratorPipeline {

extension FileBasedReferenceTests {
private func makeGeneratorPipeline(config: Config) -> GeneratorPipeline {
let parser = YamsParser()
let translator = MultiplexTranslator()
let renderer = TextBasedRenderer()
Expand All @@ -183,7 +157,7 @@ extension ReferenceTests {
return newFile
},
config: config,
diagnostics: diagnostics
diagnostics: XCTestDiagnosticCollector(test: self)
)
}

Expand Down
Loading