Skip to content
This repository was archived by the owner on Apr 30, 2025. It is now read-only.

Commit 26527fd

Browse files
committed
Move import mapper test into main test
1 parent ea7b68c commit 26527fd

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

generate_test.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,14 @@ func TestGenerateWithImports(t *testing.T) {
4646
ToDo: map[string]string{
4747
"imports/oneref_verbose": "Figure out how to disambiguate struct literals from the struct-with-braces-and-one-element case",
4848
},
49-
ImportMappers: map[string]func(string) (string, error){
50-
"imports/imports": func(s string) (string, error) {
51-
if s == "example.com/dep" {
52-
return "@example/deps", nil
53-
}
54-
return s, nil
55-
},
49+
}
50+
51+
importMappers := map[string]func(s string) (string, error){
52+
"imports/imports": func(s string) (string, error) {
53+
if s == "example.com/dep" {
54+
return "@example/deps", nil
55+
}
56+
return s, nil
5657
},
5758
}
5859

@@ -64,9 +65,16 @@ func TestGenerateWithImports(t *testing.T) {
6465
t.Fatal(v.Err())
6566
}
6667

68+
im := func(s string) (string, error) {
69+
return "", nil
70+
}
71+
if i, ok := importMappers[t.Name]; ok {
72+
im = i
73+
}
74+
6775
b, err := cuetsy.Generate(v, cuetsy.Config{
6876
Export: true,
69-
ImportMapper: t.ImportMapperFn,
77+
ImportMapper: im,
7078
})
7179
if err != nil {
7280
errors.Print(t, err, nil)

internal/cuetxtar/cuetxtar.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ type TxTarTest struct {
5959

6060
// ToDo is a map of tests that should be skipped now, but should be fixed.
6161
ToDo map[string]string
62-
63-
ImportMappers map[string]func(string) (string, error)
6462
}
6563

6664
// A Test represents a single test based on a .txtar file.
@@ -86,7 +84,7 @@ type Test struct {
8684

8785
hasGold bool
8886

89-
ImportMapperFn func(s string) (string, error)
87+
Name string
9088
}
9189

9290
func (t *Test) Write(b []byte) (n int, err error) {
@@ -270,6 +268,7 @@ func (x *TxTarTest) Run(t *testing.T, f func(tc *Test)) {
270268
T: t,
271269
Archive: a,
272270
Dir: filepath.Dir(filepath.Join(dir, fullpath)),
271+
Name: testName,
273272

274273
prefix: path.Join("out", x.Name),
275274
}
@@ -292,14 +291,6 @@ func (x *TxTarTest) Run(t *testing.T, f func(tc *Test)) {
292291
t.Skip(msg)
293292
}
294293

295-
if im, ok := x.ImportMappers[testName]; ok {
296-
tc.ImportMapperFn = im
297-
} else {
298-
tc.ImportMapperFn = func(s string) (string, error) {
299-
return "", nil
300-
}
301-
}
302-
303294
f(tc)
304295

305296
update := false

0 commit comments

Comments
 (0)