Skip to content

Commit 8b26d2a

Browse files
committed
suppress arduino output
1 parent a4f3ce3 commit 8b26d2a

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

lib/arduino_ci/arduino_cmd.rb

+11-7
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ def prefs
5858
# @param value [String] the preference value
5959
# @return [bool] whether the command succeeded
6060
def set_pref(key, value)
61-
success = run_with_gui_guess(" about preferences", "--pref", "#{key}=#{value}", "--save-prefs")
61+
resp = run_and_capture(" about preferences", "--pref", "#{key}=#{value}", "--save-prefs")
62+
success = resp[:success]
6263
@prefs_cache[key] = value if success
6364
success
6465
end
6566

6667
# run the arduino command
67-
# @return [Hash] {:out => StringIO, :err => StringIO }
6868
def run(*args, **kwargs)
6969
full_args = [@installation.cmd_path] + args
7070
@display_mgr.run(*full_args, **kwargs)
@@ -75,7 +75,8 @@ def run_with_gui_guess(message, *args, **kwargs)
7575
# so, assume that if we don't get a rapid reply that things are not installed
7676
x3 = @prefs_response_time * 3
7777
Timeout.timeout(x3) do
78-
run(*args, **kwargs)
78+
result = run_and_capture(*args, **kwargs)
79+
result[:success]
7980
end
8081
rescue Timeout::Error
8182
puts "No response in #{x3} seconds. Assuming graphical modal error message#{message}."
@@ -97,6 +98,9 @@ def run_and_capture(*args)
9798
{ out: str_out, err: str_err, success: success }
9899
end
99100

101+
# check whether a board is installed
102+
# we do this by just selecting a board.
103+
# the arduino binary will error if unrecognized and do a successful no-op if it's installed
100104
def board_installed?(boardname)
101105
run_with_gui_guess(" about board not installed", "--board", boardname)
102106
end
@@ -105,16 +109,16 @@ def board_installed?(boardname)
105109
# @param name [String] the board name
106110
# @return [bool] whether the command succeeded
107111
def install_board(boardname)
108-
run("--install-boards", boardname)
112+
run_and_capture("--install-boards", boardname)[:success]
109113
end
110114

111115
# install a library by name
112116
# @param name [String] the library name
113117
# @return [bool] whether the command succeeded
114118
def install_library(library_name)
115-
result = run("--install-library", library_name)
116-
@library_is_indexed = true if result
117-
result
119+
result = run_and_capture("--install-library", library_name)
120+
@library_is_indexed = true if result[:success]
121+
result[:success]
118122
end
119123

120124
# update the library index

spec/arduino_cmd_spec.rb

+6-2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,15 @@
2020
arduino_cmd = ArduinoCI::ArduinoCmd.autolocate!
2121
ArduinoCI::DisplayManager::instance.enable
2222
it "Finds installed boards" do
23-
expect(arduino_cmd.board_installed? "arduino:avr:uno").to be true
23+
uno_installed = arduino_cmd.board_installed? "arduino:avr:uno"
24+
expect(uno_installed).to be true
25+
expect(uno_installed).not_to be nil
2426
end
2527

2628
it "Doesn't find bogus boards" do
27-
expect(arduino_cmd.board_installed? "eggs:milk:wheat").to be false
29+
bogus_installed = arduino_cmd.board_installed? "eggs:milk:wheat"
30+
expect(bogus_installed).to be false
31+
expect(bogus_installed).not_to be nil
2832
end
2933
end
3034

0 commit comments

Comments
 (0)