-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
584 additions
and
922 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
Feature: Generic Builtins detection and replacement | ||
|
||
Some Builtin calls are not detected as an offense and are kept unchanged. | ||
That include the calls which do not have native ruby replacement, like lsort() | ||
or crytp() functions, or the replacement would be too complex (the gettext | ||
builtins). | ||
|
||
Only known builtins can be replaced, the rest needs to be kept untouched. | ||
|
||
|
||
Scenario: y2milestone() builtin call is reported as an offense | ||
Given the original code is | ||
""" | ||
Builtins.y2milestone("foo") | ||
""" | ||
When I check it using RuboCop::Cop::Yast::Builtins cop | ||
Then offense "Builtin call `y2milestone` is obsolete" is found | ||
|
||
Scenario: Builtin with explicit Yast namespace is reported as an offense | ||
Given the original code is | ||
""" | ||
Yast::Builtins.y2milestone("foo") | ||
""" | ||
When I check it using RuboCop::Cop::Yast::Builtins cop | ||
Then offense "Builtin call `y2milestone` is obsolete" is found | ||
|
||
Scenario: Builtin with explicit ::Yast namespace is reported as an offense | ||
Given the original code is | ||
""" | ||
::Yast::Builtins.y2milestone("foo") | ||
""" | ||
When I check it using RuboCop::Cop::Yast::Builtins cop | ||
Then offense "Builtin call `y2milestone` is obsolete" is found | ||
|
||
Scenario: Builtins with ::Builtins name space are ignored | ||
Given the original code is | ||
""" | ||
::Builtins.y2milestone("foo") | ||
""" | ||
When I check it using RuboCop::Cop::Yast::Builtins cop | ||
Then the code is found correct | ||
|
||
Scenario: Builtins in non Yast name space are ignored | ||
Given the original code is | ||
""" | ||
Foo::Builtins.y2milestone("foo") | ||
""" | ||
When I check it using RuboCop::Cop::Yast::Builtins cop | ||
Then the code is found correct | ||
|
||
Scenario: lsort(), crypt and gettext builtins are allowed | ||
Given the original code is | ||
""" | ||
Builtins.lsort(["foo"]) | ||
Builtins.crypt("foo") | ||
Builtins.dgettext("domain", "foo") | ||
""" | ||
When I check it using RuboCop::Cop::Yast::Builtins cop | ||
Then the code is found correct | ||
|
||
Scenario: Unknown builtins are kept unchanged | ||
Given the original code is | ||
""" | ||
Builtins.foo() | ||
""" | ||
When I correct it using RuboCop::Cop::Yast::Builtins cop | ||
Then the code is unchanged |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
Feature: Builtins.getenv() | ||
|
||
Builtins.getenv() call can be easily replaced by ENV hash access. | ||
We just need to keep the original parameter. | ||
|
||
Scenario: With string literal parameter it is translated to ENV equivalent | ||
Given the original code is | ||
""" | ||
Builtins.getenv("foo") | ||
""" | ||
When I correct it using RuboCop::Cop::Yast::Builtins cop | ||
Then the code is converted to | ||
""" | ||
ENV["foo"] | ||
""" | ||
|
||
Scenario: Variable as the parameter is preserved | ||
Given the original code is | ||
""" | ||
foo = bar | ||
Builtins.getenv(foo) | ||
""" | ||
When I correct it using RuboCop::Cop::Yast::Builtins cop | ||
Then the code is converted to | ||
""" | ||
foo = bar | ||
ENV[foo] | ||
""" | ||
|
||
Scenario: Any other statement is preserved | ||
Given the original code is | ||
""" | ||
Builtins.getenv(Ops.add(foo, bar)) | ||
""" | ||
When I correct it using RuboCop::Cop::Yast::Builtins cop | ||
Then the code is converted to | ||
""" | ||
ENV[Ops.add(foo, bar)] | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Feature: Builtins.time() | ||
|
||
Builtins.time() call can be easily replaced by native Time.now call. | ||
It has no parameter therefore no extra handling is needed. | ||
|
||
|
||
Scenario: Builtins.time() is replaced by ::Time.now.to_i | ||
Given the original code is "Builtins.time()" | ||
When I correct it using RuboCop::Cop::Yast::Builtins cop | ||
Then the code is converted to "::Time.now.to_i" |
Oops, something went wrong.