Skip to content

Commit

Permalink
Merge 8d53054 into bd338a5
Browse files Browse the repository at this point in the history
  • Loading branch information
mvidner committed Dec 8, 2015
2 parents bd338a5 + 8d53054 commit 2632aac
Show file tree
Hide file tree
Showing 22 changed files with 909 additions and 179 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,17 @@

## master (unreleased)

## 0.0.6 (15/12/2014)
## 0.0.7 (2015-12-08)

### Changes

- Added Cucumber features converted from the Zombie Killer spec.
Some of them are marked as pending because they don't work yet.
- SafeMode config removed, it is always enabled instead.
- StrictMode config added, enabled by default: report all Ops, even if they
cannot be autocorrected.

## 0.0.6 (2014-12-15)

### New Features

Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ Yast/Builtins:
# Check for obsolete Ops.* calls
Yast/Ops:
Enabled: true
# in the safe mode only safe places are reported and fixed
SafeMode: true
# in strict mode all Ops calls are reported
# even if they cannot be autocorrected
StrictMode: true
```

Development
Expand Down
5 changes: 1 addition & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ end
require "cucumber/rake/task"
Cucumber::Rake::Task.new(:features)

require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec)

require "rubocop/rake_task"
RuboCop::RakeTask.new(:rubocop)

task default: [:spec, :features, :rubocop]
task default: [:features, :rubocop]
2 changes: 1 addition & 1 deletion config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Yast/Builtins:
Yast/Ops:
Description: "Check for obsolete Ops.* calls"
Enabled: true
SafeMode: true
StrictMode: true

Yast/LogVariable:
Description: "Check for using 'log' variable"
Expand Down
75 changes: 75 additions & 0 deletions features/ops_assignments.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
Feature: assignments

Scenario: manages niceness correctly in presence of `&&=`
Given the original code is
"""
nice1 = true
nice2 = true
ugly1 = nil
ugly2 = nil
nice1 &&= true
nice2 &&= nil
ugly1 &&= true
ugly2 &&= nil
Ops.add(nice1, 1)
Ops.add(nice2, 1)
Ops.add(ugly1, 1)
Ops.add(ugly2, 1)
"""
When the cop Yast/Ops autocorrects it
Then the code is converted to
"""
nice1 = true
nice2 = true
ugly1 = nil
ugly2 = nil
nice1 &&= true
nice2 &&= nil
ugly1 &&= true
ugly2 &&= nil
nice1 + 1
Ops.add(nice2, 1)
Ops.add(ugly1, 1)
Ops.add(ugly2, 1)
"""

Scenario: manages niceness correctly in presence of `||=`
Given the original code is
"""
nice1 = true
nice2 = true
ugly1 = nil
ugly2 = nil
nice1 ||= true
nice2 ||= nil
ugly1 ||= true
ugly2 ||= nil
Ops.add(nice1, 1)
Ops.add(nice2, 1)
Ops.add(ugly1, 1)
Ops.add(ugly2, 1)
"""
When the cop Yast/Ops autocorrects it
Then the code is converted to
"""
nice1 = true
nice2 = true
ugly1 = nil
ugly2 = nil
nice1 ||= true
nice2 ||= nil
ugly1 ||= true
ugly2 ||= nil
nice1 + 1
nice2 + 1
ugly1 + 1
Ops.add(ugly2, 1)
"""
36 changes: 36 additions & 0 deletions features/ops_blocks.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Feature: blocks

Inside a block the data flow is more complex than we handle now.
After it, we start anew.

Scenario: does not translate inside a block and resumes with a clean slate
Given this gets implemented
Given the original code is
"""
v = 1
v = Ops.add(v, 1)
2.times do
v = Ops.add(v, 1)
v = uglify
end
v = Ops.add(v, 1)
w = 1
w = Ops.add(w, 1)
"""
When the cop Yast/Ops autocorrects it
Then the code is converted to
"""
v = 1
v = v + 1
2.times do
v = Ops.add(v, 1)
v = uglify
end
v = Ops.add(v, 1)
w = 1
w = w + 1
"""
129 changes: 129 additions & 0 deletions features/ops_case.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
Feature: case

With a **single-pass top-down data flow analysis**, that we have been using,
we can process the `case` statement but not beyond it,
because we cannot know which branch was taken.

We can proceed after the `case` statement but must **start with a clean slate**.
More precisely we should remove knowledge of all variables affected in either
branch of the `case` statement, but we will first simplify the job and wipe all
state for the processed method.

Scenario: translates the `when` body of a `case` statement
Given the original code is
"""
case expr
when 1
Ops.add(1, 1)
end
"""
When the cop Yast/Ops autocorrects it
Then the code is converted to
"""
case expr
when 1
1 + 1
end
"""

Scenario: It translates all branches of a `case` statement, independently of each other
Given this gets implemented
Given the original code is
"""
v = 1
case expr
when 1
Ops.add(v, 1)
v = nil
when 2
Ops.add(v, 2)
v = nil
else
Ops.add(1, v)
v = nil
end
"""
When the cop Yast/Ops autocorrects it
Then the code is converted to
"""
v = 1
case expr
when 1
v + 1
v = nil
when 2
v + 2
v = nil
else
1 + v
v = nil
end
"""

Scenario: The expression also contributes to the data state
Given the original code is
"""
case v = 1
when 1
Ops.add(v, 1)
end
"""
When the cop Yast/Ops autocorrects it
Then the code is converted to
"""
case v = 1
when 1
v + 1
end
"""

Scenario: The test also contributes to the data state
Given the original code is
"""
case expr
when v = 1
Ops.add(v, 1)
end
"""
When the cop Yast/Ops autocorrects it
Then the code is converted to
"""
case expr
when v = 1
v + 1
end
"""

Scenario: The test also contributes to the data state
Given the original code is
"""
v = 1
case expr
when 1
v = nil
end
Ops.add(v, 1)
"""
When the cop Yast/Ops autocorrects it
Then the code is unchanged

Scenario: It translates zombies whose arguments were found nice after a `case`
Given the original code is
"""
case expr
when 1
v = nil
end
v = 1
Ops.add(v, 1)
"""
When the cop Yast/Ops autocorrects it
Then the code is converted to
"""
case expr
when 1
v = nil
end
v = 1
v + 1
"""
28 changes: 28 additions & 0 deletions features/ops_chained.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Feature: chained translation

Scenario: translates a left-associative chain of nice zombies
Given this gets implemented
Given the original code is "Ops.add(Ops.add(1, 2), 3)"
When the cop Yast/Ops autocorrects it
Then the code is converted to "(1 + 2) + 3"

Scenario: translates a right-associative chain of nice zombies
Given this gets implemented
Given the original code is "Ops.add(1, Ops.add(2, 3))"
When the cop Yast/Ops autocorrects it
Then the code is converted to "1 + (2 + 3)"

Scenario: translates `Ops.add` of plus and literal
Given the original code is "Ops.add("Hello" + " ", "World")"
When the cop Yast/Ops autocorrects it
Then the code is converted to "("Hello" + " ") + "World""

Scenario: translates `Ops.add` of parenthesized plus and literal
Given the original code is "Ops.add(("Hello" + " "), "World")"
When the cop Yast/Ops autocorrects it
Then the code is converted to "("Hello" + " ") + "World""

Scenario: translates `Ops.add` of literal and plus
Given the original code is "Ops.add("Hello", " " + "World")"
When the cop Yast/Ops autocorrects it
Then the code is converted to ""Hello" + (" " + "World")"

0 comments on commit 2632aac

Please sign in to comment.