Skip to content

Commit

Permalink
Add a test for WARNINGS.md (#660)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladmos authored Jul 12, 2019
1 parent 1e195bc commit d7ccc55
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
7 changes: 7 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ config_setting(
values = {"cpu": "x64_windows"},
)

filegroup(
name = "warnings",
srcs = ["WARNINGS.md"],
visibility = ["//warn:__pkg__"]
)

test_suite(
name = "tests",
tests = [
Expand All @@ -18,6 +24,7 @@ test_suite(
"//extra_actions_base_proto:extra_actions_base.gen.pb.go_checkshtest",
"//lang:tables.gen.go_checkshtest",
"//tables:go_default_test",
"//warn:go_default_test",
"//wspace:go_default_test",
],
)
Expand Down
6 changes: 5 additions & 1 deletion warn/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ go_library(
)

go_test(
name = "warn_test",
name = "go_default_test",
size = "small",
srcs = [
"documentation_test.go",
"types_test.go",
"warn_bazel_api_test.go",
"warn_bazel_operation_test.go",
Expand All @@ -40,6 +41,9 @@ go_test(
"warn_test.go",
],
embed = [":go_default_library"],
data = [
"//:warnings",
],
deps = [
"//testutils",
],
Expand Down
37 changes: 37 additions & 0 deletions warn/documentation_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package warn

import (
"fmt"
"io/ioutil"
"strings"
"testing"

"github.com/bazelbuild/buildtools/testutils"
)

func TestWarningsDocumentation(t *testing.T) {
files, chdir := testutils.FindTests(t, "", "WARNINGS.md")
defer chdir()

if len(files) != 1 {
t.Fatalf("Expected to find exactly one WARNINGS.md file, got %d instead", len(files))
}
data, err := ioutil.ReadFile(files[0])
if err != nil {
t.Fatal(err)
return
}

contents := string(data)
for _, warning := range AllWarnings {
link := fmt.Sprintf(" * [%s](#%s)", warning, warning)
if !strings.Contains(contents, link) {
t.Errorf("No link (%q) found for the warning %q in WARNINGS.md, is it documented?", link, warning)
}

anchor := fmt.Sprintf(`<a name="%s"></a>`, warning)
if !strings.Contains(contents, anchor) {
t.Errorf("No anchor (%q) found for the warning %q in WARNINGS.md, is it documented?", anchor, warning)
}
}
}

0 comments on commit d7ccc55

Please sign in to comment.