platformio / platformio/platformio-docs

Suggested structure for library creation not compatible with unit testing

Open
#372 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
285
Forks
357
PR merge metrics
No merged PRs in 30d

Description

librarymanager/creating.rstsuggests placing library related source code in the src directory. In the example, HelloWorld.cpp would typically contain definitions for forward declarations in HelloWorld.h. If you attempt to run unit tests on any of the definitions in the separate source file, it will fail with linker errors (undefined reference to ... because files in the src directory are not compiled when running unit tests by default.

To overcome this issue, you would have to enable test_build_src which, according to advanced/unit-testing/structure/shared-code.rst, is not recommended.

It would seem that a better option is to place the files in the lib directory inside a module specific directory:

    ├── examples
    │   └── echo
    ├── lib
    │   └── HelloWorld
    │       ├── HelloWorld.h
    │       └── HelloWorld.cpp
    ├── library.json
    ├── src
    │   └── main.cpp
    └── test
        └── test_hello_world.cpp

Based on limited testing, the HelloWorld files must be in a sub-directory of lib, otherwise they wont be found by the Library Dependency Finder.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with librarymanager/creating.rst and advanced/unit-testing/structure/shared-code.rst, then verify the described library and unit-test layouts. Determine which structure the documentation should recommend and update the relevant guidance so library source files can be tested without relying on the discouraged setting.

Written by the indexing model from the issue text.

Assessment

Domain
documentation, testing-qa
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.