androidbp: make error handling stricter

Instead of putting errors into the translated Android.mk file where
they are unlikely to be seen and may cause strange build behavior,
make all errors fatal.  Also buffer to a byte buffer and then write
to the output file once we are sure there are no errors.

Change-Id: I247f405dd0a7c1d14c2681f86c7ac626e035ac2c
diff --git a/androidbp/cmd/androidbp_test.go b/androidbp/cmd/androidbp_test.go
index e16fa08..f5590e2 100644
--- a/androidbp/cmd/androidbp_test.go
+++ b/androidbp/cmd/androidbp_test.go
@@ -1,7 +1,6 @@
 package main
 
 import (
-	"bufio"
 	"bytes"
 	"strings"
 	"testing"
@@ -51,7 +50,10 @@
 			t.Errorf("Failed to read blueprint: %q", errs)
 		}
 
-		str := valueToString(blueprint.Defs[0].(*bpparser.Assignment).Value)
+		str, err := valueToString(blueprint.Defs[0].(*bpparser.Assignment).Value)
+		if err != nil {
+			t.Error(err.Error())
+		}
 		expect(t, testCase.blueprint, testCase.expected, str)
 	}
 }
@@ -129,12 +131,14 @@
 			blueprint: blueprint,
 			path:      "",
 			mapScope:  make(map[string][]*bpparser.Property),
-			Writer:    bufio.NewWriter(buf),
+			Writer:    buf,
 		}
 
 		module := blueprint.Defs[0].(*bpparser.Module)
-		writer.handleModule(module)
-		writer.Flush()
+		err := writer.handleModule(module)
+		if err != nil {
+			t.Errorf("Unexpected error %s", err.Error())
+		}
 
 		expect(t, testCase.blueprint, testCase.androidmk, buf.String())
 	}