Skip to content

Commit

Permalink
Rename and properly document ValTestRunner => AnnotatedValFileTest
Browse files Browse the repository at this point in the history
  • Loading branch information
dabrahams committed Jan 4, 2023
1 parent f219ec4 commit 6224086
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 20 deletions.
6 changes: 3 additions & 3 deletions Tests/ValTests/CXXTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import FrontEnd
import Utils
import XCTest

final class CXXTests: XCTestCase, ValTestRunner {
final class CXXTests: XCTestCase, AnnotatedValFileTest {

static var testCaseDirectoryPath: String { "TestCases/CXX" }
static var valSourceDirectory: String { "TestCases/CXX" }

func testTranspiler() throws {
// Prepare an AST with the core module loaded.
var baseAST = AST()
baseAST.importCoreModule()

try runValTests(
try checkAnnotatedValFiles(
{ (name, source) -> CXXAnnotationHandler in
// Create a module for the input.
var ast = baseAST
Expand Down
6 changes: 3 additions & 3 deletions Tests/ValTests/EmitterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import IR
import Utils
import XCTest

final class EmitterTests: XCTestCase, ValTestRunner {
final class EmitterTests: XCTestCase, AnnotatedValFileTest {

static var testCaseDirectoryPath: String { "TestCases/Lowering" }
static var valSourceDirectory: String { "TestCases/Lowering" }

func testEmitter() throws {
// Prepare an AST with the core module loaded.
var baseAST = AST()
baseAST.importCoreModule()

try runValTests(
try checkAnnotatedValFiles(
{ (name, source) -> DefaultTestAnnotationHandler in
// Create a module for the input.
var ast = baseAST
Expand Down
6 changes: 3 additions & 3 deletions Tests/ValTests/ParserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import XCTest

@testable import FrontEnd

final class ParserTests: XCTestCase, ValTestRunner {
final class ParserTests: XCTestCase, AnnotatedValFileTest {

static var testCaseDirectoryPath: String { "TestCases/Parsing" }
static var valSourceDirectory: String { "TestCases/Parsing" }

func testParser() throws {
try runValTests(
try checkAnnotatedValFiles(
{ (name, source) -> DefaultTestAnnotationHandler in
// Create a module for the input.
var ast = AST()
Expand Down
6 changes: 3 additions & 3 deletions Tests/ValTests/TypeCheckerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import Core
import FrontEnd
import XCTest

final class TypeCheckerTests: XCTestCase, ValTestRunner {
final class TypeCheckerTests: XCTestCase, AnnotatedValFileTest {

static var testCaseDirectoryPath: String { "TestCases/TypeChecking" }
static var valSourceDirectory: String { "TestCases/TypeChecking" }

func testTypeChecker() throws {
// Prepare an AST with the core module loaded.
var baseAST = AST()
baseAST.importCoreModule()

try runValTests(
try checkAnnotatedValFiles(
{ (name, source) -> DefaultTestAnnotationHandler in
// Create a module for the input.
var ast = baseAST
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@ import Core
import Utils
import XCTest

/// A XCTestCase that runs val test cases.
protocol ValTestRunner: XCTestCase {
/// A XCTestCase that preprocesses the ".val" files in a directory, and then checks the result of
/// that preprocessing against annotations embedded in the file's comments.
protocol AnnotatedValFileTest: XCTestCase {

/// The directory containing the Val test cases of this type.
static var testCaseDirectoryPath: String { get }
/// The directory containing the Val sources to test.
static var valSourceDirectory: String { get }

}

extension ValTestRunner {
extension AnnotatedValFileTest {

/// Runs the test cases found in `Self.testCaseDirectoryPath` with `runSteps` and handle the
/// Runs the test cases found in `Self.valSourceDirectory` with `runSteps` and handle the
/// result of each case with an instance of `handler`.
func runValTests<Handler: TestAnnotationHandler>(
func checkAnnotatedValFiles<Handler: TestAnnotationHandler>(
_ runSteps: (_ xcTestName: String, _ source: SourceFile) throws -> Handler
) throws {
let testCaseDirectory = try XCTUnwrap(
Bundle.module.url(forResource: Self.testCaseDirectoryPath, withExtension: nil),
Bundle.module.url(forResource: Self.valSourceDirectory, withExtension: nil),
"No test cases")

func _run(xcTestName: String, url: URL, activity: XCTActivity) throws -> [XCTIssue] {
Expand Down

0 comments on commit 6224086

Please sign in to comment.