-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add a -json command-line flag for JSON output. * Add JSON test. * Add more coverage. * Add Column to JSON output. Update Readme.
- Loading branch information
Showing
3 changed files
with
243 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"path/filepath" | ||
"reflect" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/bobg/go-generics/v3/iter" | ||
) | ||
|
||
func TestRunJSON(t *testing.T) { | ||
buf := new(bytes.Buffer) | ||
if err := run(buf, false, true, []string{"../.."}); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
var ( | ||
got []jtuple | ||
dec = json.NewDecoder(buf) | ||
) | ||
for dec.More() { | ||
var val jtuple | ||
if err := dec.Decode(&val); err != nil { | ||
t.Fatal(err) | ||
} | ||
val.FileName = filepath.Base(val.FileName) | ||
got = append(got, val) | ||
} | ||
|
||
want := []jtuple{{ | ||
PackageName: "main", | ||
FileName: "main.go", | ||
Line: 100, | ||
Column: 6, | ||
FuncName: "showJSON", | ||
Params: []jparam{{ | ||
Name: "checker", | ||
Methods: []string{ | ||
"NameForMethods", | ||
}, | ||
}}, | ||
}} | ||
|
||
if !reflect.DeepEqual(got, want) { | ||
t.Errorf("got %v, want %v", got, want) | ||
} | ||
} | ||
|
||
func TestRunPlain(t *testing.T) { | ||
buf := new(bytes.Buffer) | ||
if err := run(buf, false, false, []string{"../.."}); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
lines, err := iter.ToSlice(iter.Lines(buf)) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if len(lines) != 2 { | ||
t.Fatalf("got %d lines, want 2", len(lines)) | ||
} | ||
if !strings.HasSuffix(lines[0], ": showJSON") { | ||
t.Fatalf(`line 1 is "%s", want something ending in ": showJSON"`, lines[0]) | ||
} | ||
|
||
lines[1] = strings.TrimSpace(lines[1]) | ||
const want = "checker: [NameForMethods]" | ||
if lines[1] != want { | ||
t.Fatalf(`line 2 is "%s", want "%s"`, lines[1], want) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters