Skip to content

Commit 2c62b19

Browse files
Fix relative file paths in spec output on Windows (#14725)
1 parent b14be1e commit 2c62b19

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

src/spec/context.cr

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ module Spec
191191
failures = results_for(:fail)
192192
errors = results_for(:error)
193193

194+
cwd = Dir.current
195+
194196
failures_and_errors = failures + errors
195197
unless failures_and_errors.empty?
196198
puts
@@ -216,7 +218,7 @@ module Spec
216218

217219
if ex.is_a?(SpecError)
218220
puts
219-
puts Spec.color(" # #{Spec.relative_file(ex.file)}:#{ex.line}", :comment)
221+
puts Spec.color(" # #{Path[ex.file].relative_to(cwd)}:#{ex.line}", :comment)
220222
end
221223
end
222224
end
@@ -232,7 +234,7 @@ module Spec
232234
top_n.each do |res|
233235
puts " #{res.description}"
234236
res_elapsed = res.elapsed.not_nil!.total_seconds.humanize
235-
puts " #{res_elapsed.colorize.bold} seconds #{Spec.relative_file(res.file)}:#{res.line}"
237+
puts " #{res_elapsed.colorize.bold} seconds #{Path[res.file].relative_to(cwd)}:#{res.line}"
236238
end
237239
end
238240

@@ -258,7 +260,7 @@ module Spec
258260
puts "Failed examples:"
259261
puts
260262
failures_and_errors.each do |fail|
261-
print Spec.color("crystal spec #{Spec.relative_file(fail.file)}:#{fail.line}", :error)
263+
print Spec.color("crystal spec #{Path[fail.file].relative_to(cwd)}:#{fail.line}", :error)
262264
puts Spec.color(" # #{fail.description}", :comment)
263265
end
264266
end

src/spec/source.cr

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,4 @@ module Spec
1111
lines = lines_cache.put_if_absent(file) { File.read_lines(file) }
1212
lines[line - 1]?
1313
end
14-
15-
# :nodoc:
16-
def self.relative_file(file)
17-
cwd = Dir.current
18-
if basename = file.lchop? cwd
19-
basename.lchop '/'
20-
else
21-
file
22-
end
23-
end
2414
end

0 commit comments

Comments
 (0)