aboutsummaryrefslogtreecommitdiffstats
path: root/context_test.go
diff options
context:
space:
mode:
authorJeff Gaston <jeffrygaston@google.com>2017-12-05 15:11:55 -0800
committerJeff Gaston <jeffrygaston@google.com>2017-12-05 16:09:02 -0800
commita7e408af0af05f9bb02e532e4a47220b14665fbb (patch)
tree016dccbdc2ead75066a2e80df741341cadb48d4c /context_test.go
parent8fd9578a6a202c3f0a79ce7f819cebfe8e288f7e (diff)
downloadandroid_build_blueprint-a7e408af0af05f9bb02e532e4a47220b14665fbb.tar.gz
android_build_blueprint-a7e408af0af05f9bb02e532e4a47220b14665fbb.tar.bz2
android_build_blueprint-a7e408af0af05f9bb02e532e4a47220b14665fbb.zip
prevent file=nil panic if syntax error in Blueprints
Bug: 65683273 Test: build/soong/scripts/diff_build_graphs.sh \ 'build/blueprint:work^^^' 'build/blueprint:work' Test: put a syntax error in a file and see that the reported error reports the location of the violation Change-Id: Iaeedb91ea8e816cb8e9ee954f21cd6c6bc4afa48
Diffstat (limited to 'context_test.go')
-rw-r--r--context_test.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/context_test.go b/context_test.go
index c0ce803..635f73e 100644
--- a/context_test.go
+++ b/context_test.go
@@ -16,6 +16,8 @@ package blueprint
import (
"bytes"
+ "errors"
+ "fmt"
"reflect"
"strings"
"sync"
@@ -353,3 +355,40 @@ func doTestWalkFileOrder(t *testing.T, sleepDuration time.Duration) {
t.Errorf("Incorrect visit order; expected %v, got %v", correctVisitOrder, visitOrder)
}
}
+
+// test that WalkBlueprintsFiles reports syntax errors
+func TestWalkingWithSyntaxError(t *testing.T) {
+ // setup mock context
+ ctx := newContext()
+ mockFiles := map[string][]byte{
+ "Blueprints": []byte(`
+ sample_module {
+ name: "a" "b",
+ }
+ `),
+ "dir1/Blueprints": []byte(`
+ sample_module {
+ name: "b",
+ `),
+ "dir1/dir2/Blueprints": []byte(`
+ sample_module {
+ name: "c",
+ }
+ `),
+ }
+ ctx.MockFileSystem(mockFiles)
+
+ keys := []string{"Blueprints", "dir1/Blueprints", "dir1/dir2/Blueprints"}
+
+ // visit the blueprints files
+ _, errs := ctx.WalkBlueprintsFiles(".", keys, func(file *parser.File) {})
+
+ expectedErrs := []error{
+ errors.New(`Blueprints:3:18: expected "}", found String`),
+ errors.New(`dir1/Blueprints:4:3: expected "}", found EOF`),
+ }
+ if fmt.Sprintf("%s", expectedErrs) != fmt.Sprintf("%s", errs) {
+ t.Errorf("Incorrect errors; expected:\n%s\ngot:\n%s", expectedErrs, errs)
+ }
+
+}