Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: output STDERR from the building process #540

Merged
merged 6 commits into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
17 changes: 17 additions & 0 deletions spec/integration/build_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,23 @@ describe "build" do
end
end

{% unless flag?(:win32) %}
it "reports warning without failing" do
File.write File.join(application_path, "src", "cli.cr"), <<-CODE
@[Deprecated]
def a
end
a
CODE

Dir.cd(application_path) do
err = run "shards build --no-color app"
err.should match(/eprecated/)
File.exists?(bin_path("app")).should be_true
end
end
{% end %}

it "errors when no targets defined" do
File.write File.join(application_path, "shard.yml"), <<-YAML
name: build
Expand Down
5 changes: 3 additions & 2 deletions spec/support/factories.cr
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def tmp_path
Shards::Specs.tmp_path
end

def run(command, *, env = nil)
def run(command, *, env = nil, return_error = false)
beta-ziliani marked this conversation as resolved.
Show resolved Hide resolved
cmd_env = {
"CRYSTAL_PATH" => Shards::Specs.crystal_path,
}
Expand All @@ -255,7 +255,8 @@ def run(command, *, env = nil)
status = Process.run(command, shell: true, env: cmd_env, output: output, error: error || Process::Redirect::Close)

if status.success?
output.to_s.gsub("\r\n", "\n")
output = output.to_s.gsub("\r\n", "\n")
output + error.to_s
straight-shoota marked this conversation as resolved.
Show resolved Hide resolved
else
raise FailedCommand.new("command failed: #{command}", output.to_s.gsub("\r\n", "\n"), error.to_s.gsub("\r\n", "\n"))
end
Expand Down
7 changes: 5 additions & 2 deletions src/commands/build.cr
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ module Shards
Log.debug { "#{Shards.crystal_bin} #{args.join(' ')}" }

error = IO::Memory.new

status = Process.run(Shards.crystal_bin, args: args, output: Process::Redirect::Inherit, error: error)
raise Error.new("Error target #{target.name} failed to compile:\n#{error}") unless status.success?
unless status.success?
straight-shoota marked this conversation as resolved.
Show resolved Hide resolved
raise Error.new("Error target #{target.name} failed to compile:\n#{error}")
else
STDERR << error if error.size > 0
straight-shoota marked this conversation as resolved.
Show resolved Hide resolved
end
end
end
end
Expand Down