aboutsummaryrefslogtreecommitdiffstats
path: root/cc/cc_test.go
diff options
context:
space:
mode:
authorJiyong Park <jiyong@google.com>2017-09-26 10:50:54 +0900
committerJiyong Park <jiyong@google.com>2017-10-19 22:39:32 +0900
commitd08b697828315502b34deed28307f6e4663342ec (patch)
treed93799c41e4483c8bb670c93394e3b9153927d6d /cc/cc_test.go
parente87ae20e2593015c7d30359311a64ef96b941680 (diff)
downloadbuild_soong-d08b697828315502b34deed28307f6e4663342ec.tar.gz
build_soong-d08b697828315502b34deed28307f6e4663342ec.tar.bz2
build_soong-d08b697828315502b34deed28307f6e4663342ec.zip
Allow macro definition with space
cflags: ["-DMACRO=\" definition \""] should not be rejected. Bug: 66914194 Test: TestCompilerFlags in cc_test.go Change-Id: I7f96505a83898616415ef1fb7e13596b56a063f3
Diffstat (limited to 'cc/cc_test.go')
-rw-r--r--cc/cc_test.go84
1 files changed, 84 insertions, 0 deletions
diff --git a/cc/cc_test.go b/cc/cc_test.go
index b9cdba55..dc04a4e1 100644
--- a/cc/cc_test.go
+++ b/cc/cc_test.go
@@ -603,5 +603,89 @@ func TestLibDeps(t *testing.T) {
expected,
)
}
+}
+var compilerFlagsTestCases = []struct {
+ in string
+ out bool
+}{
+ {
+ in: "a",
+ out: false,
+ },
+ {
+ in: "-a",
+ out: true,
+ },
+ {
+ in: "-Ipath/to/something",
+ out: false,
+ },
+ {
+ in: "-isystempath/to/something",
+ out: false,
+ },
+ {
+ in: "--coverage",
+ out: false,
+ },
+ {
+ in: "-include a/b",
+ out: true,
+ },
+ {
+ in: "-include a/b c/d",
+ out: false,
+ },
+ {
+ in: "-DMACRO",
+ out: true,
+ },
+ {
+ in: "-DMAC RO",
+ out: false,
+ },
+ {
+ in: "-a -b",
+ out: false,
+ },
+ {
+ in: "-DMACRO=definition",
+ out: true,
+ },
+ {
+ in: "-DMACRO=defi nition",
+ out: true, // TODO(jiyong): this should be false
+ },
+ {
+ in: "-DMACRO(x)=x + 1",
+ out: true,
+ },
+ {
+ in: "-DMACRO=\"defi nition\"",
+ out: true,
+ },
+}
+
+type mockContext struct {
+ BaseModuleContext
+ result bool
+}
+
+func (ctx *mockContext) PropertyErrorf(property, format string, args ...interface{}) {
+ // CheckBadCompilerFlags calls this function when the flag should be rejected
+ ctx.result = false
+}
+
+func TestCompilerFlags(t *testing.T) {
+ for _, testCase := range compilerFlagsTestCases {
+ ctx := &mockContext{result: true}
+ CheckBadCompilerFlags(ctx, "", []string{testCase.in})
+ if ctx.result != testCase.out {
+ t.Errorf("incorrect output:")
+ t.Errorf(" input: %#v", testCase.in)
+ t.Errorf(" expected: %#v", testCase.out)
+ t.Errorf(" got: %#v", ctx.result)
+ }
+ }
}