diff --git a/spec/compiler/compiler_spec.cr b/spec/compiler/compiler_spec.cr index 56746736b7b1..071bba3df1c2 100644 --- a/spec/compiler/compiler_spec.cr +++ b/spec/compiler/compiler_spec.cr @@ -27,4 +27,15 @@ describe "Compiler" do end end end + + it "treats all arguments post-filename as program arguments" do + with_tempfile "args_test" do |path| + `bin/crystal '#{compiler_datapath}/args_test' -Dother_flag -- bar '#{path}'` + + File.read(path).should eq(<<-FILE) + ["-Dother_flag", "--", "bar"] + {other_flag: false} + FILE + end + end end diff --git a/spec/compiler/data/args_test b/spec/compiler/data/args_test new file mode 100644 index 000000000000..86efc6f59fbb --- /dev/null +++ b/spec/compiler/data/args_test @@ -0,0 +1,7 @@ +# Last argument is file path to write +test_path = ARGV.pop +File.open(test_path, "w") do |f| + ARGV.inspect(f) + f.puts + {other_flag: {{flag?(:other_flag)}}}.inspect(f) +end diff --git a/src/compiler/crystal/command.cr b/src/compiler/crystal/command.cr index 497682293486..7a6d5b3f60aa 100644 --- a/src/compiler/crystal/command.cr +++ b/src/compiler/crystal/command.cr @@ -462,6 +462,13 @@ class Crystal::Command filenames << stdin_filename end + if single_file + opts.before_each do |arg| + opts.stop if !arg.starts_with?('-') && arg.ends_with?(".cr") + opts.stop if File.file?(arg) + end + end + opts.unknown_args do |before, after| opt_filenames = before opt_arguments = after