androidbp: Test valueToString

Change-Id: I358cf4bb020fc4db14792e2cdffc18bc2f89f4d4
diff --git a/Android.bp b/Android.bp
index da0e55b..2a21d3d 100644
--- a/Android.bp
+++ b/Android.bp
@@ -194,6 +194,9 @@
         "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 0000000..178ea57
--- /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 6a6ba0f..8a507f2 100644
--- a/build.ninja.in
+++ b/build.ninja.in
@@ -65,11 +65,46 @@
 # 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