File: subcommand_spec.cr

package info (click to toggle)
shards 0.19.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 904 kB
  • sloc: makefile: 117
file content (41 lines) | stat: -rw-r--r-- 1,248 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require "./spec_helper"

describe "subcommand" do
  it "forwards all arguments to subcommand" do
    create_shard("dummy", "0.1.0")
    {% if flag?(:win32) %}
      create_executable "dummy", "bin/shards-dummy", %(print ARGV.join(" "))
    {% else %}
      path = create_file("dummy", "bin/shards-dummy", "#!/bin/sh\necho $@\n")
      File.chmod(path, 0o755)
    {% end %}

    with_path(git_path("dummy/bin")) do
      output = run("shards dummy --no-color --verbose --unknown other argument")
      output.should contain(%(--no-color --verbose --unknown other argument))
    end
  end

  it "correctly forwards '--help' option to subcommand" do
    create_shard("dummy", "0.1.0")
    {% if flag?(:win32) %}
      create_executable "dummy", "bin/shards-dummy", %(print ARGV.join(" "))
    {% else %}
      path = create_file("dummy", "bin/shards-dummy", "#!/bin/sh\necho $@\n")
      File.chmod(path, 0o755)
    {% end %}

    with_path(git_path("dummy/bin")) do
      output = run("shards dummy --help")
      output.should contain(%(--help))
    end
  end
end

private def with_path(path, &)
  old_path = ENV["PATH"]
  ENV["PATH"] = "#{File.expand_path(path)}#{Process::PATH_DELIMITER}#{ENV["PATH"]}"
  yield
ensure
  ENV["PATH"] = old_path
end