From ac4ea1209f605d35c4f27baa13421f5e6f41affa Mon Sep 17 00:00:00 2001 From: ignisf Date: Sun, 15 Jun 2014 13:29:53 +0300 Subject: [PATCH] Extract the CompilerHelpers module to spec/support --- spec/compiler/clang_spec.rb | 6 ---- spec/compiler/gcc_spec.rb | 6 ---- spec/compiler/generic_compiler_spec.rb | 6 ---- spec/compiler_spec.rb | 6 ---- spec/spec_helper.rb | 44 ++----------------------- spec/support/compiler_helpers.rb | 45 ++++++++++++++++++++++++++ 6 files changed, 47 insertions(+), 66 deletions(-) create mode 100644 spec/support/compiler_helpers.rb diff --git a/spec/compiler/clang_spec.rb b/spec/compiler/clang_spec.rb index ab3757b..78aca83 100644 --- a/spec/compiler/clang_spec.rb +++ b/spec/compiler/clang_spec.rb @@ -1,12 +1,6 @@ -$:.unshift File.expand_path '../../../ext/libv8', __FILE__ - require 'spec_helper' require 'compiler' -RSpec.configure do |c| - c.include CompilerHelpers -end - module Libv8::Compiler describe Clang do subject { Clang.new 'c++' } diff --git a/spec/compiler/gcc_spec.rb b/spec/compiler/gcc_spec.rb index 59f1518..689f53b 100644 --- a/spec/compiler/gcc_spec.rb +++ b/spec/compiler/gcc_spec.rb @@ -1,12 +1,6 @@ -$:.unshift File.expand_path '../../../ext/libv8', __FILE__ - require 'spec_helper' require 'compiler' -RSpec.configure do |c| - c.include CompilerHelpers -end - module Libv8::Compiler describe GCC do subject { GCC.new 'c++' } diff --git a/spec/compiler/generic_compiler_spec.rb b/spec/compiler/generic_compiler_spec.rb index d214687..9f64937 100644 --- a/spec/compiler/generic_compiler_spec.rb +++ b/spec/compiler/generic_compiler_spec.rb @@ -1,12 +1,6 @@ -$:.unshift File.expand_path '../../../ext/libv8', __FILE__ - require 'spec_helper' require 'compiler' -RSpec.configure do |c| - c.include CompilerHelpers -end - module Libv8::Compiler describe GenericCompiler do subject { GenericCompiler.new 'c++' } diff --git a/spec/compiler_spec.rb b/spec/compiler_spec.rb index 36ecffa..e0a58f1 100644 --- a/spec/compiler_spec.rb +++ b/spec/compiler_spec.rb @@ -1,12 +1,6 @@ -$:.unshift File.expand_path '../../ext/libv8', __FILE__ - require 'spec_helper' require 'compiler' -RSpec.configure do |c| - c.include CompilerHelpers -end - module Libv8 describe Compiler do describe '::type_of' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9e6e51c..c1f8718 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,46 +1,6 @@ +$:.unshift File.expand_path '../../ext/libv8', __FILE__ $:.unshift File.expand_path '../../lib', __FILE__ require 'rspec' require 'rspec-spies' require 'libv8' - -module CompilerHelpers - VERSION_OUTPUTS = { - :gcc => { - "4.2.1-freebsd" => %Q{Using built-in specs.\nTarget: i386-undermydesk-freebsd\nConfigured with: FreeBSD/i386 system compiler\nThread model: posix\ngcc version 4.2.1 20070831 patched [FreeBSD]\n}, - "4.9.0" => %Q{Using built-in specs.\nCOLLECT_GCC=c++\nCOLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.0/lto-wrapper\nTarget: x86_64-unknown-linux-gnu\nConfigured with: /build/gcc-multilib/src/gcc-4.9-20140604/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-cloog-backend=isl --disable-cloog-version-check --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --enable-multilib --disable-werror --enable-checking=release\nThread model: posix\ngcc version 4.9.0 20140604 (prerelease) (GCC)\n} - }, - :clang => { - "3.4.1" => %Q{clang version 3.4.1 (tags/RELEASE_34/dot1-final)\nTarget: x86_64-unknown-linux-gnu\nThread model: posix\nFound candidate GCC installation: /usr/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.9.0\nFound candidate GCC installation: /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.0\nFound candidate GCC installation: /usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.0\nFound candidate GCC installation: /usr/lib64/gcc/x86_64-unknown-linux-gnu/4.9.0\nSelected GCC installation: /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.0\n}, - "3.10.0" => %Q{clang version 3.10.0 (tags/RELEASE_310/dot0-final)\nTarget: x86_64-unknown-linux-gnu\n}, - "3.0.0" => %Q{clang version 3.0.0 (tags/RELEASE_30/dot0-final)\nTarget: x86_64-unknown-linux-gnu\n} - } - } - - def version_output_of(name, version) - VERSION_OUTPUTS[name][version] - end - - def success_status - double success?: true - end - - def failure_status - double success?: false - end - - def stub_shell_command(command, output, status) - allow(Libv8::Compiler).to receive(:execute_command).with(command) do - double output: output, status: status - end - end - - def stub_as_available(command, name, version) - stub_shell_command "which #{command} 2>&1", '', success_status - stub_shell_command "#{command} -v 2>&1", version_output_of(name, version), success_status - end - - def stub_as_unavailable(command) - stub_shell_command "which #{command} 2>&1", '', failure_status - stub_shell_command(/^#{command}/, '', failure_status) - end -end +require File.expand_path '../support/compiler_helpers', __FILE__ diff --git a/spec/support/compiler_helpers.rb b/spec/support/compiler_helpers.rb new file mode 100644 index 0000000..a581722 --- /dev/null +++ b/spec/support/compiler_helpers.rb @@ -0,0 +1,45 @@ +module CompilerHelpers + VERSION_OUTPUTS = { + :gcc => { + "4.2.1-freebsd" => %Q{Using built-in specs.\nTarget: i386-undermydesk-freebsd\nConfigured with: FreeBSD/i386 system compiler\nThread model: posix\ngcc version 4.2.1 20070831 patched [FreeBSD]\n}, + "4.9.0" => %Q{Using built-in specs.\nCOLLECT_GCC=c++\nCOLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.0/lto-wrapper\nTarget: x86_64-unknown-linux-gnu\nConfigured with: /build/gcc-multilib/src/gcc-4.9-20140604/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-cloog-backend=isl --disable-cloog-version-check --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --enable-multilib --disable-werror --enable-checking=release\nThread model: posix\ngcc version 4.9.0 20140604 (prerelease) (GCC)\n} + }, + :clang => { + "3.4.1" => %Q{clang version 3.4.1 (tags/RELEASE_34/dot1-final)\nTarget: x86_64-unknown-linux-gnu\nThread model: posix\nFound candidate GCC installation: /usr/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.9.0\nFound candidate GCC installation: /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.0\nFound candidate GCC installation: /usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.0\nFound candidate GCC installation: /usr/lib64/gcc/x86_64-unknown-linux-gnu/4.9.0\nSelected GCC installation: /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.0\n}, + "3.10.0" => %Q{clang version 3.10.0 (tags/RELEASE_310/dot0-final)\nTarget: x86_64-unknown-linux-gnu\n}, + "3.0.0" => %Q{clang version 3.0.0 (tags/RELEASE_30/dot0-final)\nTarget: x86_64-unknown-linux-gnu\n} + } + } + + def version_output_of(name, version) + VERSION_OUTPUTS[name][version] + end + + def success_status + double success?: true + end + + def failure_status + double success?: false + end + + def stub_shell_command(command, output, status) + allow(Libv8::Compiler).to receive(:execute_command).with(command) do + double output: output, status: status + end + end + + def stub_as_available(command, name, version) + stub_shell_command "which #{command} 2>&1", '', success_status + stub_shell_command "#{command} -v 2>&1", version_output_of(name, version), success_status + end + + def stub_as_unavailable(command) + stub_shell_command "which #{command} 2>&1", '', failure_status + stub_shell_command(/^#{command}/, '', failure_status) + end +end + +RSpec.configure do |c| + c.include CompilerHelpers +end