fix-tests: fix when gtest outputs absolute source paths

Since CMake 3.21, the Ninja generator now outputs absolute paths to
source files, rather than relative. These paths are what __FILE__ gets
mapped to during compilation, and is what gtest outputs for test
failures. This broke fix-tests, which assumed a build-relative source
path. This change detects when the source file path is absolute, and
converts it to a build-relative one.

Also, on Windows, absolute paths include the drive with a colon
character, so I added matching the colon to the regex for the path
portion.

Change-Id: I065161d65f098023376b7e479d8a24a83beb1df7
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/69440
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
Antonio Maiorano 2021-11-16 15:09:56 +00:00 committed by Tint LUCI CQ
parent 04e62a12d8
commit 2551458aef
1 changed files with 7 additions and 4 deletions

View File

@ -144,9 +144,9 @@ var (
// Regular expression to match a test declaration
reTests = regexp.MustCompile(`TEST(?:_[FP])?\([ \n]*(\w+),[ \n]*(\w+)\)`)
// Regular expression to match a `EXPECT_EQ(a, b)` failure for strings
reExpectEq = regexp.MustCompile(`([./\\\w_-]*):(\d+).*\nExpected equality of these values:\n(?:.|\n)*?(?:Which is: | )"((?:.|\n)*?[^\\])"\n(?:.|\n)*?(?:Which is: | )"((?:.|\n)*?[^\\])"`)
reExpectEq = regexp.MustCompile(`([./\\\w_\-:]*):(\d+).*\nExpected equality of these values:\n(?:.|\n)*?(?:Which is: | )"((?:.|\n)*?[^\\])"\n(?:.|\n)*?(?:Which is: | )"((?:.|\n)*?[^\\])"`)
// Regular expression to match a `EXPECT_THAT(a, HasSubstr(b))` failure for strings
reExpectHasSubstr = regexp.MustCompile(`([./\\\w_-]*):(\d+).*\nValue of: .*\nExpected: has substring "((?:.|\n)*?[^\\])"\n Actual: "((?:.|\n)*?[^\\])"`)
reExpectHasSubstr = regexp.MustCompile(`([./\\\w_\-:]*):(\d+).*\nValue of: .*\nExpected: has substring "((?:.|\n)*?[^\\])"\n Actual: "((?:.|\n)*?[^\\])"`)
)
func processFailure(test, wd, failure string) error {
@ -219,8 +219,11 @@ func processFailure(test, wd, failure string) error {
return fmt.Errorf("Cannot fix this type of failure")
}
// Get the path to the source file containing the test failure
sourcePath := filepath.Join(wd, file)
// Get the absolute source path
sourcePath := file
if !filepath.IsAbs(sourcePath) {
sourcePath = filepath.Join(wd, file)
}
// Parse the source file, split into tests
sourceFile, err := parseSourceFile(sourcePath)