func TestAnalyze(t *testing.T) { tests := []struct { dir string files []string numResults int }{ { "shipshape/androidlint_analyzer/androidlint/testdata", []string{"TicTacToeLib/res/values/strings.xml"}, 9, }, { "shipshape/androidlint_analyzer/androidlint/testdata", []string{"TicTacToeLib/res/values/strings.xml", "TicTacToeMain/res/values/strings.xml"}, 17, }, { "shipshape/androidlint_analyzer/androidlint/testdata/TicTacToeMain", []string{"res/values/strings.xml"}, 8, }, { "shipshape/androidlint_analyzer/androidlint/testdata", []string{"TicTacToeLib/src/com/example/android/tictactoe/library/GameView.java"}, 9, }, { "shipshape/androidlint_analyzer/androidlint/testdata", []string{"OtherProject/strings.xml"}, 0, }, } var a Analyzer for _, test := range tests { ctx, err := testutil.CreateContext(test.dir, test.files) if err != nil { t.Fatalf("error from CreateContext: %v", err) } actualNotes, err := testutil.RunAnalyzer(ctx, a, t) if err != nil { t.Errorf("received an analysis failure: %v", err) } if len(actualNotes) != test.numResults { t.Errorf("Number of results: got %d, want %d", len(actualNotes), test.numResults) } } }
func TestAnalyzeFailure(t *testing.T) { tests := []string{"nonexistentfile.txt"} var w WordCountAnalyzer for _, input := range tests { ctx, err := test.CreateContext(dataDir, []string{input}) if err != nil { t.Errorf("error from CreateContext: %v", err) } notes, err := w.Analyze(ctx) if err == nil { t.Errorf("expected an analysis failure for input %s", input) } if notes != nil { t.Errorf("received notes %v for input %s", notes, input) } } }
func TestAnalyze(t *testing.T) { tests := []struct { file string words int }{ {"simple.txt", 6}, {"complex.txt", 10}, {"empty.txt", 0}, {"whitespace.txt", 0}, } var w WordCountAnalyzer for _, pair := range tests { ctx, err := test.CreateContext(dataDir, []string{pair.file}) if err != nil { t.Fatalf("error from CreateContext: %v", err) } actualNotes, err := test.RunAnalyzer(ctx, w, t) if err != nil { t.Errorf("received an analysis failure: %v", err) } expectedNotes := []*notespb.Note{ ¬espb.Note{ Category: proto.String("WordCount"), Description: proto.String(fmt.Sprintf("Word count: %d", pair.words)), }, } pass, message := test.CheckNoteContainsContent(expectedNotes, actualNotes) if !pass { t.Errorf(message) } } }