Skip to content

Commit

Permalink
Adding tests, all pass except native gem on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
macumber committed Jul 8, 2018
1 parent 39fe71b commit 9f4a229
Show file tree
Hide file tree
Showing 12 changed files with 206 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.idea
.ruby-version
.bundle
test_gems
test_fails.txt
/build/
/build_debug/
Expand Down
10 changes: 4 additions & 6 deletions openstudiocore/src/cli/openstudio_cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -473,19 +473,17 @@ def parse_main_args(main_args)
# 2) find_file("Gemfile", "gems.rb")
#require 'bundler/setup'



Bundler.setup
#Bundler.require
rescue Bundler::BundlerError => e
puts "#{e.message}"
#puts e.backtrace.join("\n")
if e.is_a?(Bundler::GemNotFound)
puts "Run `bundle install` to install missing gems."
#exit e.status_code
puts "GemNotFound, Run `bundle install` to install missing gems."
exit e.status_code
elsif e.is_a?(Bundler::ProductionError)
puts "Run `bundle install` to install missing gems."
#exit e.status_code
puts "ProductionError, Run `bundle install` to install missing gems."
exit e.status_code
else
# no Gemfile,
end
Expand Down
4 changes: 4 additions & 0 deletions openstudiocore/src/cli/test/bundle/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source 'http://rubygems.org'

gem 'openstudio-standards', '0.2.0'
gem 'tilt', '2.0.8'
21 changes: 21 additions & 0 deletions openstudiocore/src/cli/test/bundle/test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'rubygems'

def local_gems
Gem::Specification.sort_by{ |g| [g.name.downcase, g.version] }.group_by{ |g| g.name }
end

# list installed gems
puts local_gems.map{ |name, specs|
[name, specs.map{ |spec| spec.version.to_s }.join(',')].join(' ')
}

# test a simple gem
require 'tilt'
puts Tilt::VERSION
raise "Tilt version does not match" unless Tilt::VERSION == '2.0.8'

# test a more complex / larger gem, that should override the existing version installed
require 'openstudio'
require 'openstudio-standards'
puts OpenstudioStandards::VERSION
raise "OpenStudio Standards version does not match" unless OpenstudioStandards::VERSION == '0.2.0'
5 changes: 5 additions & 0 deletions openstudiocore/src/cli/test/bundle_git/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source 'http://rubygems.org'

gem 'xml-simple'
gem 'openstudio-standards', github: 'nrel/openstudio-standards', branch: 'ambient-loop'
gem 'tilt', github: 'rtomayko/tilt', ref: 'abe77eaf1b5f8da0a7e46135f'
20 changes: 20 additions & 0 deletions openstudiocore/src/cli/test/bundle_git/test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'rubygems'

def local_gems
Gem::Specification.sort_by{ |g| [g.name.downcase, g.version] }.group_by{ |g| g.name }
end

# list installed gems
puts local_gems.map{ |name, specs|
[name, specs.map{ |spec| spec.version.to_s }.join(',')].join(' ')
}

# test a github checkout gem
require 'openstudio'
require 'openstudio-standards'
puts OpenstudioStandards::VERSION
raise "OpenStudio Standards version does not match" unless OpenstudioStandards::VERSION.to_s == '0.5.0-ambient'

require 'tilt'
puts Tilt::VERSION
raise "Tilt version does not match" unless Tilt::VERSION == '2.0.8'
4 changes: 4 additions & 0 deletions openstudiocore/src/cli/test/bundle_native/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source 'http://rubygems.org'

gem 'ffi', '1.9.25'
gem 'rubyXL', '3.3.29'
18 changes: 18 additions & 0 deletions openstudiocore/src/cli/test/bundle_native/test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require 'rubygems'

def local_gems
Gem::Specification.sort_by{ |g| [g.name.downcase, g.version] }.group_by{ |g| g.name }
end

# list installed gems
puts local_gems.map{ |name, specs|
[name, specs.map{ |spec| spec.version.to_s }.join(',')].join(' ')
}
# test a gem that required native extensions
require 'ffi'
puts FFI::VERSION
raise "FFI version does not match" unless FFI::VERSION == '1.9.25'

require 'rubyXL'
puts RubyXL::VERSION
raise "RubyXL version does not match" unless RubyXL::VERSION == '3.3.29'
4 changes: 4 additions & 0 deletions openstudiocore/src/cli/test/bundle_no_install/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source 'http://rubygems.org'

gem 'openstudio-standards', '0.2.2'
gem 'tilt', '2.0.8'
21 changes: 21 additions & 0 deletions openstudiocore/src/cli/test/bundle_no_install/test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'rubygems'

def local_gems
Gem::Specification.sort_by{ |g| [g.name.downcase, g.version] }.group_by{ |g| g.name }
end

# list installed gems
puts local_gems.map{ |name, specs|
[name, specs.map{ |spec| spec.version.to_s }.join(',')].join(' ')
}

# test a simple gem
require 'tilt'
puts Tilt::VERSION
raise "Tilt version does not match" unless Tilt::VERSION == '2.0.8'

# test a more complex / larger gem, that should override the existing version installed
require 'openstudio'
require 'openstudio-standards'
puts OpenstudioStandards::VERSION
raise "OpenStudio Standards version does not match" unless OpenstudioStandards::VERSION == '0.2.0'
15 changes: 15 additions & 0 deletions openstudiocore/src/cli/test/no_bundle/test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'rubygems'

def local_gems
Gem::Specification.sort_by{ |g| [g.name.downcase, g.version] }.group_by{ |g| g.name }
end

# list installed gems
puts local_gems.map{ |name, specs|
[name, specs.map{ |spec| spec.version.to_s }.join(',')].join(' ')
}

# test a more complex / larger gem, that should override the existing version installed
require 'openstudio'
require 'openstudio-standards'
puts OpenstudioStandards::VERSION
89 changes: 89 additions & 0 deletions openstudiocore/src/cli/test/test_bundle.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
require 'minitest/autorun'
require 'openstudio'

# test bundle capability in CLI
# currently CLI cannot do bundle install, rely on system bundle for that
class Bundle_Test < Minitest::Test

def rm_if_exist(p)
if File.exist?(p)
FileUtils.rm_rf(p)
end
end

def test_bundle
original_dir = Dir.pwd
Dir.chdir(File.join(File.dirname(__FILE__), 'bundle'))

rm_if_exist('Gemfile.lock')
rm_if_exist('./test_gems')
rm_if_exist('./bundle')

assert(system('bundle install --path ./test_gems'))
assert(system('bundle lock --add_platform ruby'))
assert(system("'#{OpenStudio::getOpenStudioCLI}' --bundle Gemfile --verbose test.rb"))

ensure
Dir.chdir(original_dir)
end

def test_bundle_git
original_dir = Dir.pwd
Dir.chdir(File.join(File.dirname(__FILE__), 'bundle_git'))

rm_if_exist('Gemfile.lock')
rm_if_exist('./test_gems')
rm_if_exist('./bundle')

assert(system('bundle install --path ./test_gems'))
assert(system('bundle lock --add_platform ruby'))
assert(system("'#{OpenStudio::getOpenStudioCLI}' --bundle Gemfile --verbose test.rb"))

ensure
Dir.chdir(original_dir)
end

def test_bundle_native
original_dir = Dir.pwd
Dir.chdir(File.join(File.dirname(__FILE__), 'bundle_native'))

rm_if_exist('Gemfile.lock')
rm_if_exist('./test_gems')
rm_if_exist('./bundle')

assert(system('bundle install --path ./test_gems'))
assert(system('bundle lock --add_platform ruby'))
assert(system('bundle lock --add_platform mswin'))
assert(system("'#{OpenStudio::getOpenStudioCLI}' --bundle Gemfile --verbose test.rb"))

ensure
Dir.chdir(original_dir)
end

def test_bundle_no_install
original_dir = Dir.pwd
Dir.chdir(File.join(File.dirname(__FILE__), 'bundle_no_install'))

rm_if_exist('Gemfile.lock')
rm_if_exist('./test_gems')
rm_if_exist('./bundle')

#assert(system('bundle install --path ./test_gems'))
#assert(system('bundle lock --add_platform ruby'))
assert_equal(system("'#{OpenStudio::getOpenStudioCLI}' --bundle Gemfile --verbose test.rb"), false)

ensure
Dir.chdir(original_dir)
end

def test_no_bundle
original_dir = Dir.pwd
Dir.chdir(File.join(File.dirname(__FILE__), 'no_bundle'))

assert(system("'#{OpenStudio::getOpenStudioCLI}' --verbose test.rb"))

ensure
Dir.chdir(original_dir)
end

end

0 comments on commit 9f4a229

Please sign in to comment.