Skip to content

Commit 00d39c3

Browse files
committed
fix targetcustom spec with libvips 8.13
Due to a libvips bug, we need to close in line with targetcustom output. see #351
1 parent 932c31a commit 00d39c3

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* add `Vips.vector?` to get/set SIMD status [jeremy]
99
* add `Vips.concurrency` to get/set threadpool size [jeremy]
1010
* add `Vips.concurrency_default` to get the default threadpool size [jeremy]
11+
* fix targetcustom spec test with libvips 8.13 [lucaskanashiro]
1112

1213
## Version 2.1.4 (2021-10-28)
1314

spec/connection_spec.rb

+34-9
Original file line numberDiff line numberDiff line change
@@ -140,21 +140,46 @@
140140

141141
expect(target)
142142
end
143+
end
144+
145+
# 8.13 had a broken on_finish, so close ourselves before 8.14
146+
RSpec.describe Vips::SourceCustom, version: [8, 9] do
147+
it "can write an image to a user output stream with explicit close" do
148+
image = Vips::Image.new_from_file simg("wagon.jpg")
143149

144-
it "can write an image to a user output stream" do
145150
filename = timg("x5.png")
146151
file = File.open filename, "wb"
147152
target = Vips::TargetCustom.new
148153
target.on_write { |chunk| file.write(chunk) }
149-
target.on_finish { file.close }
150-
image = Vips::Image.new_from_file simg("wagon.jpg")
151154
image.write_to_target target, ".png"
155+
file.close
152156

153-
image = Vips::Image.new_from_file filename
154-
expect(image)
155-
expect(image.width).to eq(685)
156-
expect(image.height).to eq(478)
157-
expect(image.bands).to eq(3)
158-
expect(image.avg).to be_within(0.001).of(109.789)
157+
image2 = Vips::Image.new_from_file filename
158+
expect(image2)
159+
expect(image2.width).to eq(685)
160+
expect(image2.height).to eq(478)
161+
expect(image2.bands).to eq(3)
162+
expect(image2.avg).to eq(image.avg)
163+
end
164+
end
165+
166+
# on_finish started working again in 8.14 (and 8.13.4+, and 8.12 and earlier)
167+
RSpec.describe Vips::SourceCustom, version: [8, 14] do
168+
it "can write an image to a user output stream" do
169+
image = Vips::Image.new_from_file simg("wagon.jpg")
170+
171+
filename = timg("x5.png")
172+
file = File.open filename, "wb"
173+
target = Vips::TargetCustom.new
174+
target.on_write { |chunk| file.write(chunk) }
175+
target.on_finish { file.close }
176+
image.write_to_target target, filename
177+
178+
image2 = Vips::Image.new_from_file filename
179+
expect(image2)
180+
expect(image2.width).to eq(685)
181+
expect(image2.height).to eq(478)
182+
expect(image2.bands).to eq(3)
183+
expect(image2.avg).to eq(image.avg)
159184
end
160185
end

0 commit comments

Comments
 (0)