Skip to content

Add unit tests for Utils::toHex#925

Open
mtlynch wants to merge 2 commits intomeshcore-dev:devfrom
mtlynch:unit-tests
Open

Add unit tests for Utils::toHex#925
mtlynch wants to merge 2 commits intomeshcore-dev:devfrom
mtlynch:unit-tests

Conversation

@mtlynch
Copy link
Copy Markdown

@mtlynch mtlynch commented Oct 12, 2025

Adds unit tests for Utils::toHex using Google gtest framework and adds automatic unit tests runs on every commit to Github Actions for the repo.

@mtlynch
Copy link
Copy Markdown
Author

mtlynch commented Oct 12, 2025

I know toHex isn't the most interesting function to test, but this is just a proof of concept of the idea of unit testing in this project.

Unit testing can make it significantly easier and faster to catch bugs, as we can exercise logic on regular desktops and in Github Actions without having to push code to a LoRa device and test it. It also allows maintainers to see immediately in Github Actions if a change caused a regression in tests.

I chose toHex just because it's a simple function with no external dependencies, though because it's defined in a file that also includes dependencies on Stream.h and SHA256.h, we need to mock out those dependencies.

@446564
Copy link
Copy Markdown
Contributor

446564 commented Apr 24, 2026

@mtlynch can you resolve the conflicts on this one?

@446564
Copy link
Copy Markdown
Contributor

446564 commented Apr 24, 2026

testing now :)

@mtlynch
Copy link
Copy Markdown
Author

mtlynch commented Apr 24, 2026

@446564 - Sure, just fixed. The first two pulled in some unintended changes from the dev/main branches, but it's fixed now.

@446564
Copy link
Copy Markdown
Contributor

446564 commented Apr 24, 2026

@mtlynch ok newb time, haven't run unit tests with pio before and getting an error: .pio/libdeps/native/googletest/googletest/include/gtest/internal/gtest-port.h:273:2: error: #error C++ versions less than C++17 are not supported. am I missing some dep or config not present in the repo?

edit: I have gcc 14 which supports c++17 but this should be using the pio installed toolchain right?

With the '^x.y.z' semantics, the version can upgrade out from under us and change dependencies, so this pins to an exact version.
@mtlynch
Copy link
Copy Markdown
Author

mtlynch commented Apr 24, 2026

@446564 - Yeah, it was my fault. I specified gtest ^1.15.2, which was latest when I wrote it six months ago, but now the latest is 1.17.0, which apparently depends on c++17, so I've specified c++ 17 and pinned to the exact version so that future updates don't change out from under us.

Fixed in b6a3aa1

@446564
Copy link
Copy Markdown
Contributor

446564 commented Apr 24, 2026

it's working now, i don't like the output, it's weird to me. but maybe that's just testing with pio

@mtlynch
Copy link
Copy Markdown
Author

mtlynch commented Apr 24, 2026

@446564 - Glad it's working! What's remaining to get this merged?

@liamcottle
Copy link
Copy Markdown
Member

Have pulled it in, seems to work for me. I agree with @446564 that the output isn't very nice, compared to other testing frameworks. But I'm sure as more tests are added we will just get used to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants