tools/cts: Handle CRLF in expectations.txt

Change-Id: Iccc9f0b4c488a93a3014bd1d2415b42b05c01553
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/114000
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
Ben Clayton 2022-12-13 14:55:50 +00:00 committed by Dawn LUCI CQ
parent f2b86aaffb
commit 61dbeb5b72
6 changed files with 50 additions and 12 deletions

View File

@ -222,7 +222,7 @@ func (r *roller) roll(ctx context.Context) error {
if err != nil {
return err
}
ex, err := expectations.Parse(expectationsFile)
ex, err := expectations.Parse(common.RelativeExpectationsPath, expectationsFile)
if err != nil {
return fmt.Errorf("failed to load expectations: %v", err)
}

View File

@ -90,7 +90,7 @@ func Load(path string) (Content, error) {
if err != nil {
return Content{}, err
}
ex, err := Parse(string(content))
ex, err := Parse(path, string(content))
if err != nil {
return Content{}, err
}

View File

@ -15,6 +15,7 @@
package expectations
import (
"fmt"
"strings"
"dawn.googlesource.com/dawn/tools/src/cts/result"
@ -26,7 +27,10 @@ const (
)
// Parse parses an expectations file, returning the Content
func Parse(body string) (Content, error) {
func Parse(path, body string) (Content, error) {
// Normalize CRLF -> LF
body = strings.ReplaceAll(body, "\r\n", "\n")
// LineType is an enumerator classifying the 'type' of the line.
type LineType int
const (
@ -120,7 +124,7 @@ func Parse(body string) (Content, error) {
if columnIdx == 1 {
columnIdx = len(l) + 1
}
return Diagnostic{Error, lineIdx, columnIdx, msg}
return fmt.Errorf("%v:%v:%v error: %v", path, lineIdx, columnIdx, msg)
}
// peek returns the next token without consuming it.

View File

@ -65,6 +65,16 @@ func TestParse(t *testing.T) {
},
},
}, /////////////////////////////////////////////////////////////////////
{
name: "carriage-return line-feed, followed by single line comment",
in: "\r\n# a comment",
expect: expectations.Content{
Chunks: []expectations.Chunk{
{},
{Comments: []string{`# a comment`}},
},
},
}, /////////////////////////////////////////////////////////////////////
{
name: "comments separated by single newline",
in: `# comment 1
@ -126,6 +136,30 @@ func TestParse(t *testing.T) {
},
},
}, /////////////////////////////////////////////////////////////////////
{
name: "two expectations, separated with carriage-return line-feed",
in: "abc,def [ FAIL ]\r\nghi,jkl [ PASS ]",
expect: expectations.Content{
Chunks: []expectations.Chunk{
{
Expectations: []expectations.Expectation{
{
Line: 1,
Tags: result.NewTags(),
Query: "abc,def",
Status: []string{"FAIL"},
},
{
Line: 2,
Tags: result.NewTags(),
Query: "ghi,jkl",
Status: []string{"PASS"},
},
},
},
},
},
}, /////////////////////////////////////////////////////////////////////
{
name: "expectation, with comment",
in: `abc,def [ FAIL ] # this is a comment`,
@ -432,31 +466,31 @@ crbug.com/456 [ Mac ] ghi_jkl [ PASS ]
{
name: "err missing tag ']'",
in: `[`,
expectErr: "1:2 error: expected ']' for tags",
expectErr: "expectations.txt:1:2 error: expected ']' for tags",
}, /////////////////////////////////////////////////////////////////////
{
name: "err missing test query",
in: `[ a ]`,
expectErr: "1:6 error: expected test query",
expectErr: "expectations.txt:1:6 error: expected test query",
}, /////////////////////////////////////////////////////////////////////
{
name: "err missing status EOL",
in: `[ a ] b`,
expectErr: "1:8 error: expected status",
expectErr: "expectations.txt:1:8 error: expected status",
}, /////////////////////////////////////////////////////////////////////
{
name: "err missing status comment",
in: `[ a ] b # c`,
expectErr: "1:9 error: expected status",
expectErr: "expectations.txt:1:9 error: expected status",
}, /////////////////////////////////////////////////////////////////////
{
name: "err missing status ']'",
in: `[ a ] b [ c`,
expectErr: "1:12 error: expected ']' for status",
expectErr: "expectations.txt:1:12 error: expected ']' for status",
},
} {
got, err := expectations.Parse(test.in)
got, err := expectations.Parse("expectations.txt", test.in)
errMsg := ""
if err != nil {
errMsg = err.Error()

View File

@ -507,7 +507,7 @@ crbug.com/dawn/0000 a:b,c:t29:* [ Failure ]
`,
},
} {
ex, err := expectations.Parse(header + test.expectations)
ex, err := expectations.Parse("expectations.txt", header+test.expectations)
if err != nil {
t.Fatalf("'%v': expectations.Parse():\n%v", test.name, err)
}

View File

@ -117,7 +117,7 @@ crbug.com/a/123 [ os-a ] a:b,c:d,* [ Failure ]
},
},
} {
ex, err := expectations.Parse(header + test.expectations)
ex, err := expectations.Parse("expectations.txt", header+test.expectations)
if err != nil {
t.Fatalf("'%v': expectations.Parse():\n%v", test.name, err)
}