Skip to content

Commit 6be7333

Browse files
hf-4145ianfixes
authored andcommitted
Remove flag --no-dry-run for arduino-ci >= 0.14.0
1 parent d9b191c commit 6be7333

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

lib/arduino_ci/arduino_backend.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,12 @@ def compile_sketch(path, boardname)
201201
@last_msg = "Can't compile Sketch at nonexistent path '#{path}'!"
202202
return false
203203
end
204-
ret = run_and_capture("compile", "--fqbn", boardname, "--warnings", "all", path.to_s)
204+
use_dry_run = should_use_dry_run?
205+
if use_dry_run
206+
ret = run_and_capture("compile", "--fqbn", boardname, "--warnings", "all", "--dry-run", path.to_s)
207+
else
208+
ret = run_and_capture("compile", "--fqbn", boardname, "--warnings", "all", path.to_s)
209+
end
205210
@last_msg = ret[:out]
206211
ret[:success]
207212
end
@@ -289,5 +294,11 @@ def last_bytes_usage
289294

290295
Hash[mem_info.names.map(&:to_sym).zip(mem_info.captures.map(&:to_i))]
291296
end
297+
298+
def should_use_dry_run?
299+
ret = capture_json("version")
300+
version = ret[:json]["VersionString"]
301+
Gem::Version.new(version) < Gem::Version.new('0.14')
302+
end
292303
end
293304
end

spec/arduino_backend_spec.rb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,50 @@ def with_tmp_file(desired_filename = nil)
170170
expect(the_bytes[:max]).to eq 2048
171171
end
172172
end
173+
174+
context "--dry-run flags" do
175+
176+
sketch_path_ino = get_sketch("FakeSketch", "FakeSketch.ino")
177+
178+
before { allow(backend).to receive(:run_and_capture).and_call_original }
179+
180+
it "Uses --dry-run flag for arduino-cli version < 0.14.0" do
181+
parsed_stdout = JSON.parse('{ "VersionString": "0.13.6" }')
182+
cli_version_output = {
183+
json: parsed_stdout
184+
}
185+
allow(backend).to receive(:capture_json).and_return cli_version_output
186+
187+
backend.compile_sketch(sketch_path_ino, "arduino:avr:uno")
188+
189+
expect(backend).to have_received(:run_and_capture).with(
190+
"compile",
191+
"--fqbn",
192+
"arduino:avr:uno",
193+
"--warnings",
194+
"all",
195+
"--dry-run",
196+
sketch_path_ino.to_s
197+
)
198+
end
199+
200+
it "Does not use --dry-run flag for arduino-cli version >= 0.14.0" do
201+
parsed_stdout = JSON.parse('{ "VersionString": "0.14.0" }')
202+
cli_version_output = {
203+
json: parsed_stdout
204+
}
205+
allow(backend).to receive(:capture_json).and_return cli_version_output
206+
207+
backend.compile_sketch(sketch_path_ino, "arduino:avr:uno")
208+
209+
expect(backend).to have_received(:run_and_capture).with(
210+
"compile",
211+
"--fqbn",
212+
"arduino:avr:uno",
213+
"--warnings",
214+
"all",
215+
sketch_path_ino.to_s
216+
)
217+
end
218+
end
173219
end

0 commit comments

Comments
 (0)