Skip to content

Commit f6958c0

Browse files
authored
Asciidoctor: Consistent sorting in warning message (#615)
When our copy images extension can't find an image it outputs *all* of the paths that it searched so you can be super sure it searched all the places that you wanted it to search. This sorts the output so that the error message is consistent. Which is mostly nice for tests. I mean, it is nice for stuff like reproducibility of errors locally too, but it is super nice for tests. And it is my tests that are failing.
1 parent 54c4107 commit f6958c0

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

resources/asciidoctor/lib/copy_images/extension.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ def find_source(block, uri)
124124

125125
# We'll skip images we can't find but we should log something about it so
126126
# we can fix them.
127+
checked.sort! { |lhs, rhs|
128+
by_depth = lhs.scan(/\//).count <=> rhs.scan(/\//).count
129+
if by_depth != 0
130+
by_depth
131+
else
132+
lhs <=> rhs
133+
end
134+
}
127135
logger.warn message_with_context "can't read image at any of #{checked}", :source_location => block.source_location
128136
nil
129137
end

resources/asciidoctor/spec/copy_images_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ def copy_attributes(copied)
208208
ASCIIDOC
209209
convert input, attributes, match(/
210210
WARN:\ <stdin>:\ line\ 2:\ can't\ read\ image\ at\ any\ of\ \[
211+
"#{tmp}\/not_found.png",\s
211212
"#{spec_dir}\/not_found.png",\s
212-
"#{tmp}\/not_found.png"
213213
.+
214214
\]/x).and(not_match(/INFO: <stdin>/))
215215
expect(copied).to eq([])
@@ -227,9 +227,9 @@ def copy_attributes(copied)
227227
ASCIIDOC
228228
convert input, attributes, match(/
229229
WARN:\ <stdin>:\ line\ 2:\ can't\ read\ image\ at\ any\ of\ \[
230-
"#{spec_dir}\/not_found.png",\s
230+
"\/dummy2\/not_found.png",\s
231231
"#{tmp}\/not_found.png",\s
232-
"\/dummy2\/not_found.png"
232+
"#{spec_dir}\/not_found.png",\s
233233
.+
234234
\]/x).and(not_match(/INFO: <stdin>/))
235235
expect(copied).to eq([])

0 commit comments

Comments
 (0)