Skip to content

Validate that there are no loose source files in the Tests directory #626

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 1 commit into from
Aug 31, 2016
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
13 changes: 12 additions & 1 deletion Sources/PackageLoading/PackageBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -562,8 +562,19 @@ public struct PackageBuilder {
return []
}

// Get the contents of the Tests directory.
let testsDirContents = try directoryContents(testsPath)

// Check that the Tests directory doesn't contain any loose source files.
// FIXME: Right now we just check for source files. We need to decide whether we should check for other kinds of files too.
// FIXME: We should factor out the checking for the `LinuxMain.swift` source file. So ugly...
let looseSourceFiles = testsDirContents.filter(isValidSource).filter({ $0.basename.lowercased() != "linuxmain.swift" })
guard looseSourceFiles.isEmpty else {
throw ModuleError.invalidLayout(.unexpectedSourceFiles(looseSourceFiles.map{ $0.asString }))
}

// Create the test modules
return try directoryContents(testsPath).filter(shouldConsiderDirectory).flatMap { dir in
return try testsDirContents.filter(shouldConsiderDirectory).flatMap { dir in
return [try createModule(dir, name: dir.basename, isTest: true)]
}
}
Expand Down
11 changes: 11 additions & 0 deletions Tests/PackageLoadingTests/ConventionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,16 @@ class ConventionTests: XCTestCase {
}
}

func testLooseSourceFileInTestsDir() throws {
// Loose source file in Tests/
let fs = InMemoryFileSystem(emptyFiles:
"/Sources/main.swift",
"/Tests/source.swift")
PackageBuilderTester("LooseSourceFileInTestsDir", in: fs) { result in
result.checkDiagnostic("the package has an unsupported layout, unexpected source file(s) found: /Tests/source.swift fix: move the file(s) inside a module")
}
}

func testManifestTargetDeclErrors() throws {
// Reference a target which doesn't exist.
var fs = InMemoryFileSystem(emptyFiles:
Expand Down Expand Up @@ -857,6 +867,7 @@ class ConventionTests: XCTestCase {
("testCustomTargetDependencies", testCustomTargetDependencies),
("testTestTargetDependencies", testTestTargetDependencies),
("testInvalidTestTargets", testInvalidTestTargets),
("testLooseSourceFileInTestsDir", testLooseSourceFileInTestsDir),
("testManifestTargetDeclErrors", testManifestTargetDeclErrors),
("testProducts", testProducts),
("testBadProducts", testBadProducts),
Expand Down