diff --git a/check/checktest/checktest.go b/check/checktest/checktest.go index f2f4350..6d0e641 100644 --- a/check/checktest/checktest.go +++ b/check/checktest/checktest.go @@ -336,10 +336,13 @@ func compile( moduleName descriptor.ModuleName, ) ([]descriptor.FileDescriptor, error) { dirPaths = fromSlashPaths(dirPaths) - filePaths = fromSlashPaths(filePaths) + // The compiler names each file by the path it is given, and .proto file + // names use forward slashes even on Windows. + toSlashFilePaths := make([]string, len(filePaths)) toSlashFilePathMap := make(map[string]struct{}, len(filePaths)) - for _, filePath := range filePaths { - toSlashFilePathMap[filepath.ToSlash(filePath)] = struct{}{} + for i, filePath := range fromSlashPaths(filePaths) { + toSlashFilePaths[i] = filepath.ToSlash(filePath) + toSlashFilePathMap[toSlashFilePaths[i]] = struct{}{} } var warningErrorsWithPos []reporter.ErrorWithPos @@ -360,7 +363,7 @@ func compile( // This is what buf uses. SourceInfoMode: protocompile.SourceInfoExtraOptionLocations, } - files, err := compiler.Compile(ctx, filePaths...) + files, err := compiler.Compile(ctx, toSlashFilePaths...) if err != nil { return nil, err } diff --git a/check/internal/example/cmd/buf-plugin-syntax-specified/main_test.go b/check/internal/example/cmd/buf-plugin-syntax-specified/main_test.go index 77f7f85..742a7d4 100644 --- a/check/internal/example/cmd/buf-plugin-syntax-specified/main_test.go +++ b/check/internal/example/cmd/buf-plugin-syntax-specified/main_test.go @@ -60,3 +60,25 @@ func TestSimpleFailure(t *testing.T) { }, }.Run(t) } + +func TestSubdirectoryFailure(t *testing.T) { + t.Parallel() + + checktest.CheckTest{ + Request: &checktest.RequestSpec{ + Files: &checktest.ProtoFileSpec{ + DirPaths: []string{"testdata/subdirectory_failure"}, + FilePaths: []string{"sub/simple.proto"}, + }, + }, + Spec: spec, + ExpectedAnnotations: []checktest.ExpectedAnnotation{ + { + RuleID: syntaxSpecifiedRuleID, + FileLocation: &checktest.ExpectedFileLocation{ + FileName: "sub/simple.proto", + }, + }, + }, + }.Run(t) +} diff --git a/check/internal/example/cmd/buf-plugin-syntax-specified/testdata/subdirectory_failure/sub/simple.proto b/check/internal/example/cmd/buf-plugin-syntax-specified/testdata/subdirectory_failure/sub/simple.proto new file mode 100644 index 0000000..322a627 --- /dev/null +++ b/check/internal/example/cmd/buf-plugin-syntax-specified/testdata/subdirectory_failure/sub/simple.proto @@ -0,0 +1 @@ +package simple;