mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Add tests
This commit is contained in:
parent
7d34717ccd
commit
6fc99d9569
@ -37,9 +37,9 @@ module Homebrew
|
|||||||
sig { returns(CLI::Args) }
|
sig { returns(CLI::Args) }
|
||||||
attr_reader :args
|
attr_reader :args
|
||||||
|
|
||||||
sig { void }
|
sig { params(argv: T::Array[String]).void }
|
||||||
def initialize
|
def initialize(argv = ARGV.freeze)
|
||||||
@args = T.let(CLI::Parser.new(&self.class.parser_block).parse, CLI::Args)
|
@args = T.let(CLI::Parser.new(&self.class.parser_block).parse(argv), CLI::Args)
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { abstract.void }
|
sig { abstract.void }
|
||||||
|
56
Library/Homebrew/test/abstract_command_spec.rb
Normal file
56
Library/Homebrew/test/abstract_command_spec.rb
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "abstract_command"
|
||||||
|
|
||||||
|
RSpec.describe Homebrew::AbstractCommand do
|
||||||
|
describe "subclasses" do
|
||||||
|
before do
|
||||||
|
cat = Class.new(described_class) do
|
||||||
|
cmd_args do
|
||||||
|
switch "--foo"
|
||||||
|
flag "--bar="
|
||||||
|
end
|
||||||
|
def run; end
|
||||||
|
end
|
||||||
|
stub_const("Cat", cat)
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "parsing args" do
|
||||||
|
it "parses valid args" do
|
||||||
|
expect { Cat.new(["--foo"]).run }.not_to raise_error
|
||||||
|
end
|
||||||
|
|
||||||
|
it "allows access to args" do
|
||||||
|
expect(Cat.new(["--bar", "baz"]).args[:bar]).to eq("baz")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "raises on invalid args" do
|
||||||
|
expect { Cat.new(["--bat"]) }.to raise_error(OptionParser::InvalidOption)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "command names" do
|
||||||
|
it "has a default command name" do
|
||||||
|
expect(Cat.command_name).to eq("cat")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "can lookup command" do
|
||||||
|
expect(described_class.command("cat")).to be(Cat)
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "when command name is overridden" do
|
||||||
|
before do
|
||||||
|
tac = Class.new(described_class) do
|
||||||
|
def self.command_name = "t-a-c"
|
||||||
|
def run; end
|
||||||
|
end
|
||||||
|
stub_const("Tac", tac)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "can be looked up by command name" do
|
||||||
|
expect(described_class.command("t-a-c")).to be(Tac)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
4
Library/Homebrew/test/abstract_command_spec.rbi
Normal file
4
Library/Homebrew/test/abstract_command_spec.rbi
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# typed: strict
|
||||||
|
|
||||||
|
class Cat < Homebrew::AbstractCommand; end
|
||||||
|
class Tac < Homebrew::AbstractCommand; end
|
Loading…
x
Reference in New Issue
Block a user