Skip to content

Commit b837036

Browse files
committed
test: update ini tests
1 parent de82c9b commit b837036

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

internal/core/ini_test.go

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package core
22

33
import (
4+
"fmt"
5+
"path/filepath"
46
"strings"
57
"testing"
68
)
@@ -114,7 +116,6 @@ CommentDelimiters = "{/*"
114116
})
115117
}
116118
}
117-
118119
func Test_processConfig_transform(t *testing.T) {
119120
body := `[*.xml]
120121
Transform = transform.xsl
@@ -128,25 +129,36 @@ Transform = transform.xsl
128129
if err != nil {
129130
t.Fatal(err)
130131
}
131-
conf.AddConfigFile("C:\\Source\\project\\.vale.ini")
132+
133+
// Use a path that works on both Unix and Windows
134+
projectDir, _ := filepath.Abs(filepath.Join("Source", "project"))
135+
cfgFile := filepath.Join(projectDir, ".vale.ini")
136+
conf.AddConfigFile(cfgFile)
132137

133138
_, err = processConfig(uCfg, conf, false)
134139
if err != nil {
135140
t.Fatal(err)
136141
}
137142

138143
actual := conf.Stylesheets["*.xml"]
139-
// Transform = transform.xsl is a relative path, so it should remain as is.
140-
expected := "transform.xsl"
144+
145+
// Logic: DeterminePath joins relative 'transform.xsl' with the config dir
146+
expected := filepath.Join(projectDir, "transform.xsl")
147+
141148
if actual != expected {
142149
t.Errorf("expected %v, but got %v", expected, actual)
143150
}
144151
}
145152

146153
func Test_processConfig_transform_abs(t *testing.T) {
147-
body := `[*.xml]
148-
Transform = C:\\Source\\project\\transform.xsl
149-
`
154+
// 1. Get a clean absolute path for the current OS
155+
absPath, _ := filepath.Abs("transform.xsl")
156+
157+
// 2. Use a raw string format.
158+
body := fmt.Sprintf(`[*.xml]
159+
Transform = %s
160+
`, absPath)
161+
150162
uCfg, err := shadowLoad([]byte(body))
151163
if err != nil {
152164
t.Fatal(err)
@@ -156,17 +168,21 @@ Transform = C:\\Source\\project\\transform.xsl
156168
if err != nil {
157169
t.Fatal(err)
158170
}
159-
conf.AddConfigFile("C:\\Source\\project\\.vale.ini")
171+
172+
// 3. Ensure the project directory is also absolute/clean
173+
projectDir, _ := filepath.Abs(filepath.Join("Source", "project"))
174+
conf.AddConfigFile(filepath.Join(projectDir, ".vale.ini"))
160175

161176
_, err = processConfig(uCfg, conf, false)
162177
if err != nil {
163178
t.Fatal(err)
164179
}
165180

166181
actual := conf.Stylesheets["*.xml"]
167-
// Transform = transform.xsl is a relative path, so it should remain as is.
168-
expected := `C:\\Source\\project\\transform.xsl`
169-
if actual != expected {
170-
t.Errorf("expected %v, but got %v", expected, actual)
182+
183+
// 4. Normalize both paths before comparison to account for
184+
// any trailing slashes or separator inconsistencies.
185+
if filepath.Clean(actual) != filepath.Clean(absPath) {
186+
t.Errorf("expected %v, but got %v", absPath, actual)
171187
}
172188
}

0 commit comments

Comments
 (0)