Skip to content

Commit

Permalink
Bootstrapped compiler error messages regressed
Browse files Browse the repository at this point in the history
The exception started slipping through the rescue in compiler.rb

Ultimately that needs to be fixed (along with validating whether
SyntaxError or RuntimeError should be what's raised). For now, make the
compiler specs runnable in Opal and filter what does not currently
pass (regex, __FILE__ issues)

Add matchers to fill in for RSpec, stub out RSpec helper, fix not_to
bridge

Apply change/test from opal#1075
  • Loading branch information
wied03 committed Apr 9, 2016
1 parent 919e434 commit b1fdbf9
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Whitespace conventions:

### Fixed

- `SourceMap::VLQ` patch (#1075)
- `Regexp::new` no longer throws error when the expression ends in \\\\
- `super` works properly with overwritten alias methods (#1384)
- `NoMethodError` does not need a name to be instantiated
Expand Down
2 changes: 1 addition & 1 deletion lib/opal/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def compile
@fragments = process(@sexp).flatten

@result = @fragments.map(&:code).join('')
rescue => error
rescue Exception => error
message = "An error occurred while compiling: #{self.file}\n#{error.message}"
raise error.class, message, error.backtrace
end
Expand Down
6 changes: 6 additions & 0 deletions spec/filters/bugs/compiler_opal.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
opal_filter "compiler (opal)" do
fails 'Opal::Compiler should compile undef calls'
fails 'Opal::Compiler method names when function name is reserved generates a valid named function for method'
fails 'Opal::Compiler pre-processing require-ish methods #require_relative parses and resolve #require_relative argument'
fails 'Opal::Compiler pre-processing require-ish methods #require_tree parses and resolve #require argument'
end
8 changes: 7 additions & 1 deletion spec/lib/compiler_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'lib/spec_helper'
require 'support/match_helpers'

describe Opal::Compiler do
describe 'requiring' do
Expand All @@ -20,6 +21,10 @@
end
end

it 'raises syntax errors properly' do
expect(lambda {Opal::Compiler.new('def foo').compile}).to raise_error Exception, /An error occurred while compiling:.*false/m
end

it "should compile simple ruby values" do
expect_compiled("3.142").to include("return 3.142")
expect_compiled("123e1").to include("return 1230")
Expand Down Expand Up @@ -143,9 +148,10 @@

describe '#require_tree' do
require 'pathname'
let(:file) { Pathname(__FILE__).join('../fixtures/require_tree_test.rb') }

it 'parses and resolve #require argument' do
file = Pathname(__FILE__).join('../fixtures/require_tree_test.rb')

compiler = compiler_for(file.read)
expect(compiler.required_trees).to eq(['../fixtures/required_tree_test'])
end
Expand Down
8 changes: 8 additions & 0 deletions spec/opal/stdlib/source_map_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'spec_helper'
require 'source_map'

describe 'SourceMap::VLQ' do
it 'encodes properly' do
SourceMap::VLQ.encode([0]).should == 'A'
end
end
57 changes: 57 additions & 0 deletions spec/support/match_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
module MatchHelpers
class MatchMatcher
def initialize(expected)
fail "Expected #{expected} to be a Regexp!" unless expected.is_a?(Regexp)
@expected = expected
end

def matches?(actual)
@actual = actual
@expected.match(@actual)
end

def failure_message
["Expected #{@actual.inspect} (#{@actual.class})",
"to match #{@expected}"]
end

def negative_failure_message
["Expected #{@actual.inspect} (#{@actual.class})",
"not to match #{@expected}"]
end
end

class EndWithHelper
def initialize(expected)
@expected = expected
end

def matches?(actual)
@actual = actual
@actual.end_with?(@expected)
end

def failure_message
["Expected #{@actual.inspect} (#{@actual.class})",
"to end with #{@expected}"]
end

def negative_failure_message
["Expected #{@actual.inspect} (#{@actual.class})",
"not to end with #{@expected}"]
end
end
end

if !defined? RSpec
class Object
def match(expected)
MatchHelpers::MatchMatcher.new(expected)
end

def end_with(expected)
MatchHelpers::EndWithHelper.new(expected)
end
end
end

2 changes: 1 addition & 1 deletion spec/support/mspec_rspec_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def apply_expectation(type, expectation)
end
end

def not_to
def not_to(expectation)
apply_expectation(:should_not, expectation)
end
alias to_not not_to
Expand Down
5 changes: 3 additions & 2 deletions stdlib/source_map/vlq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ def self.encode(ary)
result = []
ary.each do |n|
vlq = n < 0 ? ((-n) << 1) + 1 : n << 1
begin
loop do
digit = vlq & VLQ_BASE_MASK
vlq >>= VLQ_BASE_SHIFT
digit |= VLQ_CONTINUATION_BIT if vlq > 0
result << BASE64_DIGITS[digit]
end while vlq > 0
break unless vlq > 0
end
end
result.join
end
Expand Down
3 changes: 2 additions & 1 deletion tasks/testing.rake
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module Testing
mspec/guards/block_device
mspec/guards/endian
a_file
lib/spec_helper
]
end

Expand All @@ -35,7 +36,7 @@ module Testing
File.directory?(path) ? Dir[path+'/*.rb'] : "#{path}.rb"
end - excepting

opalspecs = Dir['spec/{opal,lib/parser}/**/*_spec.rb'] + ['spec/lib/lexer_spec.rb']
opalspecs = Dir['spec/{opal,lib/parser}/**/*_spec.rb'] + ['spec/lib/lexer_spec.rb', 'spec/lib/compiler_spec.rb']
userspecs = Dir[pattern] if pattern
userspecs &= rubyspecs if whitelist_pattern

Expand Down

0 comments on commit b1fdbf9

Please sign in to comment.