- Notifications
You must be signed in to change notification settings - Fork 34
/
Copy patharduino_backend_spec.rb
159 lines (128 loc) · 4.8 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
151
152
153
154
155
156
157
158
159
require"spec_helper"
defget_sketch(dir,file)
Pathname.new(__FILE__).parent + dir + file
end
RSpec.describeArduinoCI::ArduinoBackenddo
nextifskip_ruby_tests
backend=ArduinoCI::ArduinoInstallation.autolocate!
after(:each)do |example|
ifexample.exception
puts"Last message: #{backend.last_msg}"
puts"========== Stdout:"
putsbackend.last_out
puts"========== Stderr:"
putsbackend.last_err
end
end
context"initialize"do
it"sets base vars"do
expect(backend.binary_path).not_tobenil
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).tobetrue
expect(uno_installed).not_tobenil
end
it"Doesn't find bogus boards"do
bogus_installed=backend.board_installed?"eggs:milk:wheat"
expect(bogus_installed).tobefalse
expect(bogus_installed).not_tobenil
end
end
context"installation of boards"do
it"installs and sets boards"do
expect(backend.install_boards("arduino:sam")).tobetrue
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).toeq(expected_dir)
expect(fake_lib.installed?).tobefalse
end
it"knows whether libraries exist in the manager"do
expect(backend.library_available?("OneWire")).tobetrue
# TODO: replace with a less offensive library name guaranteed never to exist?
expect(backend.library_available?("fuck")).tobefalse
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.eachdo |urls|
backend.board_manager_urls=urls
expect(backend.board_manager_urls).tomatch_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")).tobefalse
end
it"Fails a missing sketch at #{sketch_path_mia}"do
expect(backend.compile_sketch(sketch_path_mia,"arduino:avr:uno")).tobefalse
end
it"Fails a bad sketch at #{sketch_path_bad}"do
expect(backend.compile_sketch(sketch_path_bad,"arduino:avr:uno")).tobefalse
end
it"Passes a simple INO sketch at #{sketch_path_ino}"do
expect(backend.compile_sketch(sketch_path_ino,"arduino:avr:uno")).tobetrue
end
it"Detects the bytes usage after compiling a sketch"do
expect(backend.compile_sketch(sketch_path_ino,"arduino:avr:uno")).tobetrue
the_bytes=backend.last_bytes_usage
expect(the_bytes[:globals]).toeq9
expect(the_bytes[:free]).toeq2039
expect(the_bytes[:max]).toeq2048
end
end
context"--dry-run flags"do
sketch_path_ino=get_sketch("FakeSketch","FakeSketch.ino")
before{allow(backend).toreceive(: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).toreceive(:capture_json).and_returncli_version_output
backend.compile_sketch(sketch_path_ino,"arduino:avr:uno")
expect(backend).tohave_received(:run_and_capture).with(
"compile",
"--fqbn",
"arduino:avr:uno",
"--warnings",
"all",
"--dry-run",
sketch_path_ino.to_s
)
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).toreceive(:capture_json).and_returncli_version_output
backend.compile_sketch(sketch_path_ino,"arduino:avr:uno")
expect(backend).tohave_received(:run_and_capture).with(
"compile",
"--fqbn",
"arduino:avr:uno",
"--warnings",
"all",
sketch_path_ino.to_s
)
end
end
end