// Copyright (c) 2016, Daniel Martí <mvdan@mvdan.cc>
// See LICENSE for licensing information

package sh

import (
	"os"
	"path/filepath"
	"strings"
	"testing"
)

func TestParse(t *testing.T) {
	paths, err := filepath.Glob("testdata/*.sh")
	if err != nil {
		t.Fatal(err)
	}
	for _, path := range paths {
		testParse(t, path)
	}
}

func testParse(t *testing.T, path string) {
	f, err := os.Open(path)
	if err != nil {
		t.Fatal(err)
	}
	defer f.Close()
	if err := parse(f, path); err != nil {
		t.Fatalf("Parse error: %v", err)
	}
}

func TestParseErr(t *testing.T) {
	errs := []string{
		"'",
		";",
		//"{",
		"=",
		"foo(",
		"foo()",
		"foo &&",
		"foo |",
		"foo ||",
		"foo >",
		"foo >>",
		"foo >&",
		"foo <",
	}
	for _, s := range errs {
		r := strings.NewReader(s)
		if err := parse(r, "stdin.go"); err == nil {
			t.Fatalf("Expected error in: %s", s)
		}
	}
}

// Copyright (c) 2016, Daniel Martí <mvdan@mvdan.cc>
// See LICENSE for licensing information

package sh

import (
	"os"
	"path/filepath"
	"testing"
)

func TestParse(t *testing.T) {
	paths, err := filepath.Glob("testdata/*.sh")
	if err != nil {
		t.Fatal(err)
	}
	for _, path := range paths {
		testParse(t, path)
	}
}

func testParse(t *testing.T, path string) {
	println(path)
	f, err := os.Open(path)
	if err != nil {
		t.Fatal(err)
	}
	defer f.Close()
	if err := parse(f, path); err != nil {
		t.Fatalf("Parse error: %v", err)
	}
}

--- 
+++ 
@@ -6,6 +6,7 @@
 import (
 	"os"
 	"path/filepath"
+	"strings"
 	"testing"
 )
 
@@ -20,7 +21,6 @@
 }
 
 func testParse(t *testing.T, path string) {
-	println(path)
 	f, err := os.Open(path)
 	if err != nil {
 		t.Fatal(err)
@@ -30,3 +30,27 @@
 		t.Fatalf("Parse error: %v", err)
 	}
 }
+
+func TestParseErr(t *testing.T) {
+	errs := []string{
+		"'",
+		";",
+		//"{",
+		"=",
+		"foo(",
+		"foo()",
+		"foo &&",
+		"foo |",
+		"foo ||",
+		"foo >",
+		"foo >>",
+		"foo >&",
+		"foo <",
+	}
+	for _, s := range errs {
+		r := strings.NewReader(s)
+		if err := parse(r, "stdin.go"); err == nil {
+			t.Fatalf("Expected error in: %s", s)
+		}
+	}
+}
Add expected parse error tests
