Skip to content

Commit 4fab27b

Browse files
committed
fix: revert to native path separators on windows and fix cross-platform tests
- Revert to backslashes on Windows (glob v13 default behavior) - Forward slashes only when posix: true explicitly set - Update parallel tests to use posix: true for predictable assertions
1 parent 4202d7a commit 4fab27b

2 files changed

Lines changed: 29 additions & 14 deletions

File tree

src/glob.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2023,12 +2023,15 @@ impl Glob {
20232023

20242024
/// Check if backslashes should be normalized to forward slashes.
20252025
///
2026-
/// glob v13 uses forward slashes by default on all platforms.
2027-
/// Only when posix is explicitly set to false on Windows are backslashes used.
2026+
/// On Windows with posix: false (the default), glob v13 outputs backslashes.
2027+
/// On Windows with posix: true, glob v13 outputs forward slashes.
2028+
/// On non-Windows, glob v13 always outputs forward slashes.
20282029
#[inline]
20292030
fn should_normalize_backslashes(&self) -> bool {
2030-
// Use forward slashes unless posix was explicitly set to false on Windows
2031-
!cfg!(target_os = "windows") || !self.posix_explicit_false
2031+
// Use forward slashes when:
2032+
// - On non-Windows platforms (always)
2033+
// - On Windows with posix: true
2034+
self.posix_explicit_true || !cfg!(target_os = "windows")
20322035
}
20332036

20342037
/// Normalize path separators based on platform and posix option.

tests/compat/parallel.test.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ describe('parallel option', () => {
4242

4343
describe('basic functionality', () => {
4444
it('parallel: false returns correct results (default)', () => {
45-
const results = globSync('**/*.ts', { cwd: fixture, parallel: false })
45+
// Use posix: true for predictable forward slashes in test assertions
46+
const results = globSync('**/*.ts', { cwd: fixture, parallel: false, posix: true })
4647

4748
expect(results).toContain('src/index.ts')
4849
expect(results).toContain('src/util.ts')
@@ -54,7 +55,8 @@ describe('parallel option', () => {
5455
})
5556

5657
it('parallel: true returns correct results', () => {
57-
const results = globSync('**/*.ts', { cwd: fixture, parallel: true })
58+
// Use posix: true for predictable forward slashes in test assertions
59+
const results = globSync('**/*.ts', { cwd: fixture, parallel: true, posix: true })
5860

5961
expect(results).toContain('src/index.ts')
6062
expect(results).toContain('src/util.ts')
@@ -114,11 +116,12 @@ describe('parallel option', () => {
114116
})
115117

116118
it('parallel works with maxDepth', () => {
119+
// Use posix: true for predictable path separators
117120
const serialResults = new Set(
118-
globSync('**/*', { cwd: fixture, parallel: false, maxDepth: 2 })
121+
globSync('**/*', { cwd: fixture, parallel: false, maxDepth: 2, posix: true })
119122
)
120123
const parallelResults = new Set(
121-
globSync('**/*', { cwd: fixture, parallel: true, maxDepth: 2 })
124+
globSync('**/*', { cwd: fixture, parallel: true, maxDepth: 2, posix: true })
122125
)
123126

124127
expect(parallelResults).toEqual(serialResults)
@@ -144,18 +147,21 @@ describe('parallel option', () => {
144147
})
145148

146149
it('parallel works with ignore patterns', () => {
150+
// Use posix: true for predictable path separators
147151
const serialResults = new Set(
148152
globSync('**/*', {
149153
cwd: fixture,
150154
parallel: false,
151155
ignore: ['**/node_modules/**'],
156+
posix: true,
152157
})
153158
)
154159
const parallelResults = new Set(
155160
globSync('**/*', {
156161
cwd: fixture,
157162
parallel: true,
158163
ignore: ['**/node_modules/**'],
164+
posix: true,
159165
})
160166
)
161167

@@ -165,9 +171,12 @@ describe('parallel option', () => {
165171
})
166172

167173
it('parallel works with mark: true', () => {
168-
const serialResults = new Set(globSync('**/*', { cwd: fixture, parallel: false, mark: true }))
174+
// Use posix: true for predictable path separators
175+
const serialResults = new Set(
176+
globSync('**/*', { cwd: fixture, parallel: false, mark: true, posix: true })
177+
)
169178
const parallelResults = new Set(
170-
globSync('**/*', { cwd: fixture, parallel: true, mark: true })
179+
globSync('**/*', { cwd: fixture, parallel: true, mark: true, posix: true })
171180
)
172181

173182
expect(parallelResults).toEqual(serialResults)
@@ -177,11 +186,12 @@ describe('parallel option', () => {
177186
})
178187

179188
it('parallel works with dotRelative: true', () => {
189+
// Use posix: true for predictable path separators
180190
const serialResults = new Set(
181-
globSync('**/*.md', { cwd: fixture, parallel: false, dotRelative: true })
191+
globSync('**/*.md', { cwd: fixture, parallel: false, dotRelative: true, posix: true })
182192
)
183193
const parallelResults = new Set(
184-
globSync('**/*.md', { cwd: fixture, parallel: true, dotRelative: true })
194+
globSync('**/*.md', { cwd: fixture, parallel: true, dotRelative: true, posix: true })
185195
)
186196

187197
expect(parallelResults).toEqual(serialResults)
@@ -194,7 +204,8 @@ describe('parallel option', () => {
194204

195205
describe('Glob class with parallel', () => {
196206
it('Glob class accepts parallel option', () => {
197-
const g = new Glob('**/*.ts', { cwd: fixture, parallel: true })
207+
// Use posix: true for predictable path separators
208+
const g = new Glob('**/*.ts', { cwd: fixture, parallel: true, posix: true })
198209
const results = g.walkSync()
199210

200211
expect(results).toContain('src/index.ts')
@@ -212,7 +223,8 @@ describe('parallel option', () => {
212223
})
213224

214225
it('Glob class async walk with parallel', async () => {
215-
const g = new Glob('**/*.md', { cwd: fixture, parallel: true })
226+
// Use posix: true for predictable path separators
227+
const g = new Glob('**/*.md', { cwd: fixture, parallel: true, posix: true })
216228
const results = await g.walk()
217229

218230
expect(results).toContain('docs/readme.md')

0 commit comments

Comments
 (0)