diff --git a/lib/lrama/command.rb b/lib/lrama/command.rb index 2ebe1d89..45670ae4 100644 --- a/lib/lrama/command.rb +++ b/lib/lrama/command.rb @@ -5,7 +5,6 @@ class Command def initialize(argv) @argv = argv - @version = nil @skeleton = "bison/yacc.c" @header = false @header_file = nil @@ -23,11 +22,6 @@ def initialize(argv) def run parse_option - if @version - puts Lrama::VERSION - exit 0 - end - Report::Duration.enable if @trace_opts[:time] warning = Lrama::Warning.new @@ -113,7 +107,7 @@ def parse_option opt = OptionParser.new # opt.on('-h') {|v| p v } - opt.on('-V', '--version') {|v| @version = true } + opt.on('-V', '--version') {|v| puts "lrama #{Lrama::VERSION}"; exit 0 } # Tuning the Parser opt.on('-S', '--skeleton=FILE') {|v| @skeleton = v } diff --git a/spec/lrama/command_spec.rb b/spec/lrama/command_spec.rb index a4f7d423..d532ba74 100644 --- a/spec/lrama/command_spec.rb +++ b/spec/lrama/command_spec.rb @@ -1,4 +1,15 @@ +require "open3" + RSpec.describe Lrama::Command do + describe "version option" do + it "print Lrama version and exit" do + result = Open3.popen3("ruby", exe_path("lrama"), "--version") do |stdin, stdout, stderr, wait_thr| + stdout.read + end + expect(result).to eq("lrama #{Lrama::VERSION}\n") + end + end + describe "#run" do describe "a grammar file is specified" do it "ends successfully" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b895709b..c7035804 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -30,3 +30,7 @@ def fixture_path(file_name) File.expand_path("../fixtures/#{file_name}", __FILE__) end + +def exe_path(file_name) + File.expand_path("../../exe/#{file_name}", __FILE__) +end