Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: opal/opal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 7327505d41ff^
Choose a base ref
...
head repository: opal/opal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 55ab20c24684
Choose a head ref
  • 2 commits
  • 5 files changed
  • 1 contributor

Commits on Sep 10, 2015

  1. Remove unused file

    Which was accidentally pushed to master in 0208fc9.
    elia committed Sep 10, 2015
    Copy the full SHA
    7327505 View commit details
  2. Copy the full SHA
    55ab20c View commit details
1 change: 0 additions & 1 deletion lib/mspec/opal/new.html.erb

This file was deleted.

79 changes: 2 additions & 77 deletions lib/mspec/opal/rake_task.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require 'opal'
require 'rack'
require 'webrick'
require 'mspec/opal/special_calls'

module MSpec
module Opal
@@ -26,7 +25,7 @@ def initialize(name, &task_block)
require 'opal/util'
path = './build/specs.js'
min_path = './build/specs.min.js'
Environment.new.build_specs(path)
::Opal::Environment.new.build_specs(path)
min = ::Opal::Util.uglify File.read(path)
File.open(min_path, 'w') { |f| f << min }
end
@@ -38,19 +37,6 @@ def initialize(name, &task_block)

class Runner
def initialize
@app = Rack::Builder.new do
::Opal::Processor.arity_check_enabled = true
::Opal::Processor.freezing_stubs_enabled = false
::Opal::Processor.tainting_stubs_enabled = false
::Opal::Processor.dynamic_require_severity = :error

use Rack::ShowExceptions
use Rack::ShowStatus
use MSpec::Opal::Index
run MSpec::Opal::Environment.new
end

@port = 9999
end

attr_reader :app, :server
@@ -116,7 +102,7 @@ def initialize(basedir = nil, pattern = nil)
::Opal::Processor.stub_file asset
end

ENV['OPAL_SPEC'] ||= files_to_run(pattern).join(',')
ENV['OPAL_SPEC'] ||= Testing.specs

super()

@@ -149,67 +135,6 @@ def files
@files ||= []
end

def add_files specs, tag = ''
tag = "[#{tag}] "
puts "#{tag}Adding #{specs.size} spec files..."
specs = specs.flatten.map do |path|
dirname = File.join([basedir, path])
if File.directory? dirname
rubyspec_paths_in_dir(dirname, path)
else
path
end
end.flatten
files.concat specs
end

def paths_from_glob pattern
Dir.glob(File.expand_path(pattern)).map do |s|
s.sub(/\A#{basedir}\//, '').sub(/\.rb\z/, '')
end
end

def rubyspec_paths_in_dir(dirname, path)
Dir.entries(dirname).select do |spec|
spec.end_with? '.rb'
end.map do |spec|
File.join path, spec
end
end

def rubyspec_white_list
File.read("#{basedir}/rubyspecs").split("\n").reject do |line|
line.sub(/#.*/, '').strip.empty? ||
(line.start_with?('!') && rubyspec_black_list.push(line.sub('!', '') + '.rb'))
end
end

def rubyspec_black_list
@rubyspec_black_list ||= []
end

def files_to_run(pattern=nil)
# add any filters in spec/filters of specs we dont want to run
add_files paths_from_glob("#{basedir}/filters/**/*.rb"), :filters

if pattern
# add custom opal specs from spec/
add_files paths_from_glob(pattern) & rubyspec_white_list, :rubyspec_custom
add_files paths_from_glob(pattern).grep(/(?!spec\/(rubyspec|stdlib)\/)/), :other_custom

else
# add opal specific specs
add_files paths_from_glob("#{basedir}/opal/**/*_spec.rb"), :shared
add_files paths_from_glob("#{basedir}/lib/lexer_spec.rb"), :lexer
add_files paths_from_glob("#{basedir}/lib/parser/**/*_spec.rb"), :parser

# add any rubyspecs we want to run (defined in spec/rubyspecs)
add_files rubyspec_white_list, :rubyspecs
end

files - rubyspec_black_list
end

def build_specs file = "#{basedir}/build/specs.js"
code = specs.to_s
FileUtils.mkdir_p File.dirname(file)
169 changes: 111 additions & 58 deletions tasks/testing.rake
Original file line number Diff line number Diff line change
@@ -1,16 +1,118 @@
require_relative './testing/mspec_special_calls'

require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:rspec) do |t|
t.pattern = 'spec/lib/**/*_spec.rb'
end

require 'mspec/opal/rake_task'
MSpec::Opal::RakeTask.new(:mspec_phantom) do |config|
config.pattern = ENV['MSPEC_PATTERN'] if ENV['MSPEC_PATTERN']
config.basedir = ENV['MSPEC_BASEDIR'] if ENV['MSPEC_BASEDIR']
module Testing
extend self

def stubs
%w[
mspec/helpers/tmp
mspec/helpers/environment
mspec/guards/block_device
mspec/guards/endian
]
end

def specs
excepting = []
rubyspecs = File.read('spec/rubyspecs').lines.reject do |l|
l.strip!
l.start_with?('#') || l.empty? || (l.start_with?('!') && excepting.push(l.sub('!', 'spec/') + '.rb'))
end.flat_map do |path|
path = "spec/#{path}"
File.directory?(path) ? Dir[path+'/*.rb'] : "#{path}.rb"
end - excepting

filters = Dir['spec/filters/**/*.rb']
shared = Dir['spec/{opal,lib/parser}/**/*_spec.rb'] + ['spec/lib/lexer_spec.rb']

specs = []
add_specs = ->(name, new_specs) { p [new_specs.size, name]; specs + new_specs}

specs = add_specs.(:filters, filters)
pattern = ENV['PATTERN']
whitelist_pattern = !!ENV['RUBYSPECS']

if pattern
custom = Dir[pattern]
custom &= rubyspecs if whitelist_pattern
specs = add_specs.(:custom, custom)
elsif ENV['SUITE'] == 'opal'
specs = add_specs.(:shared, shared)
elsif ENV['SUITE'] == 'rubyspec'
specs = add_specs.(:rubyspecs, rubyspecs)
else
warn 'Please provide at lease one of the following ENV vars:'
warn 'PATTERN # e.g. env PATTERN="spec/rubyspec/core/numeric/**_spec.rb"'
warn 'SUITE # can be either SUITE=opal or SUITE=rubyspec'
exit 1
end
end

def write_file(filename, specs, bm_filepath = nil)
requires = specs.map{|s| "require '#{s.sub(/^spec\//,'')}'"}

if bm_filepath
enter_benchmarking_mode = "OSpecRunner.main.bm!(#{Integer(ENV['BM'])}, '#{bm_filepath}')"
end

File.write filename, <<-RUBY
require 'spec_helper'
#{enter_benchmarking_mode}
#{requires.join("\n ")}
OSpecRunner.main.did_finish
RUBY
end

def bm_filepath
mkdir_p 'tmp/bench'
index = 0
begin
index += 1
bm_filepath = "tmp/bench/Spec#{index}"
end while File.exist?(bm_filepath)
end
end

task :mspec_phantom do
filename = File.expand_path('tmp/mspec_phantom.rb')
runner = "#{__dir__}/testing/phantomjs1-sprockets.js"
port = 9999
url = "http://localhost:#{port}/"


Testing.write_file filename, Testing.specs
mkdir_p File.dirname(filename)

Testing.stubs.each {|s| ::Opal::Processor.stub_file s }

Opal::Config.arity_check_enabled = true
Opal::Config.freezing_stubs_enabled = false
Opal::Config.tainting_stubs_enabled = false
Opal::Config.dynamic_require_severity = :error

Opal.use_gem 'mspec'
Opal.append_path 'spec'
Opal.append_path 'lib'
Opal.append_path File.dirname(filename)

app = Opal::Server.new { |s| s.main = File.basename(filename) }
server = Thread.new { Rack::Server.start(app: app, Port: port) }
sleep 1

begin
sh 'phantomjs', runner, url
ensure
server.kill if server.alive?
end
end

desc <<-DESC
Run the MSpec test suite on node
Run the MSpec test suite on Node.js
Use PATTERN and env var to manually set the glob for specs:
@@ -20,66 +122,17 @@ Use PATTERN and env var to manually set the glob for specs:
env PATTERN="spec/rubyspec/core/numeric/**_spec.rb" rake mspec_node
DESC
task :mspec_node do
excepting = []
rubyspecs = File.read('spec/rubyspecs').lines.reject do |l|
l.strip!; l.start_with?('#') || l.empty? || (l.start_with?('!') && excepting.push(l.sub('!', 'spec/') + '.rb'))
end.flat_map do |path|
path = "spec/#{path}"
File.directory?(path) ? Dir[path+'/*.rb'] : "#{path}.rb"
end - excepting

filters = Dir['spec/filters/**/*.rb']
shared = Dir['spec/{opal,lib/parser}/**/*_spec.rb'] + ['spec/lib/lexer_spec.rb']

specs = []
add_specs = ->(name, new_specs) { p [new_specs.size, name]; specs + new_specs}

specs = add_specs.(:filters, filters)
pattern = ENV['PATTERN']
whitelist_pattern = !!ENV['RUBYSPECS']

if pattern
custom = Dir[pattern]
custom &= rubyspecs if whitelist_pattern
specs = add_specs.(:custom, custom)
elsif ENV['SUITE'] == 'opal'
specs = add_specs.(:shared, shared)
elsif ENV['SUITE'] == 'rubyspec'
specs = add_specs.(:rubyspecs, rubyspecs)
else
warn 'Please provide at lease one of the following ENV vars:'
warn 'PATTERN # e.g. env PATTERN="spec/rubyspec/core/numeric/**_spec.rb"'
warn 'SUITE # can be either SUITE=opal or SUITE=rubyspec'
exit 1
end

requires = specs.map{|s| "require '#{s.sub(/^spec\//,'')}'"}
include_paths = '-Ispec -Ilib'

filename = 'tmp/mspec_node.rb'
js_filename = 'tmp/mspec_node.js'
mkdir_p File.dirname(filename)
bm_filepath = Testing.bm_filepath if ENV['BM']
Testing.write_file filename, Testing.specs, bm_filepath

if ENV['BM']
mkdir_p 'tmp/bench'
index = 0
begin
index += 1
bm_filepath = "tmp/bench/Spec#{index}"
end while File.exist?(bm_filepath)
enter_benchmarking_mode = "OSpecRunner.main.bm!(#{Integer(ENV['BM'])}, '#{bm_filepath}')"
end

File.write filename, <<-RUBY
require 'spec_helper'
#{enter_benchmarking_mode}
#{requires.join("\n ")}
OSpecRunner.main.did_finish
RUBY

stubs = '-smspec/helpers/tmp -smspec/helpers/environment -smspec/guards/block_device -smspec/guards/endian'
stubs = Testing.stubs.map{|s| "-s#{s}"}.join(' ')

sh "ruby -rbundler/setup -rmspec/opal/special_calls "\
sh "ruby -rbundler/setup -r#{__dir__}/testing/mspec_special_calls "\
"bin/opal -gmspec #{include_paths} #{stubs} -rnodejs/io -rnodejs/kernel -Dwarning -A #{filename} -c > #{js_filename}"
sh "NODE_PATH=stdlib/nodejs/node_modules node #{js_filename}"

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -3,6 +3,17 @@
*/
var args = phantom.args;
var page = require('webpage').create();
var url = args[0];


/*
* Exit phantom instance "safely" see - https://github.com/ariya/phantomjs/issues/12697
* https://github.com/nobuoka/gulp-qunit/commit/d242aff9b79de7543d956e294b2ee36eda4bac6c
*/
function phantom_exit(code) {
page.close();
setTimeout(function () { phantom.exit(code); }, 0);
}

page.onConsoleMessage = function(msg) {
console.log(msg);
@@ -19,7 +30,7 @@ page.onCallback = function(data) {
switch (data[0]) {
case 'exit':
var status = data[1] || 0;
phantom.exit(status);
phantom_exit(status);
case 'stdout':
system.stdout.write(data[1] || '');
break;
@@ -31,25 +42,25 @@ page.onCallback = function(data) {
}
};

page.open(args[0], function(status) {
page.open(url, function(status) {
if (status !== 'success') {
console.error("Cannot load: " + args[0]);
phantom.exit(1);
console.error("Cannot load: " + url);
phantom_exit(1);
} else {
var timeout = parseInt(args[1] || 60000, 10);
var start = Date.now();
var interval = setInterval(function() {
if (Date.now() > start + timeout) {
console.error("Specs timed out");
phantom.exit(124);
phantom_exit(124);
} else {
var code = page.evaluate(function() {
return window.OPAL_SPEC_CODE;
});

if (code === 0 || code === 1) {
clearInterval(interval);
phantom.exit(code);
phantom_exit(code);
}
}
}, 500);