From 9f4a22933044d89d16e6350901912eaac7d90828 Mon Sep 17 00:00:00 2001 From: Dan Macumber Date: Sun, 8 Jul 2018 11:19:39 -0600 Subject: [PATCH] Adding tests, all pass except native gem on windows --- .gitignore | 1 + openstudiocore/src/cli/openstudio_cli.rb | 10 +-- openstudiocore/src/cli/test/bundle/Gemfile | 4 + openstudiocore/src/cli/test/bundle/test.rb | 21 +++++ .../src/cli/test/bundle_git/Gemfile | 5 ++ .../src/cli/test/bundle_git/test.rb | 20 +++++ .../src/cli/test/bundle_native/Gemfile | 4 + .../src/cli/test/bundle_native/test.rb | 18 ++++ .../src/cli/test/bundle_no_install/Gemfile | 4 + .../src/cli/test/bundle_no_install/test.rb | 21 +++++ openstudiocore/src/cli/test/no_bundle/test.rb | 15 ++++ openstudiocore/src/cli/test/test_bundle.rb | 89 +++++++++++++++++++ 12 files changed, 206 insertions(+), 6 deletions(-) create mode 100644 openstudiocore/src/cli/test/bundle/Gemfile create mode 100644 openstudiocore/src/cli/test/bundle/test.rb create mode 100644 openstudiocore/src/cli/test/bundle_git/Gemfile create mode 100644 openstudiocore/src/cli/test/bundle_git/test.rb create mode 100644 openstudiocore/src/cli/test/bundle_native/Gemfile create mode 100644 openstudiocore/src/cli/test/bundle_native/test.rb create mode 100644 openstudiocore/src/cli/test/bundle_no_install/Gemfile create mode 100644 openstudiocore/src/cli/test/bundle_no_install/test.rb create mode 100644 openstudiocore/src/cli/test/no_bundle/test.rb create mode 100644 openstudiocore/src/cli/test/test_bundle.rb diff --git a/.gitignore b/.gitignore index e74b8c97e16..ea8f07b226c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .idea .ruby-version .bundle +test_gems test_fails.txt /build/ /build_debug/ diff --git a/openstudiocore/src/cli/openstudio_cli.rb b/openstudiocore/src/cli/openstudio_cli.rb index b21cf4aaf3b..30ee9f1a5be 100644 --- a/openstudiocore/src/cli/openstudio_cli.rb +++ b/openstudiocore/src/cli/openstudio_cli.rb @@ -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 diff --git a/openstudiocore/src/cli/test/bundle/Gemfile b/openstudiocore/src/cli/test/bundle/Gemfile new file mode 100644 index 00000000000..65a631115f4 --- /dev/null +++ b/openstudiocore/src/cli/test/bundle/Gemfile @@ -0,0 +1,4 @@ +source 'http://rubygems.org' + +gem 'openstudio-standards', '0.2.0' +gem 'tilt', '2.0.8' \ No newline at end of file diff --git a/openstudiocore/src/cli/test/bundle/test.rb b/openstudiocore/src/cli/test/bundle/test.rb new file mode 100644 index 00000000000..60aa596db3c --- /dev/null +++ b/openstudiocore/src/cli/test/bundle/test.rb @@ -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' diff --git a/openstudiocore/src/cli/test/bundle_git/Gemfile b/openstudiocore/src/cli/test/bundle_git/Gemfile new file mode 100644 index 00000000000..d0751987dde --- /dev/null +++ b/openstudiocore/src/cli/test/bundle_git/Gemfile @@ -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' \ No newline at end of file diff --git a/openstudiocore/src/cli/test/bundle_git/test.rb b/openstudiocore/src/cli/test/bundle_git/test.rb new file mode 100644 index 00000000000..be0c11b76d6 --- /dev/null +++ b/openstudiocore/src/cli/test/bundle_git/test.rb @@ -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' \ No newline at end of file diff --git a/openstudiocore/src/cli/test/bundle_native/Gemfile b/openstudiocore/src/cli/test/bundle_native/Gemfile new file mode 100644 index 00000000000..90fb24ab9b6 --- /dev/null +++ b/openstudiocore/src/cli/test/bundle_native/Gemfile @@ -0,0 +1,4 @@ +source 'http://rubygems.org' + +gem 'ffi', '1.9.25' +gem 'rubyXL', '3.3.29' \ No newline at end of file diff --git a/openstudiocore/src/cli/test/bundle_native/test.rb b/openstudiocore/src/cli/test/bundle_native/test.rb new file mode 100644 index 00000000000..8c457948c97 --- /dev/null +++ b/openstudiocore/src/cli/test/bundle_native/test.rb @@ -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' diff --git a/openstudiocore/src/cli/test/bundle_no_install/Gemfile b/openstudiocore/src/cli/test/bundle_no_install/Gemfile new file mode 100644 index 00000000000..4755f2d4ce9 --- /dev/null +++ b/openstudiocore/src/cli/test/bundle_no_install/Gemfile @@ -0,0 +1,4 @@ +source 'http://rubygems.org' + +gem 'openstudio-standards', '0.2.2' +gem 'tilt', '2.0.8' \ No newline at end of file diff --git a/openstudiocore/src/cli/test/bundle_no_install/test.rb b/openstudiocore/src/cli/test/bundle_no_install/test.rb new file mode 100644 index 00000000000..60aa596db3c --- /dev/null +++ b/openstudiocore/src/cli/test/bundle_no_install/test.rb @@ -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' diff --git a/openstudiocore/src/cli/test/no_bundle/test.rb b/openstudiocore/src/cli/test/no_bundle/test.rb new file mode 100644 index 00000000000..99d79a2dcf1 --- /dev/null +++ b/openstudiocore/src/cli/test/no_bundle/test.rb @@ -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 diff --git a/openstudiocore/src/cli/test/test_bundle.rb b/openstudiocore/src/cli/test/test_bundle.rb new file mode 100644 index 00000000000..975d960da6b --- /dev/null +++ b/openstudiocore/src/cli/test/test_bundle.rb @@ -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 \ No newline at end of file