Skip to content

Remove flag --no-dry-run for arduino-cli >= 0.14.0 #323

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Support for `dtostrf()`
- Added a CI workflow to lint the code base
- Added a CI workflow to check for spelling errors
- Remove `--dry-run` flag for `arduino-cli` version `>= 0.14.0`

### Changed
- We now compile a shared library to be used for each test.
Expand Down
17 changes: 16 additions & 1 deletion lib/arduino_ci/arduino_backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,12 @@ def compile_sketch(path, boardname)
@last_msg = "Can't compile Sketch at nonexistent path '#{path}'!"
return false
end
ret = run_and_capture("compile", "--fqbn", boardname, "--warnings", "all", "--dry-run", path.to_s)

ret = if should_use_dry_run?
run_and_capture("compile", "--fqbn", boardname, "--warnings", "all", "--dry-run", path.to_s)
else
run_and_capture("compile", "--fqbn", boardname, "--warnings", "all", path.to_s)
end
@last_msg = ret[:out]
ret[:success]
end
Expand Down Expand Up @@ -235,5 +240,15 @@ def install_local_library(path)
Host.symlink(src_path, destination_path)
cpp_library
end

private

# Since the dry-run behavior became default in arduino-cli 0.14, the command line flag was removed
# @return [Bool] whether the --dry-run flag is available for this arduino-cli version
def should_use_dry_run?
ret = capture_json("version")
version = ret[:json]["VersionString"]
Gem::Version.new(version) < Gem::Version.new('0.14')
end
end
end
43 changes: 43 additions & 0 deletions spec/arduino_backend_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,48 @@ def get_sketch(dir, file)
it "Passes a simple INO sketch at #{sketch_path_ino}" do
expect(backend.compile_sketch(sketch_path_ino, "arduino:avr:uno")).to be true
end

context "--dry-run flags" do
before { allow(backend).to receive(:run_and_capture).and_call_original }

it "Uses --dry-run flag for arduino-cli version < 0.14.0" do
parsed_stdout = JSON.parse('{ "VersionString": "0.13.6" }')
cli_version_output = {
json: parsed_stdout
}
allow(backend).to receive(:capture_json).and_return cli_version_output

backend.compile_sketch(sketch_path_ino, "arduino:avr:uno")

expect(backend).to have_received(:run_and_capture).with(
"compile",
"--fqbn",
"arduino:avr:uno",
"--warnings",
"all",
"--dry-run",
sketch_path_ino
)
end

it "Does not use --dry-run flag for arduino-cli version >= 0.14.0" do
parsed_stdout = JSON.parse('{ "VersionString": "0.14.0" }')
cli_version_output = {
json: parsed_stdout
}
allow(backend).to receive(:capture_json).and_return cli_version_output

backend.compile_sketch(sketch_path_ino, "arduino:avr:uno")

expect(backend).to have_received(:run_and_capture).with(
"compile",
"--fqbn",
"arduino:avr:uno",
"--warnings",
"all",
sketch_path_ino
)
end
end
end
end