aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--context.go6
-rw-r--r--context_test.go39
2 files changed, 43 insertions, 2 deletions
diff --git a/context.go b/context.go
index 5b17297..2051365 100644
--- a/context.go
+++ b/context.go
@@ -768,8 +768,10 @@ func (c *Context) WalkBlueprintsFiles(rootDir string, filePaths []string,
<-blueprint.parent.doneVisiting
}
- // process this file
- visitor(file)
+ if len(errs) == 0 {
+ // process this file
+ visitor(file)
+ }
if blueprint.doneVisiting != nil {
close(blueprint.doneVisiting)
}
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)
+ }
+
+}