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

fix: Fix error message when failing assertion of the toys version #250

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion toys-core/lib/toys/dsl/tool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1820,7 +1820,7 @@ def toys_version!(*requirements)
requirement = ::Gem::Requirement.new(*requirements)
unless requirement.satisfied_by?(version)
raise Toys::ToolDefinitionError,
"Toys version requirements #{requirement} not satisfied by {version}"
"Toys version requirements #{requirement} not satisfied by #{version}"
end
self
end
Expand Down
78 changes: 40 additions & 38 deletions toys-core/test/test_dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,13 @@ def run
end

it "doesn't execute the block if not needed" do
test = self
t = self
loader.add_block do
tool "foo" do
long_desc "hello", "world"
end
tool "bar" do
test.fail
t.flunk
end
end
tool, remaining = loader.lookup(["foo"])
Expand Down Expand Up @@ -396,10 +396,10 @@ def run

describe "include directive" do
it "supports normal modules" do
test = self
t = self
loader.add_block do
include ::FileUtils
test.assert_equal(true, include?(::FileUtils))
t.assert_equal(true, include?(::FileUtils))
end
tool, _remaining = loader.lookup([])
assert_equal(true, tool.tool_class.include?(::FileUtils))
Expand All @@ -416,10 +416,10 @@ def run
end

it "does not allow multiple inclusion of the same module" do
test = self
t = self
loader.add_block do
include :terminal, styled: true
test.assert_raises(Toys::ToolDefinitionError) do
t.assert_raises(Toys::ToolDefinitionError) do
include :terminal, styled: false
end
def run
Expand Down Expand Up @@ -1488,41 +1488,41 @@ def hello
end

it "prevents invoking flag and arg directives" do
test = self
t = self
loader.add_block do
disable_argument_parsing
test.assert_raises(Toys::ToolDefinitionError) do
t.assert_raises(Toys::ToolDefinitionError) do
flag :hello
end
test.assert_raises(Toys::ToolDefinitionError) do
t.assert_raises(Toys::ToolDefinitionError) do
required_arg :hello
end
test.assert_raises(Toys::ToolDefinitionError) do
t.assert_raises(Toys::ToolDefinitionError) do
optional_arg :hello
end
test.assert_raises(Toys::ToolDefinitionError) do
t.assert_raises(Toys::ToolDefinitionError) do
remaining_args :hello
end
end
loader.lookup([])
end

it "cannot be invoked if a flag already exists" do
test = self
t = self
loader.add_block do
flag :hello
test.assert_raises(Toys::ToolDefinitionError) do
t.assert_raises(Toys::ToolDefinitionError) do
disable_argument_parsing
end
end
loader.lookup([])
end

it "cannot be invoked if an arg already exists" do
test = self
t = self
loader.add_block do
required_arg :hello
test.assert_raises(Toys::ToolDefinitionError) do
t.assert_raises(Toys::ToolDefinitionError) do
disable_argument_parsing
end
end
Expand All @@ -1540,10 +1540,10 @@ def hello
end

it "cannot be invoked if argument parsing is disabled" do
test = self
t = self
loader.add_block do
disable_argument_parsing
test.assert_raises(Toys::ToolDefinitionError) do
t.assert_raises(Toys::ToolDefinitionError) do
enforce_flags_before_args
end
end
Expand Down Expand Up @@ -1574,14 +1574,14 @@ def hello
end

it "cannot disable already-defined flags" do
test = self
t = self
loader.add_block do
flag :foo, "-a"
flag :bar, "--bb", "--baa"
test.assert_raises(Toys::ToolDefinitionError) do
t.assert_raises(Toys::ToolDefinitionError) do
disable_flag "-a"
end
test.assert_raises(Toys::ToolDefinitionError) do
t.assert_raises(Toys::ToolDefinitionError) do
disable_flag "--bb"
end
end
Expand Down Expand Up @@ -1736,13 +1736,13 @@ def run
end

it "sets the source info within the block" do
test = self
t = self
loader.add_block do
tool "foo" do
parent_source = source_info
subtool_apply do
test.assert_equal(:proc, source_info.source_type)
test.assert_same(parent_source, source_info.parent)
t.assert_equal(:proc, source_info.source_type)
t.assert_same(parent_source, source_info.parent)
end
tool "bar" do
# Empty tool
Expand All @@ -1755,12 +1755,12 @@ def run

describe "truncate_load_path! directive" do
it "removes lower-priority load paths" do
test = self
t = self
loader.add_block do
truncate_load_path!
end
loader.add_block do
test.flunk("Search was not stopped!")
t.flunk("Search was not stopped!")
end

loader.lookup(["tool-1"])
Expand Down Expand Up @@ -1893,21 +1893,21 @@ def run

describe "settings directive" do
it "returns the settings" do
test = self
t = self
loader.add_block do
test.assert_equal(false, settings.propagate_helper_methods)
t.assert_equal(false, settings.propagate_helper_methods)
settings.propagate_helper_methods = true
test.assert_equal(true, settings.propagate_helper_methods)
t.assert_equal(true, settings.propagate_helper_methods)
end
loader.lookup(["blah"])
end

it "inherits settings of parent tool" do
test = self
t = self
loader.add_block do
settings.propagate_helper_methods = true
tool "tool-1" do
test.assert_equal(true, settings.propagate_helper_methods)
t.assert_equal(true, settings.propagate_helper_methods)
end
end
loader.lookup(["blah"])
Expand All @@ -1916,21 +1916,23 @@ def run

describe "toys_version directives" do
it "checks versions" do
test = self
t = self
loader.add_block do
test.assert(toys_version?("> 0.9", "< 100.0"))
test.refute(toys_version?("< 0.9"))
t.assert(toys_version?("> 0.9", "< 100.0"))
t.refute(toys_version?("< 0.9"))
end
loader.lookup([])
end

it "asserts versions" do
test = self
t = self
loader.add_block do
toys_version!("> 0.9", "< 100.0")
test.assert_raises(Toys::ToolDefinitionError) do
ex = t.assert_raises(Toys::ToolDefinitionError) do
toys_version!("< 0.9")
end
t.assert_equal("Toys version requirements < 0.9 not satisfied by #{Toys::Core::VERSION}",
ex.message)
end
loader.lookup([])
end
Expand Down Expand Up @@ -2003,12 +2005,12 @@ class Hello1 < Toys::Tool; end
end

it "is not allowed from a block" do
test = self
t = self
loader.add_block do
ex = test.assert_raises(Toys::ToolDefinitionError) do
ex = t.assert_raises(Toys::ToolDefinitionError) do
class Hello1 < Toys::Tool; end
end
test.assert_match(/Toys::Tool cannot be subclassed inside a tool block/, ex.message)
t.assert_match(/Toys::Tool cannot be subclassed inside a tool block/, ex.message)
end
end

Expand Down