PlatformIO Community

How does the test filter argument match test names?

I want to use the filter argument to pio test to only run the tests from one of my test files or test directories.
Like in the example below, I want to only run the tests in test_partone.hpp, or only the tests of the SomeClass directory. How do I do this?

The docs say the filter checks the “name” of the test. But what is the “name”. FIlename? Function name? Function name including class/namespace/etc? Something else? Can someone clarify this for me? So far, whatever I do, if I do anything more specific than -f test_desktop, (matching the first directory level of the tests) it doesn’t run any tests. I tried many different variations, including wildcards.

test/test_desktop/
test/test_desktop/test_main.cpp
test/test_desktop/test_main.h
test/test_desktop/SomeClass/
test/test_desktop/SomeClass/test_main.hpp
test/test_desktop/SomeClass/test_partone.hpp
test/test_desktop/SomeClass/test_parttwo.hpp

test/test_desktop/test_main.cpp contains the following:

#include "test_main.h"
#include "SomeClass/test_main.hpp"

int main(int argc, char **argv) {
    test_someclass::main(argc, argv);
    return 0;
}

test/test_desktop/SomeClass/test_main.hpp contains the following:

#pragma once
#include "test_partone.hpp"
#include "test_parttwo.hpp"

namespace test_someclass {
    
    int main(int argc, char **argv) {
        test_someclass_partone::main();
        test_someclass_parttwo::main();
        return 0;
    }
}

and test/test_desktop/SomeClass/test_partone.hpp contains the real tests like this (and test_parttwo.hpp the same, just with a different namespace):

#pragma once
#include <unity.h>

namespace test_someclass_partone {
    
    void sometest() {
        TEST_ASSERT_EQUAL(1, 1);
    }
    
    int main() {
        UNITY_BEGIN();
        RUN_TEST(some_test);
        UNITY_END();
        return 0;
    }
}

@ivankravets maybe you have a clarification on this topic.

1 Like

@valeros please help.

Hi @dolfandringa,
At the moment the Test Runner can only differentiate tests by first level folders in the root of test_dir and will compile all files in these folders, for example you have the following test structure:

test/test_common/test_main.hpp
test/test_common/test_main.cpp
test/test_common/module/test_module.cpp
test/test_native/test_native.cpp
test/test_linux/test_linux.cpp
test/test_embedded/test_embedded.cpp

If you want to run tests only from common and embedded folders, you need to run the following command:

pio test -f test_common -f test_embedded

which will compile test_main.cpp, test_module.cpp, test_embedded.cpp

Thanks for the answer @valeros. Its not the answer I was hoping for, so I guess I have a feature request. But I can live with commenting out some of my test_someclass::main calls for now. Thanks for the clear answer and great software (PlatformIO is a game changer for me)