Silence trailing "1 warning" message from javac when warning is silenced
soong_javac_wrapper is silencing a useless warning:
warning: [options] bootstrap class path not set in conjunction with -source 1.9
but recent versions of javac have started also printing:
1 warning
Read the warning count, subtract the number of silenced warnings, and
reprint it if the non-silenced warning count is nonzero.
Fixes: 144118634
Test: javac_wrapper_test.go
Change-Id: Ie1d0a978188ab7b1c41027f718a1274608628123
diff --git a/cmd/javac_wrapper/javac_wrapper_test.go b/cmd/javac_wrapper/javac_wrapper_test.go
index ad657e7..ad23001 100644
--- a/cmd/javac_wrapper/javac_wrapper_test.go
+++ b/cmd/javac_wrapper/javac_wrapper_test.go
@@ -75,13 +75,29 @@
`,
out: "\n",
},
+ {
+ in: `
+warning: [options] bootstrap class path not set in conjunction with -source 1.9\n
+1 warning
+`,
+ out: "\n",
+ },
+ {
+ in: `
+warning: foo
+warning: [options] bootstrap class path not set in conjunction with -source 1.9\n
+2 warnings
+`,
+ out: "\n\x1b[1m\x1b[35mwarning:\x1b[0m\x1b[1m foo\x1b[0m\n1 warning\n",
+ },
}
func TestJavacColorize(t *testing.T) {
for i, test := range testCases {
t.Run(strconv.Itoa(i), func(t *testing.T) {
buf := new(bytes.Buffer)
- err := process(bytes.NewReader([]byte(test.in)), buf)
+ proc := processor{}
+ err := proc.process(bytes.NewReader([]byte(test.in)), buf)
if err != nil {
t.Errorf("error: %q", err)
}