Skip to content

Commit

Permalink
Fix a freeze when specified grammar_file is '-' with file path
Browse files Browse the repository at this point in the history
  • Loading branch information
ydah committed Oct 15, 2023
1 parent be55952 commit 65e693f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions lib/lrama/option_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/lrama/command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions spec/lrama/option_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand Down

0 comments on commit 65e693f

Please sign in to comment.