Skip to content

Commit

Permalink
fix: repeat 0 causes infinite loop
Browse files Browse the repository at this point in the history
Fixes #49
  • Loading branch information
rfdonnelly committed Nov 3, 2023
1 parent 8ea638f commit ccdd14d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ Fourth Ctrl-C sends SIGKILL to active jobs.
* Fixed typo of `--verbose` option
* Fixed missing `--version` option
* Fixed coloring output when STDOUT is not a TTY
* Fixed a job repeat value of `0` causes an infinite loop

=== Removed

Expand Down
4 changes: 2 additions & 2 deletions lib/jobrnr/dsl/job_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def execute(command = nil, &block)
end

def repeat(times)
if !times.is_a?(Integer) || times.negative?
raise Jobrnr::TypeError, "'repeat' expects a positive Integer " \
if !times.is_a?(Integer) || times <= 0
raise Jobrnr::TypeError, "'repeat' expects an Integer greater than zero " \
"but was given value of '#{times}' of type " \
"'#{times.class.name}' @ #{caller_source}"
end
Expand Down
16 changes: 14 additions & 2 deletions test/dsl_command_error_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def clear
end
end
assert_equal(Jobrnr::Util.strip_heredoc(<<-EOF).strip, e.message)
'repeat' expects a positive Integer but was given value of '5' of type 'String' @ file:line
'repeat' expects an Integer greater than zero but was given value of '5' of type 'String' @ file:line
EOF
end

Expand All @@ -116,7 +116,19 @@ def clear
end
end
end
assert_match(/'repeat' expects a positive Integer but was given value of '-1' of type '\w+' @ file:line$/,
assert_match(/'repeat' expects an Integer greater than zero but was given value of '-1' of type '\w+' @ file:line$/,
e.message)
end

it "requires a non-zero Integer" do
e = assert_raises(Jobrnr::TypeError) do
@obj.job :id do
stub :caller_source, "file:line" do
repeat(0)
end
end
end
assert_match(/'repeat' expects an Integer greater than zero but was given value of '0' of type '\w+' @ file:line$/,
e.message)
end
end
Expand Down

0 comments on commit ccdd14d

Please sign in to comment.