apparat
apparat copied to clipboard
Missing Constructor wrong coverage
I was trying to use flexmojos coverage and wasn't understanding why the coverage.xml was reporting a hit on a line that doesn't exist on the file.
After a night of debug i've found that apparat is instrumenting a line past the end of file when there is no constructor
Is there any fix or workaround? Right now it prevents me from importing the coverage report to sonarqube because the line number is invalid.
If you can provide me with a reproducible test case (binary SWF, no dependencies on Flex SDK preferred) I'll fix it.
If I remember correct, there is actually code on the byte code level for each unit when being initialized.
Foo.as only has 10 lines, but it seems apparat instrumented a line number 11 during the object's initialization.
package
{
public class Foo
{
public function run():void
{
trace("run");
}
}
}
Method:
Name: Foo/Foo
Return Type: AbcQName('null,AbcNamespace(0,'null))
Needs Arguments: false
Needs Rest: false
Needs Activation: false
Has Optional Parameters: false
Ignore Rest: false
Is Native: false
DXNS: false
Has Parameter Names: false
Parameters:
Method Body:
Max Stack: 4
Locals: 1
InitScopeDepth: 4
MaxScopeDepth: 5
Bytecode:
operandStack: 4
scopeStack: 1
localCount: 1
0 exception(s):
11 operation(s):
+1|-0 GetLocal(0)
+0|-1 PushScope()
+1|-0 GetLocal(0)
+0|-1 ConstructSuper(0)
+0|-0 DebugFile('E:\demo\src;;Foo.as)
+0|-0 DebugLine(11)
+1|-0 GetLex(AbcQName('Coverage,AbcNamespace(22,'apparat.coverage)))
+1|-0 PushString('E:\demo\src;;Foo.as)
+1|-0 PushByte(11)
+0|-3 CallPropVoid(AbcQName('onSample,AbcNamespace(22,')),2)
+0|-0 ReturnVoid()
I just checked this. There is in fact a DebugLine instruction in the bytecode. It is being executed and therefore part of the coverage report.
You can supply Apparat a source-path. If a source path is given, one could calculate the number of lines for an instrumented source and ignore DebugLine instructions that are out of bounds. However this doesn't seem like a satisfactory solution to me, especially since we have to count the lines of code in the soruce file. This creates an additional dependency to the source code which was optional before.
I think FlexMojos is always passing the source path to Apparat but I'm not sure. I also think that FlexMojos already did something along those lines. Sorry this is all several years old. @velo do you remember?
Sorry @joa, I don't touch flexmojos code since 2012, I don't remember it at all
@silmerusse For workaround I suggest you creating a constructor.