Skip to content

Commit 1c648e5

Browse files
author
Brian J. Cardiff
authored
Show the shard's name when running scripts (#326)
* Show the shard's name when running scripts * Add script and dependency name on failure. Add specs
1 parent 37ba55e commit 1c648e5

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

src/resolvers/resolver.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ module Shards
4242

4343
def run_script(name)
4444
if installed? && (command = installed_spec.try(&.scripts[name]?))
45-
Shards.logger.info "#{name.capitalize} #{command}"
46-
Script.run(install_path, command)
45+
Shards.logger.info "#{name.capitalize} of #{dependency.name}: #{command}"
46+
Script.run(install_path, command, name, dependency.name)
4747
end
4848
end
4949

src/script.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ module Shards
33
class Error < Error
44
end
55

6-
def self.run(path, command)
6+
def self.run(path, command, script_name, dependency_name)
77
Dir.cd(path) do
88
output = IO::Memory.new
99
status = Process.run("/bin/sh", input: IO::Memory.new(command), output: output, error: output)
10-
raise Error.new("Failed #{command}:\n#{output.to_s.rstrip}") unless status.success?
10+
raise Error.new("Failed #{script_name} of #{dependency_name} on #{command}:\n#{output.to_s.rstrip}") unless status.success?
1111
end
1212
end
1313
end

test/integration/install_test.cr

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,15 +295,16 @@ class InstallCommandTest < Minitest::Test
295295

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

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

0 commit comments

Comments
 (0)