konstantinvlasenko / PowerSlim

Fitnesse Slim implementation in PowerShell. PowerSlim makes it possible to use PowerShell in the acceptance testing
powerslim.org
GNU General Public License v3.0
48 stars 21 forks source link

Symbol assignment in DecisionTable Result? column #49

Closed ALuckyGuy closed 11 years ago

ALuckyGuy commented 11 years ago

It seems like I saw it mentioned somewhere that this is a known issue: one cannot store a DecisionTable's Result? column in a $symbol.

In any event, it is an issue and as it turns out, a one-line change fixes it. Change line 273:
switch (Operation){ to: switch -regex (Operation){

This results in the DecisionTable "callAndAssign" instruction also being processed by the "call" branch of the switch statement and the result then gets stored in the $symbol.

The following test will demonstrate the bug and the correct behavior after the fix.

''Symbols in decision table'' |"$arg1 $arg2"| |arg1 |arg2 |result?| |Hello|World| $V= |

konstantinvlasenko commented 11 years ago

Great! Do you wanna make a pull request? Or I can change it by myself?

ALuckyGuy commented 11 years ago

If you don't mind, go ahead. I still haven't invested the time I need to learn Git.

konstantinvlasenko commented 11 years ago

Thank you:)

mikeplavsky commented 11 years ago

Great finding! Thanks a lot!

konstantinvlasenko commented 11 years ago

This change definetely solves this issue. But this test TestMatch became red with this change. We need to have more time to apply this change. Probably it is time to refactor this code.

ALuckyGuy commented 11 years ago

I didn't realize there was an effort to preserve $matches so that it can be interrogated by a later command... makes sense. In that case then instead of using -regex, use -wildcard on the switch command and change the pattern for matching "call" to include an asterisk, "call*". This should provide the same behavior, probably be slightly faster and not contaminate $matches.

ALuckyGuy commented 11 years ago

I finally had a chance to test this morning. Running with the -wildcard/call* change the fix still works, and it doesn't appear to introduce any side effects. At least not in my version of slim.ps1 and it's test suite, which is based on an older copy.

konstantinvlasenko commented 11 years ago

Great! I'll try to apply this fix today. Thank you. Just one small notice.

|"$arg1 $arg2"| |arg1 |arg2 |result?| |Hello|World| $V= |

I found that after that fix you will be able to use this symbol for verification only: |check|eval|"Hello World"|$V|

But not for using inside a followup execution (this will not work): |eval|"$V"|Hello World|

ALuckyGuy commented 11 years ago

Good point. FitNesse assumes the SUT knows about the assigned value, and the fix above doesn't update the symbol table.

I made the following change to fix that, adding line 316 below:

312:          if($ins[3] -ne 'Result'){
313:            "Not Implemented"
314:          }else{
315:            $script:decision_result
316:            if($symbol){$slimsymbols[$symbol] = $script:decision_result}
317:          }
318:          return

edited, replace $global: with $script: