aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Willemsen <dwillemsen@google.com>2015-06-23 23:34:49 -0700
committerDan Willemsen <dwillemsen@google.com>2015-06-29 21:46:22 +0000
commitf33877b0e90fee602b7e80d70f373e29c36b568f (patch)
treed1e8868aee0bb1778926ed23e732380f953b787b
parent00a36d3f217d507a717bfdb8e1ff2ed402b1eca4 (diff)
downloadbuild_soong-f33877b0e90fee602b7e80d70f373e29c36b568f.tar.gz
build_soong-f33877b0e90fee602b7e80d70f373e29c36b568f.tar.bz2
build_soong-f33877b0e90fee602b7e80d70f373e29c36b568f.zip
androidbp: Test valueToString
Change-Id: I358cf4bb020fc4db14792e2cdffc18bc2f89f4d4
-rw-r--r--Android.bp3
-rw-r--r--androidbp/cmd/androidbp_test.go59
-rw-r--r--build.ninja.in37
3 files changed, 98 insertions, 1 deletions
diff --git a/Android.bp b/Android.bp
index da0e55bb..2a21d3db 100644
--- a/Android.bp
+++ b/Android.bp
@@ -194,6 +194,9 @@ bootstrap_go_binary {
"androidbp/cmd/androidbp.go",
"androidbp/cmd/soong.go",
],
+ testSrcs: [
+ "androidbp/cmd/androidbp_test.go",
+ ],
deps: [
"blueprint-parser",
],
diff --git a/androidbp/cmd/androidbp_test.go b/androidbp/cmd/androidbp_test.go
new file mode 100644
index 00000000..178ea570
--- /dev/null
+++ b/androidbp/cmd/androidbp_test.go
@@ -0,0 +1,59 @@
+package main
+
+import (
+ "strings"
+ "testing"
+
+ bpparser "github.com/google/blueprint/parser"
+)
+
+var valueTestCases = []struct {
+ blueprint string
+ expected string
+}{
+ {
+ blueprint: `test = false`,
+ expected: `false`,
+ },
+ {
+ blueprint: `test = Variable`,
+ expected: `$(Variable)`,
+ },
+ {
+ blueprint: `test = "string"`,
+ expected: `string`,
+ },
+ {
+ blueprint: `test = ["a", "b"]`,
+ expected: `\
+ a \
+ b`,
+ },
+ {
+ blueprint: `test = Var + "b"`,
+ expected: `$(Var)b`,
+ },
+ {
+ blueprint: `test = ["a"] + ["b"]`,
+ expected: `\
+ a\
+ b`,
+ },
+}
+
+func TestValueToString(t *testing.T) {
+ for _, testCase := range valueTestCases {
+ blueprint, errs := bpparser.Parse("", strings.NewReader(testCase.blueprint), nil)
+ if len(errs) > 0 {
+ t.Errorf("Failed to read blueprint: %q", errs)
+ }
+
+ str := valueToString(blueprint.Defs[0].(*bpparser.Assignment).Value)
+ if str != testCase.expected {
+ t.Errorf("test case: %s", testCase.blueprint)
+ t.Errorf("unexpected difference:")
+ t.Errorf(" expected: %s", testCase.expected)
+ t.Errorf(" got: %s", str)
+ }
+ }
+}
diff --git a/build.ninja.in b/build.ninja.in
index 6a6ba0f4..8a507f2b 100644
--- a/build.ninja.in
+++ b/build.ninja.in
@@ -65,11 +65,46 @@ rule g.bootstrap.test
# Factory: github.com/google/blueprint/bootstrap.funcĀ·003
# Defined: build/soong/Android.bp:191:1
+build .bootstrap/androidbp/test/androidbp.a: g.bootstrap.gc $
+ ${g.bootstrap.srcDir}/build/soong/androidbp/cmd/androidbp.go $
+ ${g.bootstrap.srcDir}/build/soong/androidbp/cmd/soong.go $
+ ${g.bootstrap.srcDir}/build/soong/androidbp/cmd/androidbp_test.go | $
+ ${g.bootstrap.gcCmd} $
+ .bootstrap/blueprint-parser/pkg/github.com/google/blueprint/parser.a
+ incFlags = -I .bootstrap/blueprint-parser/pkg
+ pkgPath = androidbp
+default .bootstrap/androidbp/test/androidbp.a
+
+build .bootstrap/androidbp/test/test.go: g.bootstrap.gotestmain $
+ ${g.bootstrap.srcDir}/build/soong/androidbp/cmd/androidbp_test.go | $
+ ${g.bootstrap.goTestMainCmd}
+ pkg = androidbp
+default .bootstrap/androidbp/test/test.go
+
+build .bootstrap/androidbp/test/test.a: g.bootstrap.gc $
+ .bootstrap/androidbp/test/test.go | $
+ .bootstrap/androidbp/test/androidbp.a
+ incFlags = -I .bootstrap/androidbp/test
+ pkgPath = main
+default .bootstrap/androidbp/test/test.a
+
+build .bootstrap/androidbp/test/test: g.bootstrap.link $
+ .bootstrap/androidbp/test/test.a | ${g.bootstrap.linkCmd}
+ libDirFlags = -L .bootstrap/androidbp/test -L .bootstrap/blueprint-parser/pkg
+default .bootstrap/androidbp/test/test
+
+build .bootstrap/androidbp/test/test.passed: g.bootstrap.test $
+ .bootstrap/androidbp/test/test
+ pkg = androidbp
+ pkgSrcDir = ${g.bootstrap.srcDir}/build/soong/androidbp/cmd
+default .bootstrap/androidbp/test/test.passed
+
build .bootstrap/androidbp/obj/androidbp.a: g.bootstrap.gc $
${g.bootstrap.srcDir}/build/soong/androidbp/cmd/androidbp.go $
${g.bootstrap.srcDir}/build/soong/androidbp/cmd/soong.go | $
${g.bootstrap.gcCmd} $
- .bootstrap/blueprint-parser/pkg/github.com/google/blueprint/parser.a
+ .bootstrap/blueprint-parser/pkg/github.com/google/blueprint/parser.a $
+ || .bootstrap/androidbp/test/test.passed
incFlags = -I .bootstrap/blueprint-parser/pkg
pkgPath = androidbp
default .bootstrap/androidbp/obj/androidbp.a