(t *testing.T)
| 9 | ) |
| 10 | |
| 11 | func TestCreateTasks(t *testing.T) { |
| 12 | fsys := fstest.MapFS{ |
| 13 | "a.js": {}, |
| 14 | "dir/b.js": {}, |
| 15 | } |
| 16 | |
| 17 | tests := []struct { |
| 18 | input, output string |
| 19 | tasks map[string]string |
| 20 | }{ |
| 21 | // root file |
| 22 | {"a.js", "", map[string]string{"a.js": "a.js"}}, |
| 23 | {"a.js", "-", map[string]string{"a.js": "-"}}, |
| 24 | {"a.js", ".", map[string]string{"a.js": "a.js"}}, |
| 25 | {"a.js", "./", map[string]string{"a.js": "a.js"}}, |
| 26 | {"a.js", "out", map[string]string{"a.js": "out"}}, |
| 27 | {"a.js", "out/", map[string]string{"a.js": "out/a.js"}}, |
| 28 | |
| 29 | // nested file |
| 30 | {"dir/b.js", "", map[string]string{"dir/b.js": "dir/b.js"}}, |
| 31 | {"dir/b.js", "-", map[string]string{"dir/b.js": "-"}}, |
| 32 | {"dir/b.js", ".", map[string]string{"dir/b.js": "b.js"}}, |
| 33 | {"dir/b.js", "./", map[string]string{"dir/b.js": "b.js"}}, |
| 34 | {"dir/b.js", "out", map[string]string{"dir/b.js": "out"}}, |
| 35 | {"dir/b.js", "out/", map[string]string{"dir/b.js": "out/b.js"}}, |
| 36 | |
| 37 | // directory |
| 38 | {"dir", "", map[string]string{"dir/b.js": "dir/b.js"}}, |
| 39 | {"dir", "-", map[string]string{"dir/b.js": "-"}}, |
| 40 | {"dir", ".", map[string]string{"dir/b.js": "dir/b.js"}}, |
| 41 | {"dir", "./", map[string]string{"dir/b.js": "dir/b.js"}}, |
| 42 | {"dir", "out/", map[string]string{"dir/b.js": "out/dir/b.js"}}, |
| 43 | {"dir/", "out/", map[string]string{"dir/b.js": "out/b.js"}}, |
| 44 | } |
| 45 | |
| 46 | recursive = true |
| 47 | for _, tt := range tests { |
| 48 | t.Run(tt.input+" => "+tt.output, func(t *testing.T) { |
| 49 | tasks, _, err := createTasks(fsys, []string{tt.input}, tt.output) |
| 50 | test.Error(t, err) |
| 51 | if len(tasks) != len(tt.tasks) { |
| 52 | test.Fail(t, fmt.Sprintf("missing %v", tt.tasks)) |
| 53 | } |
| 54 | for _, task := range tasks { |
| 55 | if dst, ok := tt.tasks[task.srcs[0]]; !ok || dst != task.dst { |
| 56 | test.Fail(t, fmt.Sprintf("unexpected %s => %s", task.srcs[0], task.dst)) |
| 57 | } |
| 58 | } |
| 59 | }) |
| 60 | } |
| 61 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…