Skip to content

Commit 4bcdcc9

Browse files
committed
[pkg-config] Add failure case for pkg parser testing
1 parent 673d666 commit 4bcdcc9

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

Tests/Build/PkgConfigParserTests.swift

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ final class PkgConfigParserTests: XCTestCase {
1616

1717
func testGTK3PCFile() {
1818
loadPCFile("gtk+-3.0.pc") { parser in
19+
guard let parser = parser else { XCTFail("Unexpected parsing error"); return}
1920
XCTAssertEqual(parser.variables, ["libdir": "/usr/local/Cellar/gtk+3/3.18.9/lib", "gtk_host": "x86_64-apple-darwin15.3.0", "includedir": "/usr/local/Cellar/gtk+3/3.18.9/include", "prefix": "/usr/local/Cellar/gtk+3/3.18.9", "gtk_binary_version": "3.0.0", "exec_prefix": "/usr/local/Cellar/gtk+3/3.18.9", "targets": "quartz"])
2021
XCTAssertEqual(parser.dependencies, ["gdk-3.0", "atk", "cairo", "cairo-gobject", "gdk-pixbuf-2.0", "gio-2.0"])
2122
XCTAssertEqual(parser.cFlags, "-I/usr/local/Cellar/gtk+3/3.18.9/include/gtk-3.0 ")
@@ -25,6 +26,7 @@ final class PkgConfigParserTests: XCTestCase {
2526

2627
func testEmptyCFlags() {
2728
loadPCFile("empty_cflags.pc") { parser in
29+
guard let parser = parser else { XCTFail("Unexpected parsing error"); return}
2830
XCTAssertEqual(parser.variables, ["prefix": "/usr/local/bin", "exec_prefix": "/usr/local/bin"])
2931
XCTAssertEqual(parser.dependencies, ["gdk-3.0", "atk"])
3032
XCTAssertEqual(parser.cFlags, "")
@@ -34,22 +36,31 @@ final class PkgConfigParserTests: XCTestCase {
3436

3537
func testVariableinDependency() {
3638
loadPCFile("deps_variable.pc") { parser in
39+
guard let parser = parser else { XCTFail("Unexpected parsing error"); return}
3740
XCTAssertEqual(parser.variables, ["prefix": "/usr/local/bin", "exec_prefix": "/usr/local/bin", "my_dep": "atk"])
3841
XCTAssertEqual(parser.dependencies, ["gdk-3.0", "atk"])
3942
XCTAssertEqual(parser.cFlags, "-I")
4043
XCTAssertEqual(parser.libs, "-L/usr/local/bin -lgtk-3 ")
4144
}
4245
}
4346

44-
private func loadPCFile(_ inputName: String, line: UInt = #line, body: (PkgConfigParser) -> Void) {
47+
func testUnresolvablePCFile() {
48+
loadPCFile("failure_case.pc") { parser in
49+
if parser != nil {
50+
XCTFail("parsing should have failed: \(parser)")
51+
}
52+
}
53+
}
54+
55+
private func loadPCFile(_ inputName: String, body: (PkgConfigParser?) -> Void) {
56+
let input = Path.join(#file, "../pkgconfigInputs", inputName).normpath
57+
var parser: PkgConfigParser? = PkgConfigParser(pcFile: input)
4558
do {
46-
let input = Path.join(#file, "../pkgconfigInputs", inputName).normpath
47-
var parser = PkgConfigParser(pcFile: input)
48-
try parser.parse()
49-
body(parser)
59+
try parser?.parse()
5060
} catch {
51-
XCTFail("Unexpected error: \(error)", file: #file, line: line)
61+
parser = nil
5262
}
63+
body(parser)
5364
}
5465
}
5566

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
prefix=/usr/local/bin
2+
exec_prefix=${prefix}
3+
4+
#some comment
5+
6+
Requires: gdk-3.0 >= 1.0.0
7+
Libs: -L${prefix} -lgtk-3 ${my_dep}
8+
Cflags: -I

0 commit comments

Comments
 (0)