How to run mtests in QtCreator/MinGW Windows

MuseScore 3.x only!

Just an information log of what I did to make mtest work in QtCreator. This acts as a temporary scrapbook note until (if?) these instructions can be finalized and turned into the real compilation documentation.

This guide is not valid for non 3.x versions!

Start situation

I have a setup similar to https://musescore.org/en/handbook/developers-handbook/compilation/compi… for which I'll specify the settings here. This was not a clean local copy, but one that has been around for a while and updated several times.

I worked on the 3.x branch at around the 3.5beta tag; I suspect the steps required for master will be quite similar.

  • QtCreator: 4.12.0
  • Kit: Qt 5.12.5 MinGW 64-bit
  • cmake: 3.16.4

Build Settings

CMake

Setting Value
Build directory .\build.qtc
CMAKE_BUILD_TYPE Debug
CMAKE_INSTALL_PREFIX ..\win64install

Build Steps

Build target mscore :
cmake.exe --build . --target mscore -- -j3

Run Settings

Deployment

Build target install :
cmake.exe --build . --target install -- -j3

Run

Custom executable:
%{sourceDir}\win64install\bin\MuseScore3.exe

Enabling mtests

Pull Request

Assuming https://github.com/musescore/MuseScore/pull/6392 is merged into your local clone

Build settings

Add an additional build step to build the mtests. As building them all can take quite some time, you might consider building just a selection of tests.

For just one test:

  1. Add Build Step, type "Build"
  2. Check the corresponding target (for example tst_repeat)

For all tests:

  1. Add Build Step, type "build"
  2. Check the target mtest_build_and_install

Disable build steps

You can easily disable a certain build step (for example, disable the mtest build during initial development/debugging to save on compilation time). Do this by clicking the "stop sign" for the corresponding build step (in the screenshot the normal mscore and the additional tst_repeat build steps will not be executed as they are disabled):
mtest-build-steps.png

Build Environment PATH changes

To be able to run the test from their build location, they need to include the build library search path. Rather than painstakingly adjusting each run target, we'll explicitly update the Build Environment Path variable, which by default is also used for the run target environment.
mtest-build-environment-path.png

  1. Click on Details to expand the Build Environment settings
  2. Select the Path entry in the list
  3. Choose Prepend Path and navigate to the Qt MinGW binary directory (C:\Qt\5.12.5\mingw73_64\bin)
  4. Choose Prepend Path again and navigate to the dependencies directory of your local clone (%USERPROFILE%\Documents\MuseScore_git\dependencies for me)

If you don't have diff into your path, then append it here as well by clicking on Append Path. This tool is required for many tests to compare the test result against the reference score. I pointed to C:\Program Files\Git\usr\bin as diff comes along with the Git for Windows install which any windows MuseScore dev should've installed anyway.
WARNING: If you add the git bin directory to your path, you will likely break cmake-for-mingw as it'll now be able to find sh.exe as well. The solution here is to go into Tools > Options > Kits, select the kit (Desktop Qt 5.12.5 MinGW 64-bit) and press the "Change…" button for the CMake Configuration setting.
Add the line CMAKE_SH:STRING=CMAKE_SH-NOTFOUND to it, which'll stop CMake from detecting sh.exe and allow it to run in Codeblocks-MinGW style.

Running an mtest (or all of them)

  1. Open QtCreator and the mscore project
  2. Change from project to test view
    mtest-switch-project-to-test-view.png
  3. Scan for tests: Tools → Tests → Rescan Tests
  4. Change the bottom output window to the "Test Results" window
  5. Right-click any test in the list to Run/Debug just that test, or run only selected tests or run All tests

Results

1033 passes, 0 fails, 1 expected fails, 4 skipped.

Do you still have an unanswered question? Please log in first to post your question.