Skip to content

Commit a65e1b1

Browse files
committed
Add tests for C libraries, Rename CLang to Clang
1 parent 7e285fa commit a65e1b1

File tree

26 files changed

+129
-6
lines changed

26 files changed

+129
-6
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
int foo() {
2+
int a = 5;
3+
int b = a;
4+
a = b;
5+
return a;
6+
}

Fixtures/ClangModules/CLibraryFlat/Package.swift

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
int foo();
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module CLibraryFlat {
2+
header "abc.h"
3+
link "CLibraryFlat"
4+
export *
5+
}

Fixtures/ClangModules/CLibrarySources/Package.swift

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
int foo() {
2+
int a = 5;
3+
int b = a;
4+
a = b;
5+
return a;
6+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
int foo();
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module CLibrarySources {
2+
header "abc.h"
3+
link "CLibrarySources"
4+
export *
5+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import PackageDescription
2+
3+
let package = Package(
4+
name: "SwiftCMixed",
5+
targets: [Target(name: "SeaExec", dependencies: ["SeaLib"])]
6+
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import SeaLib
2+
3+
let a = foo(5)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
int foo(int a) {
2+
return a;
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
int foo(int a);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module SeaLib {
2+
header "Foo.h"
3+
link "SeaLib"
4+
export *
5+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import PackageDescription
2+
3+
let package = Package(
4+
name: "Bar",
5+
dependencies: [
6+
.Package(url: "../Foo", majorVersion: 1)])
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import Foo
2+
3+
foo()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
void foo() {
2+
3+
}

Fixtures/DependencyResolution/External/SimpleCDep/Foo/Package.swift

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
void foo();
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module Foo {
2+
header "Foo.h"
3+
link "Foo"
4+
export *
5+
}

Sources/Build/describe().swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public func describe(prefix: String, _ conf: Configuration, _ modules: [Module],
107107
//FIXME: Probably needs more compiler options for debug and release modes
108108
//FIXME: Incremental builds
109109
//FIXME: Add support for executables
110-
for case let module as CLangModule in modules {
110+
for case let module as ClangModule in modules {
111111
let inputs = module.dependencies.map{ $0.targetName } + module.sources.paths
112112
let productPath = Path.join(prefix, "\(module.c99name).o")
113113
let wd = Path.join(prefix, "\(module.c99name).build")

Sources/Build/misc.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ extension Module {
3232
if let module = module as? CModule {
3333
let moduleMapPath = Path.join(module.path, "module.modulemap")
3434
return ["-Xcc", "-fmodule-map-file=\(moduleMapPath)"]
35-
} else if let cmodule = module as? CLangModule {
35+
} else if let cmodule = module as? ClangModule {
3636
return ["-Xcc", "-fmodule-map-file=\(cmodule.moduleMapPath)"]
3737
} else {
3838
return []

Sources/PackageType/Module.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public class CModule: Module {
7070
}
7171
}
7272

73-
public class CLangModule: Module {
73+
public class ClangModule: Module {
7474
public let sources: Sources
7575
public let moduleMapPath: String
7676

Sources/Transmute/Package+modules.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ extension Package {
4242
if sourcified.isSwiftModule {
4343
modules = [SwiftModule(name: self.name, sources: sourcified.sources)]
4444
} else {
45-
modules = [CLangModule(name: self.name, sources: sourcified.sources)]
45+
modules = [ClangModule(name: self.name, sources: sourcified.sources)]
4646
}
4747

4848
} catch Module.Error.NoSources {
@@ -59,7 +59,7 @@ extension Package {
5959
if sourcified.isSwiftModule {
6060
return SwiftModule(name: name, sources: sourcified.sources)
6161
}
62-
return CLangModule(name: name, sources: sourcified.sources)
62+
return ClangModule(name: name, sources: sourcified.sources)
6363
}
6464
}
6565

Sources/Transmute/fillModuleGraph().swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func fillModuleGraph(packages: [Package], modulesForPackage: (Package) -> [Modul
2020
return false
2121
case let module as SwiftModule where module.type == .Library:
2222
return true
23-
case is CLangModule:
23+
case is ClangModule:
2424
return true
2525
case is CModule:
2626
return true
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright 2015 - 2016 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See http://swift.org/LICENSE.txt for license information
8+
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
*/
10+
11+
import struct Utility.Path
12+
import func POSIX.symlink
13+
import func Utility.walk
14+
import func POSIX.rename
15+
import func POSIX.mkdir
16+
import func POSIX.popen
17+
import XCTest
18+
19+
class TestClangModulesTestCase: XCTestCase {
20+
21+
func testSingleModuleFlatCLibrary() {
22+
fixture(name: "ClangModules/CLibraryFlat") { prefix in
23+
XCTAssertBuilds(prefix)
24+
XCTAssertFileExists(prefix, ".build", "debug", "libCLibraryFlat.so")
25+
}
26+
}
27+
28+
func testSingleModuleCLibraryInSources() {
29+
fixture(name: "ClangModules/CLibrarySources") { prefix in
30+
XCTAssertBuilds(prefix)
31+
XCTAssertFileExists(prefix, ".build", "debug", "libCLibrarySources.so")
32+
}
33+
}
34+
35+
func testMixedSwiftAndC() {
36+
fixture(name: "ClangModules/SwiftCMixed") { prefix in
37+
XCTAssertBuilds(prefix)
38+
XCTAssertFileExists(prefix, ".build", "debug", "libSeaLib.so")
39+
}
40+
}
41+
42+
func testExternalSimpleCDep() {
43+
fixture(name: "DependencyResolution/External/SimpleCDep") { prefix in
44+
XCTAssertBuilds(prefix, "Bar")
45+
XCTAssertFileExists(prefix, "Bar/.build/debug/Bar")
46+
XCTAssertFileExists(prefix, "Bar/.build/debug/libFoo.so")
47+
XCTAssertDirectoryExists(prefix, "Bar/Packages/Foo-1.2.3")
48+
}
49+
}
50+
}
51+
52+
53+
extension TestClangModulesTestCase {
54+
static var allTests : [(String, TestClangModulesTestCase -> () throws -> Void)] {
55+
return [
56+
("testSingleModuleFlatCLibrary", testSingleModuleFlatCLibrary),
57+
("testSingleModuleCLibraryInSources", testSingleModuleCLibraryInSources),
58+
("testMixedSwiftAndC", testMixedSwiftAndC),
59+
("testExternalSimpleCDep", testExternalSimpleCDep),
60+
]
61+
}
62+
}

Tests/LinuxMain.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import XCTest
1515
@testable import Buildtest
1616

1717
XCTMain([
18+
testCase(TestClangModulesTestCase.allTests),
1819
testCase(DependencyResolutionTestCase.allTests),
1920
testCase(FileTests.allTests),
2021
testCase(GetTests.allTests),

0 commit comments

Comments
 (0)