Skip to content

Commit

Permalink
Show the shard's name when running scripts (crystal-lang#326)
Browse files Browse the repository at this point in the history
* Show the shard's name when running scripts

* Add script and dependency name on failure. Add specs
  • Loading branch information
Brian J. Cardiff authored and taylor committed Aug 11, 2020
1 parent aa44c25 commit 233af25
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/resolvers/resolver.cr
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ module Shards

def run_script(name)
if installed? && (command = installed_spec.try(&.scripts[name]?))
Shards.logger.info "#{name.capitalize} #{command}"
Script.run(install_path, command)
Shards.logger.info "#{name.capitalize} of #{dependency.name}: #{command}"
Script.run(install_path, command, name, dependency.name)
end
end

Expand Down
4 changes: 2 additions & 2 deletions src/script.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ module Shards
class Error < Error
end

def self.run(path, command)
def self.run(path, command, script_name, dependency_name)
Dir.cd(path) do
output = IO::Memory.new
status = Process.run("/bin/sh", input: IO::Memory.new(command), output: output, error: output)
raise Error.new("Failed #{command}:\n#{output.to_s.rstrip}") unless status.success?
raise Error.new("Failed #{script_name} of #{dependency_name} on #{command}:\n#{output.to_s.rstrip}") unless status.success?
end
end
end
Expand Down
5 changes: 3 additions & 2 deletions test/integration/install_test.cr
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,16 @@ class InstallCommandTest < Minitest::Test

def test_runs_postinstall_script
with_shard({dependencies: {post: "*"}}) do
run "shards install"
output = run "shards install --no-color", capture: true
assert File.exists?(File.join(application_path, "lib", "post", "made.txt"))
assert_match "Postinstall of post: make", output
end
end

def test_prints_details_and_removes_dependency_when_postinstall_script_fails
with_shard({dependencies: {fails: "*"}}) do
ex = assert_raises(FailedCommand) { run "shards install --no-color" }
assert_match "E: Failed make:\n", ex.stdout
assert_match "E: Failed postinstall of fails on make:\n", ex.stdout
assert_match "test -n ''\n", ex.stdout
refute Dir.exists?(File.join(application_path, "lib", "fails"))
end
Expand Down

0 comments on commit 233af25

Please sign in to comment.