overturetool / vdm-vscode

Visual Studio Code extension for VDM language support
GNU General Public License v3.0
21 stars 6 forks source link

Traces are inherited #200

Closed cakemaster9001 closed 1 year ago

cakemaster9001 commented 1 year ago

I was doing some trace testing on both a derived and a base class in my project, but when I tried to run the tests in the derived class, the CT framework failed to run the tests. Interestingly enough, I can run the tests for the base class just fine, but when I try to run the tests of the derived class, they fail. I made a small example to reproduce my issue:

File 1

class TestInheritedTracesBase
operations
doStuff: () ==> ()
doStuff() == return;

traces
TestDoStuff:
    let dut = new TestInheritedTracesBase() in
    dut.doStuff();

end TestInheritedTracesBase

File 2

class TestInheritedTracesDerived is subclass of TestInheritedTracesBase
operations
doOtherStuff: () ==> ()
doOtherStuff() == return;

traces
TestDoOtherStuff:
    let dut = new TestInheritedTracesDerived() in
    dut.doOtherStuff();

end TestInheritedTracesDerived

When I try to run the tests using the CT VSCode tab I get the following message: "Exception during trace expansion: Error 6: Constructor for TestInheritedTracesDerived can't find TestDoStuff in 'TestInheritedTracesDerived' (/home/mikkel/Documents/vdm/test/test2.vdmpp) at line 3:7

You can debug this using the 'generate' console command"

The test also fails when the two classes are in the same file.

nickbattle commented 1 year ago

OK, thanks for reporting this. I can confirm that your example is reproducible here in VDMJ, so it should be easy to track down...

nickbattle commented 1 year ago

Yes, the inheritance was inconsistent. Good spot! We want named traces to be "public" so that they can easily be called from outside their class, but that implies they are inherited as well, which we don't want. Simple fix. So now it says:

> runtrace TestInheritedTracesDerived`TestDoOtherStuff
Generated 1 tests in 0.017 secs. 
Test 1 = dut.doOtherStuff()
Result = [(), PASSED]
Executed in 0.355 secs. 
All tests passed
> 

It works on VSCode too, of course :-) It's pushed to the "development" branch, if you want to try a patch?

nickbattle commented 1 year ago

Closing, as this is now resolved and there are no UI changes.