androidbp: Test valueToString
Change-Id: I358cf4bb020fc4db14792e2cdffc18bc2f89f4d4
This commit is contained in:
@@ -194,6 +194,9 @@ bootstrap_go_binary {
|
|||||||
"androidbp/cmd/androidbp.go",
|
"androidbp/cmd/androidbp.go",
|
||||||
"androidbp/cmd/soong.go",
|
"androidbp/cmd/soong.go",
|
||||||
],
|
],
|
||||||
|
testSrcs: [
|
||||||
|
"androidbp/cmd/androidbp_test.go",
|
||||||
|
],
|
||||||
deps: [
|
deps: [
|
||||||
"blueprint-parser",
|
"blueprint-parser",
|
||||||
],
|
],
|
||||||
|
59
androidbp/cmd/androidbp_test.go
Normal file
59
androidbp/cmd/androidbp_test.go
Normal file
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -65,11 +65,46 @@ rule g.bootstrap.test
|
|||||||
# Factory: github.com/google/blueprint/bootstrap.func·003
|
# Factory: github.com/google/blueprint/bootstrap.func·003
|
||||||
# Defined: build/soong/Android.bp:191:1
|
# 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 $
|
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/androidbp.go $
|
||||||
${g.bootstrap.srcDir}/build/soong/androidbp/cmd/soong.go | $
|
${g.bootstrap.srcDir}/build/soong/androidbp/cmd/soong.go | $
|
||||||
${g.bootstrap.gcCmd} $
|
${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
|
incFlags = -I .bootstrap/blueprint-parser/pkg
|
||||||
pkgPath = androidbp
|
pkgPath = androidbp
|
||||||
default .bootstrap/androidbp/obj/androidbp.a
|
default .bootstrap/androidbp/obj/androidbp.a
|
||||||
|
Reference in New Issue
Block a user