arduino_ci 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0c01ddca13fd4bd941dcff9e9faeeae700f184bbf647876d520c7ccfce0c87b3
4
+ data.tar.gz: 974ce43ef7eba01113b9470750c78ad4cc5f81f0296f72f18ce43def9ad1c597
5
+ SHA512:
6
+ metadata.gz: a044d9ab06badda8a648f189786c14209d7bee59d4ba299dc8790bd29e54adfd107f15a53fcb28d7ad7f286c6daf3e559f6a09b15b3f625c5344c400b0a4c5e8
7
+ data.tar.gz: f134b211ce71483ee88794a8a9d9f742deed82ee3d93ccecbbdd745ff53af12d6b44f71e2480c7ea98ce60d62bb28f0553c22b773bd6376ea7854bae29f19c9c
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ lib/arduino_ci.rb lib/**/*.rb
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ [![Gem Version](https://badge.fury.io/rb/arduino_ci.svg)](https://rubygems.org/gems/arduino_ci)
2
+ [![Build Status](https://travis-ci.org/ifreecarve/arduino_ci.svg)](https://travis-ci.org/ifreecarve/arduino_ci)
3
+ [![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](http://www.rubydoc.info/gems/arduino_ci/)
4
+
5
+ # ArduinoCI Ruby gem (`arduino_ci`)
6
+
7
+ [Arduino CI](https://github.com/ifreecarve/arduino_ci) is a Ruby gem for executing Continuous Integration (CI) tests on an Arduino library -- both locally and as part of a service like Travis CI.
8
+
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'arduino_ci'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install arduino_ci
25
+
26
+
27
+ ## Usage
28
+
29
+ TODO: Write usage instructions here, based on other TODO of writing the actual gem.
30
+
31
+
32
+ ## Author
33
+
34
+ This gem was written by Ian Katz (ifreecarve@gmail.com) in 2018. It's released under the Apache 2.0 license.
35
+
36
+
37
+ ## See Also
38
+
39
+ * [Contributing](CONTRIBUTING.md)
data/lib/arduino_ci.rb ADDED
@@ -0,0 +1,124 @@
1
+ require "arduino_ci/version"
2
+
3
+ require 'singleton'
4
+
5
+ # Cross-platform way of finding an executable in the $PATH.
6
+ # via https://stackoverflow.com/a/5471032/2063546
7
+ # which('ruby') #=> /usr/bin/ruby
8
+ def which(cmd)
9
+ exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
10
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
11
+ exts.each do |ext|
12
+ exe = File.join(path, "#{cmd}#{ext}")
13
+ return exe if File.executable?(exe) && !File.directory?(exe)
14
+ end
15
+ end
16
+ nil
17
+ end
18
+
19
+ # ArduinoCI contains classes for automated testing of Arduino code on the command line
20
+ # @author Ian Katz <ifreecarve@gmail.com>
21
+ module ArduinoCI
22
+
23
+ # Wrap the Arduino executable. This requires, in some cases, a faked display.
24
+ class ArduinoCmd
25
+
26
+ # create as many ArduinoCmds as you like, but we need one and only one display manager
27
+ class DisplayMgr
28
+ include Singleton
29
+ attr_reader :enabled
30
+
31
+ def initialize
32
+ @existing = existing_display?
33
+ @enabled = false
34
+ @pid = nil
35
+ end
36
+
37
+ # attempt to determine if the machine is running a graphical display (i.e. not Travis)
38
+ def existing_display?
39
+ return true if RUBY_PLATFORM.include? "darwin"
40
+ return true if ENV["DISPLAY"].nil?
41
+ return true if ENV["DISPLAY"].include? ":"
42
+ false
43
+ end
44
+
45
+ # enable a virtual display
46
+ def enable
47
+ return @enabled = true if @existing # silent no-op if built in display
48
+ return unless @pid.nil?
49
+
50
+ @enabled = true
51
+ @pid = fork do
52
+ puts "Forking Xvfb"
53
+ system("Xvfb", ":1", "-ac", "-screen", "0", "1280x1024x16")
54
+ puts "Xvfb unexpectedly quit!"
55
+ end
56
+ sleep(3) # TODO: test a connection to the X server?
57
+ end
58
+
59
+ # disable the virtual display
60
+ def disable
61
+ return @enabled = false if @existing # silent no-op if built in display
62
+ return if @pid.nil?
63
+
64
+ begin
65
+ Process.kill 9, @pid
66
+ ensure
67
+ Process.wait @pid
68
+ @pid = nil
69
+ end
70
+ puts "Xvfb killed"
71
+ end
72
+
73
+ # Enable a virtual display for the duration of the given block
74
+ def with_display
75
+ enable
76
+ begin
77
+ yield environment
78
+ ensure
79
+ disable
80
+ end
81
+ end
82
+
83
+ def environment
84
+ return nil unless @existing || @enabled
85
+ return {} if @existing
86
+ { DISPLAY => ":1.0" }
87
+ end
88
+
89
+ # On finalize, ensure child process is ended
90
+ def self.finalize
91
+ disable
92
+ end
93
+ end
94
+
95
+ class << self
96
+ protected :new
97
+
98
+ # attempt to find a workable Arduino executable across platforms
99
+ def guess_executable_location
100
+ osx_place = "/Applications/Arduino.app/Contents/MacOS/Arduino"
101
+ places = {
102
+ "arduino" => !which("arduino").nil?,
103
+ osx_place => (File.exist? osx_place),
104
+ }
105
+ places.each { |k, v| return k if v }
106
+ nil
107
+ end
108
+
109
+ def autolocate
110
+ ret = new
111
+ ret.path = guess_executable_location
112
+ ret
113
+ end
114
+ end
115
+
116
+ attr_accessor :path
117
+
118
+ def initialize
119
+ @display_mgr = DisplayMgr::instance
120
+ end
121
+
122
+ end
123
+
124
+ end
@@ -0,0 +1,3 @@
1
+ module ArduinoCI
2
+ VERSION = "0.0.1".freeze
3
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: arduino_ci
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ian Katz
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-01-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 0.46.0
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 0.46.0
61
+ - !ruby/object:Gem::Dependency
62
+ name: yard
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '0.8'
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0.8'
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: '0.8'
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0.8'
81
+ description: ''
82
+ email:
83
+ - ifreecarve@gmail.com
84
+ executables: []
85
+ extensions: []
86
+ extra_rdoc_files: []
87
+ files:
88
+ - ".yardopts"
89
+ - README.md
90
+ - lib/arduino_ci.rb
91
+ - lib/arduino_ci/version.rb
92
+ homepage: http://github.com/ifreecarve/arduino_ci
93
+ licenses:
94
+ - Apache-2.0
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.7.4
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Tools for building and unit testing Arduino libraries
116
+ test_files: []