(t *testing.T, dir string, actual map[string]string)
| 303 | } |
| 304 | |
| 305 | func cmpDirectory(t *testing.T, dir string, actual map[string]string) { |
| 306 | expected := map[string]string{} |
| 307 | var ff = func(path string, file os.FileInfo, err error) error { |
| 308 | if err != nil { |
| 309 | return err |
| 310 | } |
| 311 | if file.IsDir() { |
| 312 | return nil |
| 313 | } |
| 314 | if !strings.HasSuffix(path, ".go") && !strings.HasSuffix(path, ".kt") && !strings.HasSuffix(path, ".py") && !strings.HasSuffix(path, ".json") && !strings.HasSuffix(path, ".txt") { |
| 315 | return nil |
| 316 | } |
| 317 | // TODO: Figure out a better way to ignore certain files |
| 318 | if strings.HasSuffix(path, ".txt") && filepath.Base(path) != "hello.txt" { |
| 319 | return nil |
| 320 | } |
| 321 | if filepath.Base(path) == "sqlc.json" { |
| 322 | return nil |
| 323 | } |
| 324 | if filepath.Base(path) == "exec.json" { |
| 325 | return nil |
| 326 | } |
| 327 | if strings.Contains(path, "/kotlin/build") { |
| 328 | return nil |
| 329 | } |
| 330 | if strings.HasSuffix(path, "_test.go") || strings.Contains(path, "src/test/") { |
| 331 | return nil |
| 332 | } |
| 333 | if strings.Contains(path, "/python/.venv") || strings.Contains(path, "/python/src/tests/") || |
| 334 | strings.HasSuffix(path, "__init__.py") || strings.Contains(path, "/python/src/dbtest/") || |
| 335 | strings.Contains(path, "/python/.mypy_cache") { |
| 336 | return nil |
| 337 | } |
| 338 | blob, err := os.ReadFile(path) |
| 339 | if err != nil { |
| 340 | return err |
| 341 | } |
| 342 | expected[path] = string(blob) |
| 343 | return nil |
| 344 | } |
| 345 | if err := filepath.Walk(dir, ff); err != nil { |
| 346 | t.Fatal(err) |
| 347 | } |
| 348 | |
| 349 | opts := []cmp.Option{ |
| 350 | cmpopts.EquateEmpty(), |
| 351 | lineEndings(), |
| 352 | } |
| 353 | |
| 354 | if !cmp.Equal(expected, actual, opts...) { |
| 355 | t.Errorf("%s contents differ", dir) |
| 356 | for name, contents := range expected { |
| 357 | name := name |
| 358 | if actual[name] == "" { |
| 359 | t.Errorf("%s is empty", name) |
| 360 | return |
| 361 | } |
| 362 | if diff := cmp.Diff(contents, actual[name], opts...); diff != "" { |
no test coverage detected