Skip to content

Commit 064a888

Browse files
committed
add ability to verify sketches
1 parent 32de3b4 commit 064a888

File tree

6 files changed

+50
-1
lines changed

6 files changed

+50
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1414
- `ArduinoCmd` installs boards
1515
- `ArduinoCmd` installs libraries
1616
- `ArduinoCmd` selects boards (compiler preference)
17+
- `ArduinoCmd` verifies sketches
1718

1819
### Changed
1920
- `DisplayManger.with_display` doesn't `disable` if the display was enabled prior to starting the block

exe/ci_system_check.rb

+6-1
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,13 @@
3737
got_problem = true unless arduino_cmd.set_pref("compiler.warning_level", "all")
3838
puts "use board! (install board)"
3939
got_problem = true unless arduino_cmd.use_board!("arduino:samd:zero")
40-
puts "verify that board has been installed"
40+
puts "assert that board has been installed"
4141
got_problem = true unless arduino_cmd.board_installed?("arduino:samd:zero")
4242

43+
simple_sketch = File.join(File.dirname(__FILE__), "spec", "FakeSketch", "FakeSketch.ino")
44+
45+
puts "verify a simple sketch"
46+
got_problem = true unless arduino_cmd.verify_sketch(simple_sketch)
47+
4348
abort if got_problem
4449
exit(0)

lib/arduino_ci/arduino_cmd.rb

+9
Original file line numberDiff line numberDiff line change
@@ -151,5 +151,14 @@ def use_board!(boardname)
151151
use_board(boardname)
152152
end
153153

154+
def verify_sketch(path)
155+
ext = File.extname path
156+
unless ext.casecmp(".ino").zero?
157+
puts "Refusing to verify sketch with '#{ext}' extension -- rename it to '.ino'!"
158+
return false
159+
end
160+
run("--verify", path, err: :out)
161+
end
162+
154163
end
155164
end

spec/BadSketch/BadSketch.ino

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Oh god how did this get in here I am not good with computer

spec/FakeSketch/FakeSketch.ino

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
void setup(void) { 0; }
2+
void loop(void) { 0; }

spec/arduino_cmd_spec.rb

+31
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
require "spec_helper"
22

3+
def get_sketch(dir, file)
4+
File.join(File.dirname(__FILE__), dir, file)
5+
end
6+
7+
38
RSpec.describe ArduinoCI::ArduinoCmd do
49
context "autolocate" do
510
it "Finds the Arduino executable" do
@@ -42,4 +47,30 @@
4247
expect(result).to be true
4348
end
4449
end
50+
51+
context "verify_sketch" do
52+
arduino_cmd = ArduinoCI::ArduinoCmd.autolocate!
53+
ArduinoCI::DisplayManager::instance.enable
54+
55+
sketch_path_ino = get_sketch("FakeSketch", "FakeSketch.ino")
56+
sketch_path_pde = get_sketch("FakeSketch", "FakeSketch.pde")
57+
sketch_path_mia = get_sketch("NO_FILE_HERE", "foo.ino")
58+
sketch_path_bad = get_sketch("BadSketch", "BadSketch.ino")
59+
60+
it "Passes a simple INO sketch at #{sketch_path_ino}" do
61+
expect(arduino_cmd.verify_sketch(sketch_path_ino)).to be true
62+
end
63+
64+
it "Rejects a PDE sketch at #{sketch_path_pde}" do
65+
expect(arduino_cmd.verify_sketch(sketch_path_pde)).to be false
66+
end
67+
68+
it "Fails a missing sketch at #{sketch_path_mia}" do
69+
expect(arduino_cmd.verify_sketch(sketch_path_mia)).to be false
70+
end
71+
72+
it "Fails a bad sketch at #{sketch_path_bad}" do
73+
expect(arduino_cmd.verify_sketch(sketch_path_bad)).to be false
74+
end
75+
end
4576
end

0 commit comments

Comments
 (0)