Skip to content

Finish 2020 milestone #256

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

Merged
merged 14 commits into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
ArduinoBackend.library_available?() to check whether libraries exist
  • Loading branch information
ianfixes committed Jan 4, 2021
commit dc1d1b817fd245fd2aa6978d8e7c3f53a26ba72c
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- `shiftIn()` and `shiftOut()`
- `CIConfig.is_default` to detect when the default configuration is used
- `ArduinoBackend.boards_installed?` to detect whether a board family (or package, like `arduino:avr`) is installed
- `ArduinoBackend.library_available?` to detect whether the library manager knows of a library

### Changed
- Rubocop expected syntax downgraded from ruby 2.6 to 2.5
Expand Down
9 changes: 9 additions & 0 deletions lib/arduino_ci/arduino_backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,15 @@ def install_boards(boardfamily)
result[:success]
end

# Find out if a library is available
#
# @param name [String] the library name
# @return [bool] whether the library can be installed via the library manager
def library_available?(name)
# the --names flag limits the size of the response to just the name field
capture_json("lib", "search", "--names", name)[:json]["libraries"].any? { |l| l["name"] == name }
end

# @return [Hash] information about installed libraries via the CLI
def installed_libraries
capture_json("lib", "list")[:json]
Expand Down
7 changes: 7 additions & 0 deletions spec/arduino_backend_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ def get_sketch(dir, file)
expect(fake_lib.path).to eq(expected_dir)
expect(fake_lib.installed?).to be false
end

it "knows whether libraries exist in the manager" do
expect(backend.library_available?("OneWire")).to be true

# TODO: replace with a less offensive library name guaranteed never to exist?
expect(backend.library_available?("fuck")).to be false
end
end

context "board_manager" do
Expand Down