aboutsummaryrefslogtreecommitdiffstats
path: root/unpack_test.go
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2015-06-22 13:38:45 -0700
committerColin Cross <ccross@android.com>2015-06-26 10:46:17 -0700
commit4adc8194905e72bcc240ef5bf5bbb2175c329c16 (patch)
treed6288cdd4f70388f21b9eb5ce921a0fd2202ee79 /unpack_test.go
parent944a7a5ed4a1b554dde0bb8be493a65d4a8dc1ba (diff)
downloadandroid_build_blueprint-4adc8194905e72bcc240ef5bf5bbb2175c329c16.tar.gz
android_build_blueprint-4adc8194905e72bcc240ef5bf5bbb2175c329c16.tar.bz2
android_build_blueprint-4adc8194905e72bcc240ef5bf5bbb2175c329c16.zip
Support filtering nested structures by tag
Allow tagging a nested property structure with `blueprint:"filter(key:\"value\")"`, which will only allow property assignments to properites in the nested structure that are tagged with `key:"value"`. Moving the filter into Blueprint instead of the project build logic allows more reliable and consistent error messages. Change-Id: I06bc673dde647776fc5552673bdc0cdcd7216462
Diffstat (limited to 'unpack_test.go')
-rw-r--r--unpack_test.go78
1 files changed, 75 insertions, 3 deletions
diff --git a/unpack_test.go b/unpack_test.go
index bd4dd8f..393631c 100644
--- a/unpack_test.go
+++ b/unpack_test.go
@@ -16,15 +16,19 @@ package blueprint
import (
"bytes"
- "github.com/google/blueprint/parser"
- "github.com/google/blueprint/proptools"
+ "fmt"
"reflect"
"testing"
+ "text/scanner"
+
+ "github.com/google/blueprint/parser"
+ "github.com/google/blueprint/proptools"
)
var validUnpackTestCases = []struct {
input string
output interface{}
+ errs []error
}{
{`
m {
@@ -36,6 +40,7 @@ var validUnpackTestCases = []struct {
}{
Name: "abc",
},
+ nil,
},
{`
@@ -48,6 +53,7 @@ var validUnpackTestCases = []struct {
}{
IsGood: true,
},
+ nil,
},
{`
@@ -61,6 +67,7 @@ var validUnpackTestCases = []struct {
}{
Stuff: []string{"asdf", "jkl;", "qwert", "uiop", "bnm,"},
},
+ nil,
},
{`
@@ -79,6 +86,7 @@ var validUnpackTestCases = []struct {
Name: "abc",
},
},
+ nil,
},
{`
@@ -95,6 +103,7 @@ var validUnpackTestCases = []struct {
Name: "def",
},
},
+ nil,
},
{`
@@ -119,6 +128,64 @@ var validUnpackTestCases = []struct {
Bar: false,
Baz: []string{"def", "ghi"},
},
+ nil,
+ },
+
+ {`
+ m {
+ nested: {
+ foo: "abc",
+ },
+ bar: false,
+ baz: ["def", "ghi"],
+ }
+ `,
+ struct {
+ Nested struct {
+ Foo string `allowNested:"true"`
+ } `blueprint:"filter(allowNested:\"true\")"`
+ Bar bool
+ Baz []string
+ }{
+ Nested: struct {
+ Foo string `allowNested:"true"`
+ }{
+ Foo: "abc",
+ },
+ Bar: false,
+ Baz: []string{"def", "ghi"},
+ },
+ nil,
+ },
+
+ {`
+ m {
+ nested: {
+ foo: "abc",
+ },
+ bar: false,
+ baz: ["def", "ghi"],
+ }
+ `,
+ struct {
+ Nested struct {
+ Foo string
+ } `blueprint:"filter(allowNested:\"true\")"`
+ Bar bool
+ Baz []string
+ }{
+ Nested: struct{ Foo string }{
+ Foo: "",
+ },
+ Bar: false,
+ Baz: []string{"def", "ghi"},
+ },
+ []error{
+ &Error{
+ Err: fmt.Errorf("filtered field nested.foo cannot be set in a Blueprint file"),
+ Pos: scanner.Position{"", 27, 4, 8},
+ },
+ },
},
}
@@ -139,13 +206,18 @@ func TestUnpackProperties(t *testing.T) {
properties := proptools.CloneProperties(reflect.ValueOf(testCase.output))
proptools.ZeroProperties(properties.Elem())
_, errs = unpackProperties(module.Properties, properties.Interface())
- if len(errs) != 0 {
+ if len(errs) != 0 && len(testCase.errs) == 0 {
t.Errorf("test case: %s", testCase.input)
t.Errorf("unexpected unpack errors:")
for _, err := range errs {
t.Errorf(" %s", err)
}
t.FailNow()
+ } else if !reflect.DeepEqual(errs, testCase.errs) {
+ t.Errorf("test case: %s", testCase.input)
+ t.Errorf("incorrect errors:")
+ t.Errorf(" expected: %+v", testCase.errs)
+ t.Errorf(" got: %+v", errs)
}
output := properties.Elem().Interface()