diff --git a/lib/laser/analysis/sexp.rb b/lib/laser/analysis/sexp.rb index 5b5155d..cae33fa 100644 --- a/lib/laser/analysis/sexp.rb +++ b/lib/laser/analysis/sexp.rb @@ -98,14 +98,18 @@ def all_errors # Performs a DFS on the node, yielding each subnode (including the given node) # in DFS order. def dfs - yield self - self.children.each do |child| - next unless is_sexp?(child) - case child[0] - when Array - child.each { |x| x.dfs { |y| yield y}} - when ::Symbol - child.dfs { |y| yield y } + stack = [self] + while node = stack.pop + yield node + + node.children.reverse.each do |child| + next unless is_sexp?(child) + case child[0] + when Array + child.reverse.each { |x| stack.push(x) } + when ::Symbol + stack.push(child) + end end end end diff --git a/lib/laser/analysis/sexp_extensions/constant_extraction.rb b/lib/laser/analysis/sexp_extensions/constant_extraction.rb index ded9249..13c62c3 100644 --- a/lib/laser/analysis/sexp_extensions/constant_extraction.rb +++ b/lib/laser/analysis/sexp_extensions/constant_extraction.rb @@ -45,9 +45,11 @@ def constant_value str = self[1] pos = self.parent.parent.source_begin first_two = lines[pos[0]-1][pos[1],2] - if first_two[0,1] == '"' || first_two == '%Q' + if first_two[0,1] == '"' eval(%Q{"#{str}"}) - else + elsif first_two == '%Q' + eval("%Q{#{str}}") + else str end when :string_content diff --git a/lib/laser/runner.rb b/lib/laser/runner.rb index b93d924..7aa127c 100644 --- a/lib/laser/runner.rb +++ b/lib/laser/runner.rb @@ -75,7 +75,7 @@ def get_settings opt :stdin, 'Read Ruby code from standard input', short: '-s' opt :'list-modules', 'Print the discovered, loaded modules' opt :profile, 'Run the profiler during execution' - opt :include, 'specify $LOAD_PATH directory (may be used more than once)', short: '-I', multi: true + opt :include, 'specify $LOAD_PATH directory (may be used more than once)', short: '-I', multi: true, type: :string opt :S, 'look for scripts using PATH environment variable', short: '-S' warning_opts.each { |warning| opt(*warning) } end diff --git a/spec/analysis_specs/sexp_extension_specs/constant_extraction_spec.rb b/spec/analysis_specs/sexp_extension_specs/constant_extraction_spec.rb index d8769a3..ab28bd8 100644 --- a/spec/analysis_specs/sexp_extension_specs/constant_extraction_spec.rb +++ b/spec/analysis_specs/sexp_extension_specs/constant_extraction_spec.rb @@ -93,6 +93,14 @@ list[0][2].is_constant.should be true list[0][2].constant_value.should == 'abc \n \x12def' end + + it 'should not be fooled by quotes inside %Q{}' do + input = 'a = %Q{"}' + tree = annotate_all(input) + list = tree[1] + list[0][2].is_constant.should be true + list[0][2].constant_value.should == '"' + end end describe 'handling integer literals' do diff --git a/spec/runner_spec.rb b/spec/runner_spec.rb index 4a08c14..fd794ab 100644 --- a/spec/runner_spec.rb +++ b/spec/runner_spec.rb @@ -141,6 +141,12 @@ settings[:"report-fixed"].should be_true settings[:"report-fixed_given"].should be_true end + + it 'has a --include option' do + runner = Runner.new(['--include=/some/path', '-I', '/another/path']) + settings = runner.swizzling_argv { runner.get_settings } + settings[:include].should == ["/some/path", "/another/path"] + end end describe '#handle_global_options' do