thermite 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1fdbea9d416375c6831c8dc80d9966cb6cf20eea
4
- data.tar.gz: a2029b606d18db0b23dc9a3c34f894af351d3d75
3
+ metadata.gz: 4298855469a6d6a12e9dd7d33df5a95cfe8b4c9f
4
+ data.tar.gz: e793be7663705a076bdcfb81bc4157d4ba10466b
5
5
  SHA512:
6
- metadata.gz: e3a6cd74b197901582b2e04ef4a99eabea6b9a636712fcaee488c402f7f6e46a6f89043af8ab9d54e2c75b112686750d347af2688a606079848df2d31dee5b06
7
- data.tar.gz: ec981b8bc75da63d8deedf273d2c4df8bc18c69dc027ef681eb478ee75c8982185168976ef97c97f3fdb72279be4a93ea9c0f2457c8ec5f780e56db2fe3933e8
6
+ metadata.gz: d6fe53f8a54d8617d1578cf71619687734d447bd42ec2a37fdde84bc1b2eaf17045232f30d71fc5f47d9ece3ebab95dbfc79ddae22407421ed43e267c7a93832
7
+ data.tar.gz: 8475eaa3cfc6a52aaaf2fef3eb514a79f8a02f56e2c95ba6f3c7f8f8d6f8a557a43837c8cd0b34c41800eeb102a342631d86513ef48f3c332ac4ceb9f229ea43
data/.appveyor.yml ADDED
@@ -0,0 +1,27 @@
1
+ platform:
2
+ - x86
3
+ - x64
4
+ environment:
5
+ matrix:
6
+ - RUBY_VERSION: 21
7
+ - RUBY_VERSION: 22
8
+ - RUBY_VERSION: 23
9
+ cache:
10
+ - vendor\bundle
11
+ install:
12
+ - ps: |
13
+ if ($env:platform -eq 'x86') {
14
+ $env:WIN_RUBY_BIN = "C:\Ruby${env:RUBY_VERSION}\bin";
15
+ } else {
16
+ $env:WIN_RUBY_BIN = "C:\Ruby${env:RUBY_VERSION}-x64\bin";
17
+ }
18
+ $env:PATH = "${env:WIN_RUBY_BIN};${env:PATH}";
19
+ - ruby --version
20
+ - gem --version
21
+ - rake --version
22
+ - bundle --version
23
+ - bundle config --local path vendor/bundle
24
+ - bundle install
25
+ build: false
26
+ test_script:
27
+ - bundle exec rake
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  *.gem
2
+ .yardoc
2
3
  Gemfile.lock
4
+ coverage
3
5
  doc
4
- html
data/.rubocop.yml CHANGED
@@ -1,6 +1,10 @@
1
1
  Metrics/AbcSize:
2
2
  Max: 20
3
3
 
4
+ Metrics/ClassLength:
5
+ Exclude:
6
+ - 'test/**/*'
7
+
4
8
  Metrics/LineLength:
5
9
  Max: 100
6
10
  AllowURI: true
data/.travis.yml CHANGED
@@ -1,4 +1,8 @@
1
1
  language: ruby
2
+ os:
3
+ - linux
4
+ - osx
5
+ osx_image: xcode8
2
6
  rvm:
3
7
  - 2.1.10
4
8
  - 2.2.5
@@ -11,3 +15,5 @@ env:
11
15
  - secure: Ia4faKtCVBGN6z5jFrnBsCJX/Hg3Hs+pGll+lczDE+UFM0Io7LT/upQdre5JUftM0IiynwCw/XS4dz6h/ZZWS28pSFm12NvHHmO22NAaX/xQjKvBhWz8OblnNjybPNSdt0bBa4XnssW7SiPSH5moO3PEnRfbaVrAppHWw+VL0449RnFwu33J9663Gvsf48cE9f3ZeX/NUowqe9Gr3Y1edKsE5btK2vgW+VrwCCbf3PIF60SveClcivB823IrjHsBN76n8C6/Hx6zngZXYN8GfBN5c9JGMP9UP0fSE81jqmDo2poX1MdVch3kf3ylllOrOP/Z5hzZ3aYv+sOTDR68si+sLx1mlrY8ImX6sK/uDbGx0CYOGvmZO9OqREOBEBLg98KQAOsdxIXe2CTfUSQbj7pVppba72tTVqPrM8mroEIl+Dk6rPB5x0makMj1xQ8UyyyCgsiEcfkRrUjefPBIw5aczxXGoqg+SEnRdqQu94z5V0UeGtbZ2BqBuP6E/XINr90nm9fmpI2nDgMde8MCjPfHz8nbXM/l/1nkQ4l7d0Dob+vUZtTwr4CBW1oWp4w46Iv0mBSr5js0b7fhh95rMN1/CYZaaNsraXnqACsP70WRMBuHSDZ6mk4DQG0D7BjIckt/GplUoo3I7Z5tPjBgejk+VhoLdQGAu9CGutSGkTk=
12
16
  # APPVEYOR_TOKEN
13
17
  - secure: Qvw49LusnruOfYYL0SpcV3PhK1Fm15y9wtZK+YEscvkNw6LZ+xziD+1+f2nuR+zQkHmG/izqpA+NMoGqJvB8JsI+8N6S7YORJJ5e/TVjVq7voQXohNRMldUPn38IIVfBSR8Wzmqw7t+g7Eg6WWnbiRHO7RGlHuGwLeG4Cgl9gPNYt9gZpuditAIk/jmuOaTMbp4gRB02CERIMInrH8+52fcAWJCTQzLecD116c33xa3LUCC1hS49Wu6ku0O8OsuOAcpWTUuxAhScdCSYf8iy7WP83mNkbuIPN8OsOz6wS0pO1cJ5opdIvDWNPnYinhVOXbyP1FEXj5GtlDzt+5eIslp3BBAf90czc/TpYQS+9HBXZTD81l0xslneC/eAc0/bPlF98qLdhPByAZpjJFHM1tiijFVyIzqHLNXL4c2NUcOZONquCwKkroyL/Ze2w7pwttP8hC5TUEoRexMgE3ULAPKITKSmkrq2UxRdRB4Ln6uXaK5zfxLfJOgwqmcD7W/34pfQ/X+f/wymEYG2FwORewGVH//UtYklN6J8ivQDmJ1eyECSJmfHWgKWX729pfAuKLkc+iVOvZZ736plcN2GbmznyplevhjScaBpZHzjF1Iz/A7JEJHYoQIdecn67iIY2p5ULKklBJP8vqrI24YqtNl4Ly/8/kRn0DjyPVauQ1o=
18
+ # CODECLIMATE_REPO_TOKEN
19
+ - secure: qILkdIw4zV2tqtt5JikSMSsUW4GhNrvGoIITGFS0YBAsQFOS3UuQ4Kg4RisZ8N5H+orfyg06EqGw/Csq9M4Ndf08DHUmXcQK5R/aOKuIOwsJvQ8sk2SEtmJU/4D6Ku2oK78DuBiXvu8z4UZm4dNkFuU4HFc6Lzn0ny5Yu92UOQg7/OBGWm4VaX9QeK/ohgJwyTUUJVlVQAcvtg8TXU3uKE6C9mP7D1kPJGuCflBfHFRXnTsJrHQms1cv+NQeMppv5WYNFdMlMIFwg+B+1lKZ6HYLWdsqw0lv27eBVqzKcyZSl6tFC/2B7RTT430MfXbbA/5hbXobv7cZYOuv0FSh8ms/eQIX4VO0Tx6yLT0gknm21tIs/ZKHuYVZ6jqFD87AVVof0iyD4VhBnxuYluMsETZGlmBN1uj12WBZIlcwZVId+SC6erGKLRFqLahBzAtNy2UrPosrXMWdKG4oHkCNDTSX6ZDm4qZu/DV10Gv1gITN+YSXNCYX27hW+JFjsarvaEQfQ22LMyfbQ79qMVgt0mKOCzs/o1XxrCyyQq/xHYCOH1aZRILFZJoVwb0t4Wo/gT1Xzro4O1RYq7OMRamjLw/8tRrSjDQoLhGUwvR1TQCafPcvLNrHdNRn9DqBCJeuYjE+yvTNpk8B7GqRtvmMe2z9Fb7waiSFWTJfuGeXwKI=
data/Gemfile CHANGED
@@ -3,4 +3,9 @@
3
3
 
4
4
  source 'https://rubygems.org'
5
5
 
6
+ group :test do
7
+ gem 'codeclimate-test-reporter', require: nil
8
+ gem 'simplecov', require: nil
9
+ end
10
+
6
11
  gemspec
data/NEWS.md CHANGED
@@ -2,6 +2,24 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## [0.5.0] - 2016-07-18
6
+
7
+ ### Added
8
+
9
+ * Unit tests and code coverage (including new development dependencies)
10
+ * CI support on OSX and Windows in addition to Linux
11
+ * Successful CI builds on Linux trigger rusty_blank CI builds on Linux/OSX/Windows
12
+
13
+ ### Changed
14
+
15
+ * Documentation uses YARD instead of RDoc
16
+ * `unpack_tarball` is a public method
17
+
18
+ ### Fixed
19
+
20
+ * Documentation for `debug`
21
+ * Windows platform support
22
+
5
23
  ## [0.4.0] - 2016-07-12
6
24
 
7
25
  ### Added
@@ -49,6 +67,7 @@
49
67
 
50
68
  Initial release.
51
69
 
70
+ [0.5.0]: https://github.com/malept/thermite/compare/v0.4.0...v0.5.0
52
71
  [0.4.0]: https://github.com/malept/thermite/compare/v0.3.0...v0.4.0
53
72
  [0.3.0]: https://github.com/malept/thermite/compare/v0.2.0...v0.3.0
54
73
  [0.2.0]: https://github.com/malept/thermite/compare/v0.1.0...v0.2.0
data/README.md CHANGED
@@ -1,8 +1,11 @@
1
1
  # Thermite
2
2
 
3
- [![Build Status](https://travis-ci.org/malept/thermite.svg?branch=master)](https://travis-ci.org/malept/thermite)
3
+ [![Linux/OSX build status](https://travis-ci.org/malept/thermite.svg?branch=master)](https://travis-ci.org/malept/thermite)
4
+ [![Windows build status](https://ci.appveyor.com/api/projects/status/kneo890m3ypoxril?svg=true)](https://ci.appveyor.com/project/malept/thermite)
5
+ [![Code Climate](https://codeclimate.com/github/malept/thermite/badges/gpa.svg)](https://codeclimate.com/github/malept/thermite)
6
+ [![Test coverage](https://codeclimate.com/github/malept/thermite/badges/coverage.svg)](https://codeclimate.com/github/malept/thermite/coverage)
4
7
  [![Inline docs](http://inch-ci.org/github/malept/thermite.svg?branch=master)](http://inch-ci.org/github/malept/thermite)
5
- [![Gem](https://img.shields.io/gem/v/thermite.svg?maxAge=300000)](https://rubygems.org/gems/thermite)
8
+ [![Gem](https://img.shields.io/gem/v/thermite.svg?maxAge=30000)](https://rubygems.org/gems/thermite)
6
9
 
7
10
  Thermite is a Rake-based helper for building and distributing Rust-based Ruby extensions.
8
11
 
data/Rakefile CHANGED
@@ -19,10 +19,15 @@
19
19
  # OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
20
 
21
21
  require 'bundler/gem_tasks'
22
- require 'rdoc/task'
22
+ require 'rake/testtask'
23
23
  require 'rubocop/rake_task'
24
+ require 'yard'
24
25
 
25
- RDoc::Task.new
26
+ Rake::TestTask.new do |t|
27
+ t.libs << 'test'
28
+ t.test_files = FileList['test/**/*_test.rb']
29
+ end
30
+ YARD::Rake::YardocTask.new
26
31
  RuboCop::RakeTask.new
27
32
 
28
- task default: %w(rubocop rdoc)
33
+ task default: %w(rubocop yard test)
data/ci/after_success.py CHANGED
@@ -48,6 +48,7 @@ def trigger_travis_build():
48
48
  print(http.getresponse().read())
49
49
 
50
50
  if __name__ == '__main__':
51
- if os.environ['TRAVIS_RUBY_VERSION'].startswith('2.3.'):
51
+ if (os.environ['TRAVIS_OS_NAME'] == 'linux' and
52
+ os.environ['TRAVIS_RUBY_VERSION'].startswith('2.3.')):
52
53
  trigger_appveyor_build()
53
54
  trigger_travis_build()
@@ -56,6 +56,8 @@ module Thermite
56
56
  run_cargo(*cargo_args)
57
57
  end
58
58
 
59
+ # :nocov:
60
+
59
61
  #
60
62
  # Message used when cargo is required but not found.
61
63
  #
@@ -48,12 +48,12 @@ module Thermite
48
48
  #
49
49
  def shared_ext
50
50
  @shared_ext ||= begin
51
- if RbConfig::CONFIG['DLEXT'] == 'bundle'
51
+ if dlext == 'bundle'
52
52
  'dylib'
53
53
  elsif Gem.win_platform?
54
54
  'dll'
55
55
  else
56
- RbConfig::CONFIG['DLEXT']
56
+ dlext
57
57
  end
58
58
  end
59
59
  end
@@ -63,11 +63,13 @@ module Thermite
63
63
  #
64
64
  def ruby_version
65
65
  @ruby_version ||= begin
66
- version_info = RbConfig::CONFIG['ruby_version'].split('.')
66
+ version_info = rbconfig_ruby_version.split('.')
67
67
  "ruby#{version_info[0]}#{version_info[1]}"
68
68
  end
69
69
  end
70
70
 
71
+ # :nocov:
72
+
71
73
  #
72
74
  # Alias for `RbConfig::CONFIG['target_cpu']`.
73
75
  #
@@ -81,6 +83,7 @@ module Thermite
81
83
  def target_os
82
84
  @target_os ||= RbConfig::CONFIG['target_os']
83
85
  end
86
+ # :nocov:
84
87
 
85
88
  #
86
89
  # The name of the library compiled by Rust.
@@ -191,5 +194,17 @@ module Thermite
191
194
  end
192
195
  end
193
196
  end
197
+
198
+ private
199
+
200
+ # :nocov:
201
+
202
+ def dlext
203
+ RbConfig::CONFIG['DLEXT']
204
+ end
205
+
206
+ def rbconfig_ruby_version
207
+ RbConfig::CONFIG['ruby_version']
208
+ end
194
209
  end
195
210
  end
@@ -20,9 +20,7 @@
20
20
 
21
21
  require 'net/http'
22
22
  require 'rexml/document'
23
- require 'rubygems/package'
24
23
  require 'uri'
25
- require 'zlib'
26
24
 
27
25
  module Thermite
28
26
  #
@@ -92,9 +90,11 @@ module Thermite
92
90
  "#{github_uri}/releases/download/#{tag}/#{config.tarball_filename(version)}"
93
91
  end
94
92
 
93
+ # :nocov:
95
94
  def http_get(uri)
96
95
  Net::HTTP.get(URI(uri))
97
96
  end
97
+ # :nocov:
98
98
 
99
99
  def each_github_release(github_uri)
100
100
  releases_uri = "#{github_uri}/releases.atom"
@@ -113,23 +113,14 @@ module Thermite
113
113
  when Net::HTTPClientError
114
114
  nil
115
115
  when Net::HTTPServerError
116
- raise response
116
+ raise Net::HTTPServerException.new(response.message, response)
117
117
  else
118
- puts "Downloading latest compiled version (#{version}) from GitHub"
119
- StringIO.new(http_get(response['location']))
120
- end
121
- end
122
-
123
- def unpack_tarball(tgz)
124
- gz = Zlib::GzipReader.new(tgz)
125
- tar = Gem::Package::TarReader.new(gz)
126
- tar.each do |entry|
127
- path = entry.header.name
128
- next if path.end_with?('/')
129
- debug "Unpacking file: #{path}"
130
- File.open(path, 'wb') do |f|
131
- f.write(entry.read)
118
+ unless ENV.key?('THERMITE_TEST')
119
+ # :nocov:
120
+ puts "Downloading latest compiled version (#{version}) from GitHub"
121
+ # :nocov:
132
122
  end
123
+ StringIO.new(http_get(response['location']))
133
124
  end
134
125
  end
135
126
  end
@@ -19,6 +19,7 @@
19
19
  # OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
20
 
21
21
  require 'archive/tar/minitar'
22
+ require 'rubygems/package'
22
23
  require 'zlib'
23
24
 
24
25
  module Thermite
@@ -31,10 +32,30 @@ module Thermite
31
32
  #
32
33
  def build_package
33
34
  filename = config.tarball_filename(config.toml[:package][:version])
34
- tgz = Zlib::GzipWriter.new(File.open(filename, 'wb'))
35
35
  relative_library_path = config.ruby_extension_path.sub("#{config.ruby_toplevel_dir}/", '')
36
- Dir.chdir(config.ruby_toplevel_dir) do
37
- Archive::Tar::Minitar.pack(relative_library_path, tgz)
36
+ Zlib::GzipWriter.open(filename) do |tgz|
37
+ Dir.chdir(config.ruby_toplevel_dir) do
38
+ Archive::Tar::Minitar.pack(relative_library_path, tgz)
39
+ end
40
+ end
41
+ end
42
+
43
+ #
44
+ # Unpack a gzipped tarball stream (specified by `tgz`) into the current
45
+ # working directory.
46
+ #
47
+ def unpack_tarball(tgz)
48
+ Zlib::GzipReader.wrap(tgz) do |gz|
49
+ Gem::Package::TarReader.new(gz) do |tar|
50
+ tar.each do |entry|
51
+ path = entry.header.name
52
+ next if path.end_with?('/')
53
+ debug "Unpacking file: #{path}"
54
+ File.open(path, 'wb') do |f|
55
+ f.write(entry.read)
56
+ end
57
+ end
58
+ end
38
59
  end
39
60
  end
40
61
  end
data/lib/thermite/util.rb CHANGED
@@ -23,6 +23,9 @@ module Thermite
23
23
  # Utility methods
24
24
  #
25
25
  module Util
26
+ #
27
+ # Logs a debug message to the specified `config.debug_filename`, if set.
28
+ #
26
29
  def debug(msg)
27
30
  # Should probably replace with a Logger
28
31
  if config.debug_filename
@@ -0,0 +1,5 @@
1
+ [package]
2
+ name = "fixture"
3
+
4
+ [package.metadata.thermite]
5
+ github_releases = true
@@ -0,0 +1,30 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xml:lang="en-US">
3
+ <id>tag:github.com,2008:https://github.com/ghost/project/releases</id>
4
+ <link type="text/html" rel="alternate" href="https://github.com/ghost/project/releases"/>
5
+ <link type="application/atom+xml" rel="self" href="https://github.com/ghost/project/releases.atom"/>
6
+ <title>Release notes from project</title>
7
+ <updated>2016-07-10T01:57:28Z</updated>
8
+ <entry>
9
+ <id>tag:github.com,2008:Repository/12345678/v0.1.12-rust</id>
10
+ <updated>2016-07-10T01:59:24Z</updated>
11
+ <link rel="alternate" type="text/html" href="/ghost/project/releases/tag/v0.1.12-rust"/>
12
+ <title>v0.1.12-rust</title>
13
+ <content>No content.</content>
14
+ <author>
15
+ <name>ghost</name>
16
+ </author>
17
+ <media:thumbnail height="30" width="30" url="about:blank"/>
18
+ </entry>
19
+ <entry>
20
+ <id>tag:github.com,2008:Repository/12345678/v0.1.11-rust</id>
21
+ <updated>2016-07-09T22:47:09Z</updated>
22
+ <link rel="alternate" type="text/html" href="/ghost/project/releases/tag/v0.1.11-rust"/>
23
+ <title>v0.1.11-rust</title>
24
+ <content>No content.</content>
25
+ <author>
26
+ <name>ghost</name>
27
+ </author>
28
+ <media:thumbnail height="30" width="30" url="about:blank"/>
29
+ </entry>
30
+ </feed>
@@ -0,0 +1,39 @@
1
+ require 'test_helper'
2
+ require 'thermite/cargo'
3
+
4
+ module Thermite
5
+ class CargoTest < Minitest::Test
6
+ include Thermite::ModuleTester
7
+
8
+ class Tester
9
+ include Thermite::Cargo
10
+ include Thermite::TestHelper
11
+ end
12
+
13
+ def test_run_cargo_if_exists
14
+ mock_module.stubs(:find_executable).returns('/opt/cargo-test/bin/cargo')
15
+ mock_module.expects(:sh).with('/opt/cargo-test/bin/cargo foo bar').once
16
+ mock_module.run_cargo_if_exists('foo', 'bar')
17
+ end
18
+
19
+ def test_run_cargo_if_exists_sans_cargo
20
+ mock_module.stubs(:find_executable).returns(nil)
21
+ mock_module.expects(:sh).never
22
+ mock_module.run_cargo_if_exists('foo', 'bar')
23
+ end
24
+
25
+ def test_run_cargo_debug_build
26
+ mock_module.expects(:run_cargo).with('build').once
27
+ mock_module.run_cargo_build('debug')
28
+ end
29
+
30
+ def test_run_cargo_release_build
31
+ mock_module.expects(:run_cargo).with('build', '--release').once
32
+ mock_module.run_cargo_build('release')
33
+ end
34
+
35
+ def described_class
36
+ Tester
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,144 @@
1
+ require 'test_helper'
2
+
3
+ module Thermite
4
+ class ConfigTest < Minitest::Test
5
+ def test_debug_filename
6
+ assert_nil described_class.new.debug_filename
7
+ ENV['THERMITE_DEBUG_FILENAME'] = 'foo'
8
+ assert_equal 'foo', described_class.new.debug_filename
9
+ ENV['THERMITE_DEBUG_FILENAME'] = nil
10
+ end
11
+
12
+ def test_shared_ext_osx
13
+ config.stubs(:dlext).returns('bundle')
14
+ assert_equal 'dylib', config.shared_ext
15
+ end
16
+
17
+ def test_shared_ext_windows
18
+ config.stubs(:dlext).returns('so')
19
+ Gem.stubs(:win_platform?).returns(true)
20
+ assert_equal 'dll', config.shared_ext
21
+ end
22
+
23
+ def test_shared_ext_unix
24
+ config.stubs(:dlext).returns('foobar')
25
+ Gem.stubs(:win_platform?).returns(false)
26
+ assert_equal 'foobar', config.shared_ext
27
+ end
28
+
29
+ def test_ruby_version
30
+ config.stubs(:rbconfig_ruby_version).returns('3.2.0')
31
+ assert_equal 'ruby32', config.ruby_version
32
+ end
33
+
34
+ def test_library_name_from_cargo_lib
35
+ config.stubs(:toml).returns(lib: { name: 'foobar' }, package: { name: 'barbaz' })
36
+ assert_equal 'foobar', config.library_name
37
+ end
38
+
39
+ def test_library_name_from_cargo_package
40
+ config.stubs(:toml).returns(lib: {}, package: { name: 'barbaz' })
41
+ assert_equal 'barbaz', config.library_name
42
+ end
43
+
44
+ def test_shared_library
45
+ config.stubs(:library_name).returns('foobar')
46
+ config.stubs(:shared_ext).returns('ext')
47
+ Gem.stubs(:win_platform?).returns(false)
48
+ assert_equal 'libfoobar.ext', config.shared_library
49
+ end
50
+
51
+ def test_shared_library_windows
52
+ config.stubs(:library_name).returns('foobar')
53
+ config.stubs(:shared_ext).returns('ext')
54
+ Gem.stubs(:win_platform?).returns(true)
55
+ assert_equal 'foobar.ext', config.shared_library
56
+ end
57
+
58
+ def test_tarball_filename
59
+ config.stubs(:library_name).returns('foobar')
60
+ config.stubs(:ruby_version).returns('ruby12')
61
+ config.stubs(:target_os).returns('c64')
62
+ config.stubs(:target_arch).returns('z80')
63
+ assert_equal 'foobar-0.1.2-ruby12-c64-z80.tar.gz', config.tarball_filename('0.1.2')
64
+ end
65
+
66
+ def test_default_ruby_toplevel_dir
67
+ FileUtils.stubs(:pwd).returns('/tmp/foobar')
68
+ assert_equal '/tmp/foobar', config.ruby_toplevel_dir
69
+ end
70
+
71
+ def test_ruby_toplevel_dir
72
+ FileUtils.stubs(:pwd).returns('/tmp/foobar')
73
+ assert_equal '/tmp/barbaz', config(ruby_project_path: '/tmp/barbaz').ruby_toplevel_dir
74
+ end
75
+
76
+ def test_ruby_path
77
+ FileUtils.stubs(:pwd).returns('/tmp/foobar')
78
+ assert_equal '/tmp/foobar/baz/quux', config.ruby_path('baz', 'quux')
79
+ end
80
+
81
+ def test_ruby_extension_path
82
+ FileUtils.stubs(:pwd).returns('/tmp/foobar')
83
+ config.stubs(:shared_library).returns('libfoo.ext')
84
+ assert_equal '/tmp/foobar/lib/libfoo.ext', config.ruby_extension_path
85
+ end
86
+
87
+ def test_default_rust_toplevel_dir
88
+ FileUtils.stubs(:pwd).returns('/tmp/foobar')
89
+ assert_equal '/tmp/foobar', config.rust_toplevel_dir
90
+ end
91
+
92
+ def test_rust_toplevel_dir
93
+ FileUtils.stubs(:pwd).returns('/tmp/foobar')
94
+ assert_equal '/tmp/barbaz', config(cargo_project_path: '/tmp/barbaz').rust_toplevel_dir
95
+ end
96
+
97
+ def test_rust_path
98
+ FileUtils.stubs(:pwd).returns('/tmp/foobar')
99
+ assert_equal '/tmp/foobar/baz/quux', config.rust_path('baz', 'quux')
100
+ end
101
+
102
+ def test_default_git_tag_regex
103
+ assert_equal described_class::DEFAULT_TAG_REGEX, config.git_tag_regex
104
+ end
105
+
106
+ def test_git_tag_regex
107
+ assert_equal(/abc(\d)/, config(git_tag_regex: 'abc(\d)').git_tag_regex)
108
+ end
109
+
110
+ def test_toml
111
+ expected = {
112
+ package: {
113
+ name: 'fixture',
114
+ metadata: {
115
+ thermite: {
116
+ github_releases: true
117
+ }
118
+ }
119
+ }
120
+ }
121
+ assert_equal expected, config(cargo_project_path: fixtures_path('config')).toml
122
+ end
123
+
124
+ def test_default_toml_config
125
+ config.stubs(:toml).returns({})
126
+ assert_equal({}, config.toml_config)
127
+ end
128
+
129
+ def test_toml_config
130
+ expected = { github_releases: true }
131
+ assert_equal expected, config(cargo_project_path: fixtures_path('config')).toml_config
132
+ end
133
+
134
+ private
135
+
136
+ def config(options = {})
137
+ @config ||= described_class.new(options)
138
+ end
139
+
140
+ def described_class
141
+ Thermite::Config
142
+ end
143
+ end
144
+ end
@@ -0,0 +1,118 @@
1
+ require 'tmpdir'
2
+ require 'test_helper'
3
+ require 'thermite/github_release_binary'
4
+ require 'thermite/util'
5
+
6
+ module Thermite
7
+ class GithubReleaseBinaryTest < Minitest::Test
8
+ include Thermite::ModuleTester
9
+
10
+ class Tester
11
+ include Thermite::GithubReleaseBinary
12
+ include Thermite::TestHelper
13
+ include Thermite::Util
14
+ end
15
+
16
+ def test_no_downloading_when_github_releases_is_false
17
+ mock_module(github_releases: false)
18
+ mock_module.expects(:download_latest_binary_from_github_release).never
19
+ mock_module.expects(:download_cargo_version_from_github_release).never
20
+
21
+ assert !mock_module.download_binary
22
+ end
23
+
24
+ def test_github_release_type_defaults_to_cargo
25
+ mock_module(github_releases: true)
26
+ mock_module.expects(:download_latest_binary_from_github_release).never
27
+ mock_module.expects(:download_cargo_version_from_github_release).once
28
+
29
+ mock_module.download_binary
30
+ end
31
+
32
+ def test_download_cargo_version_from_github_release
33
+ mock_module(github_releases: true)
34
+ mock_module.config.stubs(:toml).returns(package: { version: '4.5.6' })
35
+ stub_github_download_uri('v4.5.6')
36
+ Net::HTTP.stubs(:get_response).returns('location' => 'redirect')
37
+ mock_module.stubs(:http_get).returns('tarball')
38
+ mock_module.expects(:unpack_tarball).once
39
+
40
+ assert mock_module.download_binary
41
+ end
42
+
43
+ def test_download_cargo_version_from_github_release_with_custom_git_tag_format
44
+ mock_module(github_releases: true, git_tag_format: 'VER_%s')
45
+ mock_module.config.stubs(:toml).returns(package: { version: '4.5.6' })
46
+ stub_github_download_uri('VER_4.5.6')
47
+ Net::HTTP.stubs(:get_response).returns('location' => 'redirect')
48
+ mock_module.stubs(:http_get).returns('tarball')
49
+ mock_module.expects(:unpack_tarball).once
50
+
51
+ assert mock_module.download_binary
52
+ end
53
+
54
+ def test_download_cargo_version_from_github_release_with_client_error
55
+ mock_module(github_releases: true)
56
+ mock_module.config.stubs(:toml).returns(package: { version: '4.5.6' })
57
+ Net::HTTP.stubs(:get_response).returns(Net::HTTPClientError.new('1.1', 403, 'Forbidden'))
58
+
59
+ assert !mock_module.download_binary
60
+ end
61
+
62
+ def test_download_cargo_version_from_github_release_with_server_error
63
+ mock_module(github_releases: true)
64
+ mock_module.config.stubs(:toml).returns(package: { version: '4.5.6' })
65
+ server_error = Net::HTTPServerError.new('1.1', 500, 'Internal Server Error')
66
+ Net::HTTP.stubs(:get_response).returns(server_error)
67
+
68
+ assert_raises Net::HTTPServerException do
69
+ mock_module.download_binary
70
+ end
71
+ end
72
+
73
+ def test_download_latest_binary_from_github_release
74
+ mock_module(github_releases: true, github_release_type: 'latest', git_tag_regex: 'v(.*)-rust')
75
+ stub_releases_atom
76
+ mock_module.stubs(:download_binary_from_github_release).returns(StringIO.new('tarball'))
77
+ mock_module.expects(:unpack_tarball).once
78
+
79
+ assert mock_module.download_binary
80
+ end
81
+
82
+ def test_download_latest_binary_from_github_release_no_releases_match_regex
83
+ mock_module(github_releases: true, github_release_type: 'latest')
84
+ stub_releases_atom
85
+ mock_module.expects(:github_download_uri).never
86
+
87
+ assert !mock_module.download_binary
88
+ end
89
+
90
+ def test_download_latest_binary_from_github_release_no_tarball_found
91
+ mock_module(github_releases: true, github_release_type: 'latest', git_tag_regex: 'v(.*)-rust')
92
+ stub_releases_atom
93
+ mock_module.stubs(:download_binary_from_github_release).returns(nil)
94
+ mock_module.expects(:unpack_tarball).never
95
+
96
+ assert !mock_module.download_binary
97
+ end
98
+
99
+ private
100
+
101
+ def described_class
102
+ Tester
103
+ end
104
+
105
+ def stub_github_download_uri(tag)
106
+ uri = 'https://github.com/user/project/downloads/project-4.5.6.tar.gz'
107
+ mock_module.expects(:github_download_uri).with(tag, '4.5.6').returns(uri)
108
+ end
109
+
110
+ def stub_releases_atom
111
+ atom = File.read(fixtures_path('github', 'releases.atom'))
112
+ project_uri = 'https://github.com/user/project'
113
+ releases_uri = "#{project_uri}/releases.atom"
114
+ mock_module.config.stubs(:toml).returns(package: { repository: project_uri })
115
+ mock_module.expects(:http_get).with(releases_uri).returns(atom)
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,91 @@
1
+ require 'fileutils'
2
+ require 'tmpdir'
3
+ require 'test_helper'
4
+ require 'thermite/package'
5
+ require 'thermite/util'
6
+
7
+ module Thermite
8
+ class PackageTest < Minitest::Test
9
+ include Thermite::ModuleTester
10
+
11
+ class Tester
12
+ include Thermite::Package
13
+ include Thermite::TestHelper
14
+ include Thermite::Util
15
+ end
16
+
17
+ def test_build_package_and_unpack_tarball
18
+ using_temp_dir do |dir, tgz_filename|
19
+ using_project_dir(stub_dir(dir, 'project')) do |project_dir|
20
+ extension_path = stub_extension_path(project_dir)
21
+ stub_config(project_dir, extension_path, tgz_filename)
22
+
23
+ mock_module.build_package
24
+ end
25
+
26
+ using_install_dir(stub_dir(dir, 'install')) do |install_dir|
27
+ File.open(tgz_filename, 'rb') do |f|
28
+ mock_module.unpack_tarball(f)
29
+ end
30
+ packed_file = File.join(install_dir, 'lib', 'test.txt')
31
+ assert File.exist?(packed_file), "File '#{packed_file}' does not exist."
32
+ assert_equal 'some extension', File.read(packed_file)
33
+ end
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def described_class
40
+ Tester
41
+ end
42
+
43
+ def stub_config(project_dir, extension_path, filename)
44
+ mock_module.config.stubs(:ruby_toplevel_dir).returns(project_dir)
45
+ mock_module.config.stubs(:ruby_extension_path).returns(extension_path)
46
+ mock_module.config.stubs(:toml).returns(package: { version: '7.8.9' })
47
+ mock_module.config.stubs(:tarball_filename).with('7.8.9').returns(filename)
48
+ end
49
+
50
+ def stub_dir(base, name)
51
+ subdir = File.join(base, name)
52
+ Dir.mkdir(subdir)
53
+
54
+ subdir
55
+ end
56
+
57
+ def stub_extension_path(dir)
58
+ extension_path = File.join(dir, 'lib', 'test.txt')
59
+ Dir.mkdir(File.dirname(extension_path))
60
+ File.write(extension_path, 'some extension')
61
+
62
+ extension_path
63
+ end
64
+
65
+ def using_project_dir(project_dir)
66
+ yield project_dir
67
+ ensure
68
+ FileUtils.rm_rf(project_dir)
69
+ end
70
+
71
+ def using_install_dir(install_dir)
72
+ Dir.mkdir(File.join(install_dir, 'lib'))
73
+ Dir.chdir(install_dir) do
74
+ yield install_dir
75
+ end
76
+ ensure
77
+ FileUtils.rm_rf(install_dir)
78
+ end
79
+
80
+ def using_temp_dir
81
+ Dir.mktmpdir do |dir|
82
+ filename = File.join(dir, 'test-7.8.9.tar.gz')
83
+ begin
84
+ yield dir, filename
85
+ ensure
86
+ FileUtils.rm_f(filename)
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,36 @@
1
+ require 'tempfile'
2
+ require 'test_helper'
3
+ require 'thermite/util'
4
+
5
+ module Thermite
6
+ class UtilTest < Minitest::Test
7
+ include Thermite::ModuleTester
8
+
9
+ class Tester
10
+ include Thermite::TestHelper
11
+ include Thermite::Util
12
+ end
13
+
14
+ def test_debug
15
+ stub_debug_filename(nil)
16
+ mock_module.debug('will not exist')
17
+ debug_file = Tempfile.new('thermite_test')
18
+ stub_debug_filename(debug_file.path)
19
+ mock_module.debug('some message')
20
+ mock_module.instance_variable_get('@debug').flush
21
+ debug_file.rewind
22
+ assert_equal "some message\n", debug_file.read
23
+ ensure
24
+ debug_file.close
25
+ debug_file.unlink
26
+ end
27
+
28
+ def stub_debug_filename(value)
29
+ mock_module.config.stubs(:debug_filename).returns(value)
30
+ end
31
+
32
+ def described_class
33
+ Tester
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,41 @@
1
+ if ENV['CODECLIMATE_REPO_TOKEN']
2
+ require 'codeclimate-test-reporter'
3
+ CodeClimate::TestReporter.start
4
+ else
5
+ require 'simplecov'
6
+ SimpleCov.start do
7
+ load_profile 'test_frameworks'
8
+ add_filter 'lib/thermite/tasks.rb'
9
+ track_files 'lib/**/*.rb'
10
+ end
11
+ end
12
+
13
+ ENV['THERMITE_TEST'] = '1'
14
+
15
+ require 'minitest/autorun'
16
+ require 'mocha/mini_test'
17
+ require 'thermite/config'
18
+
19
+ module Minitest
20
+ class Test
21
+ def fixtures_path(*components)
22
+ File.join(File.dirname(__FILE__), 'fixtures', *components)
23
+ end
24
+ end
25
+ end
26
+
27
+ module Thermite
28
+ module ModuleTester
29
+ def mock_module(options = {})
30
+ @mock_module ||= described_class.new(options)
31
+ end
32
+ end
33
+
34
+ module TestHelper
35
+ attr_reader :config, :options
36
+ def initialize(options = {})
37
+ @options = options
38
+ @config = Thermite::Config.new(@options)
39
+ end
40
+ end
41
+ end
data/thermite.gemspec CHANGED
@@ -3,7 +3,7 @@ require 'English'
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = 'thermite'
6
- s.version = '0.4.0'
6
+ s.version = '0.5.0'
7
7
  s.summary = 'Rake helpers for Rust+Ruby'
8
8
  s.description = 'A Rake-based helper for building and distributing Rust-based Ruby extensions'
9
9
 
@@ -17,9 +17,12 @@ Gem::Specification.new do |s|
17
17
 
18
18
  # Mostly due to tomlrb
19
19
  s.required_ruby_version = '>= 2.0.0'
20
+
20
21
  s.add_runtime_dependency 'rake', '>= 10'
21
22
  s.add_runtime_dependency 'minitar', '~> 0.5'
22
23
  s.add_runtime_dependency 'tomlrb', '~> 1.2'
23
- s.add_development_dependency 'rdoc', '~> 4.2'
24
- s.add_development_dependency 'rubocop', '~> 0.40'
24
+ s.add_development_dependency 'minitest', '~> 5.9'
25
+ s.add_development_dependency 'mocha', '~> 1.1'
26
+ s.add_development_dependency 'rubocop', '~> 0.41'
27
+ s.add_development_dependency 'yard', '~> 0.9'
25
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thermite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Lee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-12 00:00:00.000000000 Z
11
+ date: 2016-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -53,41 +53,69 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.2'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rdoc
56
+ name: minitest
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '4.2'
61
+ version: '5.9'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '4.2'
68
+ version: '5.9'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mocha
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.1'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rubocop
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: '0.40'
89
+ version: '0.41'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.41'
97
+ - !ruby/object:Gem::Dependency
98
+ name: yard
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.9'
76
104
  type: :development
77
105
  prerelease: false
78
106
  version_requirements: !ruby/object:Gem::Requirement
79
107
  requirements:
80
108
  - - "~>"
81
109
  - !ruby/object:Gem::Version
82
- version: '0.40'
110
+ version: '0.9'
83
111
  description: A Rake-based helper for building and distributing Rust-based Ruby extensions
84
112
  email: malept@users.noreply.github.com
85
113
  executables: []
86
114
  extensions: []
87
115
  extra_rdoc_files: []
88
116
  files:
117
+ - ".appveyor.yml"
89
118
  - ".gitignore"
90
- - ".rdoc_options"
91
119
  - ".rubocop.yml"
92
120
  - ".travis.yml"
93
121
  - ".yardopts"
@@ -104,6 +132,14 @@ files:
104
132
  - lib/thermite/package.rb
105
133
  - lib/thermite/tasks.rb
106
134
  - lib/thermite/util.rb
135
+ - test/fixtures/config/Cargo.toml
136
+ - test/fixtures/github/releases.atom
137
+ - test/lib/thermite/cargo_test.rb
138
+ - test/lib/thermite/config_test.rb
139
+ - test/lib/thermite/github_release_binary_test.rb
140
+ - test/lib/thermite/package_test.rb
141
+ - test/lib/thermite/util_test.rb
142
+ - test/test_helper.rb
107
143
  - thermite.gemspec
108
144
  homepage: https://github.com/malept/thermite
109
145
  licenses:
data/.rdoc_options DELETED
@@ -1,24 +0,0 @@
1
- --- !ruby/object:RDoc::Options
2
- encoding: UTF-8
3
- static_path: []
4
- rdoc_include:
5
- - "lib/thermite/*.rb"
6
- - "README.md"
7
- charset: UTF-8
8
- exclude:
9
- - vendor/bundle
10
- hyperlink_all: false
11
- line_numbers: true
12
- locale:
13
- locale_dir: locale
14
- locale_name:
15
- main_page: README.md
16
- markup: markdown
17
- output_decoration: true
18
- page_dir:
19
- show_hash: false
20
- tab_width: 2
21
- template_stylesheets: []
22
- title:
23
- visibility: :protected
24
- webcvs: https://github.com/malept/thermite/tree/master