From f41ce7fed464e8ddbfe4c72786de327c93dfba99 Mon Sep 17 00:00:00 2001 From: David Sisson Date: Sat, 29 Apr 2017 17:27:08 -0700 Subject: [PATCH 1/4] Fix tests for PR #1844. --- doc/go-target.md | 2 +- .../test/org/antlr/v4/test/runtime/go/BaseGoTest.java | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/doc/go-target.md b/doc/go-target.md index 6de6db916..4f7e64e05 100644 --- a/doc/go-target.md +++ b/doc/go-target.md @@ -88,7 +88,7 @@ func (this *TreeShapeListener) EnterEveryRule(ctx antlr.ParserRuleContext) { } func main() { - input := antlr.NewFileStream(os.Args[1]) + input, _ := antlr.NewFileStream(os.Args[1]) lexer := parser.NewJSONLexer(input) stream := antlr.NewCommonTokenStream(lexer,0) p := parser.NewJSONParser(stream) diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/go/BaseGoTest.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/go/BaseGoTest.java index 762635bce..4f5179eff 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/go/BaseGoTest.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/go/BaseGoTest.java @@ -696,7 +696,11 @@ public class BaseGoTest implements RuntimeTestSupport { + "}\n" + "\n" + "func main() {\n" - + " input := antlr.NewFileStream(os.Args[1])\n" + + " input, err := antlr.NewFileStream(os.Args[1])\n" + + " if err != nil {\n" + + " fmt.Printf("Failed to find file: %v", err)\n" + + " return\n" + + " }\n" + " lexer := parser.New(input)\n" + " stream := antlr.NewCommonTokenStream(lexer,0)\n" + "" From 81b8078860fb5e61ac8d8848f321b63f0976bc9f Mon Sep 17 00:00:00 2001 From: David Sisson Date: Sat, 29 Apr 2017 17:52:21 -0700 Subject: [PATCH 2/4] updated --- .../test/org/antlr/v4/test/runtime/go/BaseGoTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/go/BaseGoTest.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/go/BaseGoTest.java index 4f5179eff..d0b34d0f1 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/go/BaseGoTest.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/go/BaseGoTest.java @@ -698,7 +698,7 @@ public class BaseGoTest implements RuntimeTestSupport { + "func main() {\n" + " input, err := antlr.NewFileStream(os.Args[1])\n" + " if err != nil {\n" - + " fmt.Printf("Failed to find file: %v", err)\n" + + " fmt.Printf(\"Failed to find file: %v\", err)\n" + " return\n" + " }\n" + " lexer := parser.New(input)\n" From fc8b14b1dc7f36a49242b935deaeba0b5ee334e3 Mon Sep 17 00:00:00 2001 From: David Sisson Date: Sat, 29 Apr 2017 18:45:45 -0700 Subject: [PATCH 3/4] io.Copy surprisingly returns the number of bytes it copies so we need to explicitly ignore that. --- runtime/Go/antlr/file_stream.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/Go/antlr/file_stream.go b/runtime/Go/antlr/file_stream.go index 540cf5030..842170c08 100644 --- a/runtime/Go/antlr/file_stream.go +++ b/runtime/Go/antlr/file_stream.go @@ -28,9 +28,9 @@ func NewFileStream(fileName string) (*FileStream, error) { return nil, err } defer f.Close() - err = io.Copy(buf, f) + _, err = io.Copy(buf, f) if err != nil { - return nil, er + return nil, err } fs := new(FileStream) From e9dd953cf1bb4bb96eed3294c9734961a8c38e0e Mon Sep 17 00:00:00 2001 From: David Sisson Date: Sat, 29 Apr 2017 19:55:32 -0700 Subject: [PATCH 4/4] Fixed another occurrence of NewFileInputStream. --- .../test/org/antlr/v4/test/runtime/go/BaseGoTest.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/go/BaseGoTest.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/go/BaseGoTest.java index d0b34d0f1..48791461f 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/go/BaseGoTest.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/go/BaseGoTest.java @@ -674,6 +674,7 @@ public class BaseGoTest implements RuntimeTestSupport { "import (\n" +" \"github.com/antlr/antlr4/runtime/Go/antlr\"\n" +" \"./parser\"\n" + +" \"fmt\"\n" +" \"os\"\n" +")\n" + "\n" @@ -738,7 +739,11 @@ public class BaseGoTest implements RuntimeTestSupport { + ")\n" + "\n" + "func main() {\n" - + " input := antlr.NewFileStream(os.Args[1])\n" + + " input, err := antlr.NewFileStream(os.Args[1])\n" + + " if err != nil {\n" + + " fmt.Printf(\"Failed to find file: %v\", err)\n" + + " return\n" + + " }\n" + " lexer := parser.New(input)\n" + " stream := antlr.NewCommonTokenStream(lexer,0)\n" + " stream.Fill()\n"