dodie / scott

Never debug a test again: Detailed failure reports and hassle free assertions for Java tests - Power Asserts for Java
https://advancedweb.hu/junit-and-cucumber-test-reports-based-on-source-code-and-behavior/
MIT License
137 stars 17 forks source link

Investigate and if possible, remove lineNumberToFirstOccurrenceOfVariables and varAccesses in ScopeExtractorMethodVisitor #86

Closed dodie closed 5 years ago

dodie commented 5 years ago

lineNumberToFirstOccurrenceOfVariables and varAccesses in ScopeExtractorMethodVisitor are required for some try-finally constructs to work correctly.

Investigate if it's possible to remove it, or it's indeed necessary to have these exceptional access tracking.

dodie commented 5 years ago

Create more tests to verify the example classes introduced with #80 to see if they are instrumented correctly.

public boolean hello(boolean b) {
        try {
            if (b) {
                return false;
            }

            String string = "a";
            return true;
        } finally {
            System.out.println("Hey");
        }
    }

I suspect that the special constructs that this ticket is about causes an inappropriate recording will happen to the string variable when b is true.

dodie commented 5 years ago

I've tested the snipped from my previous comment, and it does not cause inappropriate recording to happen, because the return statement generates an iload and and an ireturn statement, while the variable recording in inserted for store statements and methods calls only.

So, as far as I know, these variables does not cause side effects, so it's safe to keep them,