diff options
author | makoto kuwata <kwa@kuwata-lab.com> | 2009-07-15 18:49:34 +0900 |
---|---|---|
committer | makoto kuwata <kwa@kuwata-lab.com> | 2009-07-15 18:49:34 +0900 |
commit | dd9c9ae791bcd086af414c964a1cc7c59be5d8c0 (patch) | |
tree | 1940234c992b9d8ee80ca2d3476c2e30a54645ea | |
parent | 74015d82a8a505f43c0c2beb6f7befb9a35e7d87 (diff) | |
download | erubis-dd9c9ae791bcd086af414c964a1cc7c59be5d8c0.tar.gz |
[bugfix] 'main.rb' to 'erubis -z' prints 'Syntax OK' correctly
-rw-r--r-- | lib/erubis/main.rb | 4 | ||||
-rw-r--r-- | test/test-main.rb | 24 |
2 files changed, 27 insertions, 1 deletions
diff --git a/lib/erubis/main.rb b/lib/erubis/main.rb index 5234944..c8f1ff5 100644 --- a/lib/erubis/main.rb +++ b/lib/erubis/main.rb @@ -468,7 +468,9 @@ module Erubis def check_syntax(filename, src) require 'open3' - command = (ENV['_'] || 'ruby') + ' -wc' # ENV['_'] stores command name + #command = (ENV['_'] || 'ruby') + ' -wc' # ENV['_'] stores command name + bin = ENV['_'] && File.basename(ENV['_']) =~ /^ruby/ ? ENV['_'] : 'ruby' + command = bin + ' -wc' stdin, stdout, stderr = Open3.popen3(command) stdin.write(src) stdin.close diff --git a/test/test-main.rb b/test/test-main.rb index 5db3f52..5fe62ac 100644 --- a/test/test-main.rb +++ b/test/test-main.rb @@ -201,11 +201,35 @@ END end + def _with_dummy_file + bindir = File.join(File.dirname(File.dirname(__FILE__)), 'bin') + env_path = ENV['PATH'] + env__ = ENV['_'] + begin + ENV['PATH'] = bindir + File::PATH_SEPARATOR + ENV['PATH'] + ENV['_'] = 'erubis' + Tempfile.open(self.name.gsub(/[^\w]/,'_')) do |f| + f.write(INPUT) + f.flush + yield(f.path) + end + ensure + ENV['PATH'] = env_path + ENV['_'] = env__ if env__ + end + end + + def test_syntax1 # -z (syntax ok) @input = INPUT @expected = "Syntax OK\n" @options = '-z' _test() + # + _with_dummy_file do |filepath| + actual = `erubis #{@options} #{filepath}` + assert_equal @expected, actual + end end |