Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions spec/primitives/external_command_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{% skip_file if flag?(:interpreted) %}

require "../spec_helper"

describe Crystal::Command do
it "exec external commands", tags: %w[slow] do
with_temp_executable "crystal-external" do |path|
with_tempfile "crystal-external.cr" do |source_file|
File.write source_file, <<-CRYSTAL
puts ENV["CRYSTAL"]?
puts PROGRAM_NAME
puts ARGV
CRYSTAL

Process.run(ENV["CRYSTAL_SPEC_COMPILER_BIN"]? || "bin/crystal", ["build", source_file, "-o", path])
end

File.exists?(path).should be_true

process = Process.new(ENV["CRYSTAL_SPEC_COMPILER_BIN"]? || "bin/crystal",
["external", "foo", "bar"],
output: :pipe,
env: {"PATH" => {ENV["PATH"], File.dirname(path)}.join(Process::PATH_DELIMITER)}
)
output = process.output.gets_to_end
status = process.wait
status.success?.should be_true
lines = output.lines
lines[0].should match /crystal/
lines[1].should match /crystal-external/
lines[2].should eq %(["foo", "bar"])
end
end
end
3 changes: 3 additions & 0 deletions src/compiler/crystal/command.cr
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ class Crystal::Command
else
if command.ends_with?(".cr")
error "file '#{command}' does not exist"
elsif external_command = Process.find_executable("crystal-#{command}")
options.shift
Process.exec(external_command, options, env: {"CRYSTAL" => Process.executable_path})
else
error "unknown command: #{command}"
end
Expand Down