diff --git a/lib/lrama/option_parser.rb b/lib/lrama/option_parser.rb index d8ed62ee..c73322ef 100644 --- a/lib/lrama/option_parser.rb +++ b/lib/lrama/option_parser.rb @@ -22,10 +22,10 @@ def parse(argv) if @options.grammar_file == '-' @options.grammar_file = argv.shift or abort "File name for STDIN should be specified\n" - else - @options.y = File.open(@options.grammar_file, 'r') end + @options.y = File.open(@options.grammar_file, 'r') + if !@report.empty? && @options.report_file.nil? && @options.grammar_file @options.report_file = File.dirname(@options.grammar_file) + "/" + File.basename(@options.grammar_file, ".*") + ".output" end diff --git a/spec/lrama/command_spec.rb b/spec/lrama/command_spec.rb index 204faad8..abb20391 100644 --- a/spec/lrama/command_spec.rb +++ b/spec/lrama/command_spec.rb @@ -17,7 +17,7 @@ File.open(fixture_path("command/basic.y")) do |f| allow(STDIN).to receive(:read).and_return(f.read) command = Lrama::Command.new - expect(command.run(o_option + ["-", "test.y"])).to be_nil + expect(command.run(o_option + ["-", fixture_path("command/basic.y")])).to be_nil end end end diff --git a/spec/lrama/option_parser_spec.rb b/spec/lrama/option_parser_spec.rb index 06432fdf..22aab83d 100644 --- a/spec/lrama/option_parser_spec.rb +++ b/spec/lrama/option_parser_spec.rb @@ -84,9 +84,9 @@ context "file name is specified after '-'" do it "@grammar_file is file name" do option_parser = Lrama::OptionParser.new - option_parser.send(:parse, ["-", "test.y"]) + option_parser.send(:parse, ["-", fixture_path("command/basic.y")]) options = option_parser.instance_variable_get(:@options) - expect(options.grammar_file).to eq "test.y" + expect(options.grammar_file).to eq fixture_path("command/basic.y") end end end @@ -95,7 +95,7 @@ context "output option is not passed" do it "@outfile is default value" do option_parser = Lrama::OptionParser.new - option_parser.send(:parse, ["-", "test.y"]) + option_parser.send(:parse, ["-", fixture_path("command/basic.y")]) options = option_parser.instance_variable_get(:@options) expect(options.outfile).to eq "y.tab.c" end @@ -104,7 +104,7 @@ context "output option is passed" do it "@outfile is same with passed value" do option_parser = Lrama::OptionParser.new - option_parser.send(:parse, ["-o", "parse.c", "-", "test.y"]) + option_parser.send(:parse, ["-o", "parse.c", "-", fixture_path("command/basic.y")]) options = option_parser.instance_variable_get(:@options) expect(options.outfile).to eq "parse.c" end @@ -116,7 +116,7 @@ context "outfile option is passed" do it "@header_file is set based on outfile" do option_parser = Lrama::OptionParser.new - option_parser.send(:parse, ["-h", "-o", "parse.c", "-", "test.y"]) + option_parser.send(:parse, ["-h", "-o", "parse.c", "-", fixture_path("command/basic.y")]) options = option_parser.instance_variable_get(:@options) expect(options.header_file).to eq "./parse.h" end @@ -125,7 +125,7 @@ context "outfile option is not passed" do it "@header_file is set based on outfile default value" do option_parser = Lrama::OptionParser.new - option_parser.send(:parse, ["-h", "-", "test.y"]) + option_parser.send(:parse, ["-h", "-", fixture_path("command/basic.y")]) options = option_parser.instance_variable_get(:@options) expect(options.header_file).to eq "./y.tab.h" end @@ -135,7 +135,7 @@ context "header file name is passed" do it "@header_file is same with passed value" do option_parser = Lrama::OptionParser.new - option_parser.send(:parse, ["-hparse.h", "-", "test.y"]) + option_parser.send(:parse, ["-hparse.h", "-", fixture_path("command/basic.y")]) options = option_parser.instance_variable_get(:@options) expect(options.header_file).to eq "parse.h" end @@ -151,9 +151,9 @@ expect(options.report_file).to match(/command\/basic\.output/) option_parser = Lrama::OptionParser.new - option_parser.send(:parse, ["--report=all", "-", "test.y"]) + option_parser.send(:parse, ["--report=all", "-", fixture_path("command/basic.y")]) options = option_parser.instance_variable_get(:@options) - expect(options.report_file).to eq "./test.output" + expect(options.report_file).to eq fixture_path("command/basic.output") end end @@ -165,7 +165,7 @@ expect(options.report_file).to eq "report.output" option_parser = Lrama::OptionParser.new - option_parser.send(:parse, ["--report-file=report.output", "-", "test.y"]) + option_parser.send(:parse, ["--report-file=report.output", "-", fixture_path("command/basic.y")]) options = option_parser.instance_variable_get(:@options) expect(options.report_file).to eq "report.output" end