Add unit tests for android/neverallow.go

Bug: 74506774
Test: lunch aosp_walleye-userdebug && make  # runs unit tests
Change-Id: Ibde685d7213713be219681cb039ad58a43d9c377
This commit is contained in:
Logan Chien
2018-03-12 16:34:26 +08:00
parent 4203971351
commit ee97c3ed75
4 changed files with 222 additions and 26 deletions

View File

@@ -17,6 +17,7 @@ package android
import (
"fmt"
"path/filepath"
"regexp"
"strings"
"testing"
@@ -163,3 +164,26 @@ func FailIfErrored(t *testing.T, errs []error) {
t.FailNow()
}
}
func FailIfNoMatchingErrors(t *testing.T, pattern string, errs []error) {
t.Helper()
matcher, err := regexp.Compile(pattern)
if err != nil {
t.Errorf("failed to compile regular expression %q because %s", pattern, err)
}
found := false
for _, err := range errs {
if matcher.FindStringIndex(err.Error()) != nil {
found = true
break
}
}
if !found {
t.Errorf("missing the expected error %q (checked %d error(s))", pattern, len(errs))
for i, err := range errs {
t.Errorf("errs[%d] = %s", i, err)
}
}
}