forked from Arduino-CI/arduino_ci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharduino_backend_spec.rb
150 lines (121 loc) · 4.5 KB
/
arduino_backend_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
require "spec_helper"
require 'pathname'
def get_sketch(dir, file)
File.join(File.dirname(__FILE__), dir, file)
end
RSpec.describe ArduinoCI::ArduinoBackend do
next if skip_ruby_tests
backend = ArduinoCI::ArduinoInstallation.autolocate!
after(:each) do |example|
if example.exception
puts "Last message: #{backend.last_msg}"
puts "========== Stdout:"
puts backend.last_out
puts "========== Stderr:"
puts backend.last_err
end
end
context "initialize" do
it "sets base vars" do
expect(backend.binary_path).not_to be nil
end
end
context "board_installed?" do
it "Finds installed boards" do
backend.install_boards("arduino:avr") # we used to assume this was installed... not the case for arduino-cli
uno_installed = backend.board_installed? "arduino:avr:uno"
expect(uno_installed).to be true
expect(uno_installed).not_to be nil
end
it "Doesn't find bogus boards" do
bogus_installed = backend.board_installed? "eggs:milk:wheat"
expect(bogus_installed).to be false
expect(bogus_installed).not_to be nil
end
end
context "installation of boards" do
it "installs and sets boards" do
expect(backend.install_boards("arduino:sam")).to be true
end
end
context "libraries" do
it "knows where to find libraries" do
fake_lib_name = "_____nope"
expected_dir = Pathname.new(backend.lib_dir) + fake_lib_name
fake_lib = backend.library_of_name(fake_lib_name)
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
it "Reads and writes board_manager URLs" do
fake_urls = ["http://foo.bar", "http://arduino.ci"]
existing_urls = backend.board_manager_urls
# try to ensure maximum variability in the test
test_url_sets = (existing_urls.empty? ? [fake_urls, []] : [[], fake_urls]) + [existing_urls]
test_url_sets.each do |urls|
backend.board_manager_urls = urls
expect(backend.board_manager_urls).to match_array(urls)
end
end
end
context "compile_sketch" do
sketch_path_ino = get_sketch("FakeSketch", "FakeSketch.ino")
sketch_path_pde = get_sketch("FakeSketch", "FakeSketch.pde")
sketch_path_mia = get_sketch("NO_FILE_HERE", "foo.ino")
sketch_path_bad = get_sketch("BadSketch", "BadSketch.ino")
it "Rejects a PDE sketch at #{sketch_path_pde}" do
expect(backend.compile_sketch(sketch_path_pde, "arduino:avr:uno")).to be false
end
it "Fails a missing sketch at #{sketch_path_mia}" do
expect(backend.compile_sketch(sketch_path_mia, "arduino:avr:uno")).to be false
end
it "Fails a bad sketch at #{sketch_path_bad}" do
expect(backend.compile_sketch(sketch_path_bad, "arduino:avr:uno")).to be false
end
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