Skip to content

Commit 1f2b7e5

Browse files
hf-4145ianfixes
authored andcommitted
Remove flag --no-dry-run for arduino-ci >= 0.14.0
1 parent 5fd4959 commit 1f2b7e5

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-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: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,47 @@ 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+
before { allow(backend).to receive(:run_and_capture).and_call_original }
176+
177+
it "Uses --dry-run flag for arduino-cli version < 0.14.0" do
178+
parsed_stdout = JSON.parse('{ "VersionString": "0.13.6" }')
179+
cli_version_output = {
180+
json: parsed_stdout
181+
}
182+
allow(backend).to receive(:capture_json).and_return cli_version_output
183+
184+
backend.compile_sketch(sketch_path_ino, "arduino:avr:uno")
185+
186+
expect(backend).to have_received(:run_and_capture).with(
187+
"compile",
188+
"--fqbn",
189+
"arduino:avr:uno",
190+
"--warnings",
191+
"all",
192+
"--dry-run",
193+
sketch_path_ino
194+
)
195+
end
196+
197+
it "Does not use --dry-run flag for arduino-cli version >= 0.14.0" do
198+
parsed_stdout = JSON.parse('{ "VersionString": "0.14.0" }')
199+
cli_version_output = {
200+
json: parsed_stdout
201+
}
202+
allow(backend).to receive(:capture_json).and_return cli_version_output
203+
204+
backend.compile_sketch(sketch_path_ino, "arduino:avr:uno")
205+
206+
expect(backend).to have_received(:run_and_capture).with(
207+
"compile",
208+
"--fqbn",
209+
"arduino:avr:uno",
210+
"--warnings",
211+
"all",
212+
sketch_path_ino
213+
)
214+
end
215+
end
173216
end

0 commit comments

Comments
 (0)