SanderVocke / qoverage

Simple code coverage for QML
GNU General Public License v3.0
4 stars 1 forks source link

(some_dude912 on Reddit): TypeError: Cannot read property 'line_states' of undefined #54

Closed SanderVocke closed 6 months ago

SanderVocke commented 8 months ago

(posted by some_dude912 on Reddit @ https://www.reddit.com/r/QML/comments/1aumcfe/comment/kr60ctl/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button):

Awesome idea, coincidentally I was working on something similar at the moment. I have just tried out your tool and I may have used it wrong so I am commenting in hopes of getting some advice on how to proceed: I ran qoverage instrument --in-place (without using --in-place or with any other option I was already getting different errors). Now I cd'd into my tests directory which was one level above the source directory which I instrumented. Now I ran my tests using qmltestrunner ... | tee output.log which is how we currently run our tests. (I also went ahead and tried to run it like qoverage collect -- qmltestrunner ...and got the same results) in the output it shows a lot of errors most of them along the lines of TypeError: Cannot read property 'line_states' of undefined. I assume that it is also due to this that when I then try to create the xml report using the procedure described on github I get only a very minimal xml document only stating 0 branches etc.

SanderVocke commented 8 months ago

Hey there, thanks for posting the first issue! It sounds like something is going wrong in the instrumentation or when running the app. It doesn't sound like you are using it wrong.

After instrumenting with --in-place, the expectation is that it should just run as normal but also generate <QOVERAGERESULT>...</QOVERAGERESULT> lines on stdout when the program exits.

If that is not happening and you are already getting errors during runtime, there is no point moving on to the collection stage. line_states is the name(s) of the variable(s) where the coverage is stored at runtime. Quite strange that the collector object holding the line_states seems to be undefined in your case.

Did you also add -g / --glob to your instrument command to specify which files to include? Can you confirm that your QML files are indeed replaced by instrumented ones?

I am afraid it is a bit hard to continue without seeing what is happening in the code.

Just as a sanity check, could you run a very simple "Hello world" QML file? Like this one from the qoverage tests: https://github.com/SanderVocke/qoverage/blob/master/test/examples/basic/main.qml If you just run that with qml main.qml after instrumenting it using qoverage instrument --in-place --glob main.qml, do you see the QOVERAGERESULT line on the stdout?

SanderVocke commented 8 months ago

I can already tell that something needs fixing for using qmltestrunner:

Unfortunately I used a custom test runner in my own project, and used qml (not qmltestrunner) in qoverage's own tests.

I need to address these issues, but it seems unrelated to your issue about line_states. So my questions above remain.

SanderVocke commented 8 months ago

As for triggering the dump, I have an idea on how to fix this for qmltestrunner (see #55) Edit: This was merged to master, and a test for running with qmltestrunner was added. It works, but a new requirement is that you should add qoverage's import directory (get it with qoverage --importpath) to your QML_IMPORT_PATH when running.

Released as well to PyPi (v0.1.12)

SanderVocke commented 6 months ago

stale.