C++ Unit testing framework up and running

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
waebbl
Posts: 200
Joined: Thu Aug 16, 2018 3:12 pm

Re: C++ Unit testing framework up and running

Post by waebbl »

wmayer wrote: Tue Feb 07, 2023 9:58 am These are separate executables and a user must run them from the command line in order to see any results. Another thing is that the packages will get quite bloated if each class has its own test executable.
The files wont get installed onto the system. They are just run during the test phase of the build process, often invoked using ctest for a cmake based build system.
wmayer
Founder
Posts: 20203
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: C++ Unit testing framework up and running

Post by wmayer »

waebbl wrote: Tue Feb 07, 2023 6:46 pm The files wont get installed onto the system. They are just run during the test phase of the build process, often invoked using ctest for a cmake based build system.
OK, that makes sense.
berniev
Posts: 247
Joined: Wed Apr 13, 2022 10:45 pm
Location: Oz

Re: C++ Unit testing framework up and running

Post by berniev »

A PR is lodged. How does a reviewer/maintainer know the changes a) work, and b) don't change functionality?

Imagine if the PR includes tests

Code: Select all

TEST(Unit, FlowCheckThrowPos)
{
    EXPECT_ANY_THROW(new Base::Unit("test",0,8,0,0,0,0,0,0));
}
TEST(Unit, GetString){
    Base::Unit unit {"test",0,0,-8,0,0,0,0,0};
    EXPECT_EQ(unit.getString(), "1/s^8");
}
TEST(Unit, GetStringElectricPotential){
    Base::Unit unit {Base::UnitDefs::ElectricPotential};
    EXPECT_EQ(unit.getString(), "mm^2*kg/(s^3*A)");
}
TEST(Unit, AsStringElectricPotential){
    Base::Unit unit {Base::UnitDefs::ElectricPotential};
    EXPECT_EQ(unit.asString(), "Unit: mm^2*kg/(s^3*A) (2,1,-3,-1,0,0,0,0) [ElectricPotential]");
}
TEST(Unit, NameString){
    Base::Unit unit {"test",0,0,-8,0,0,0,0,0};
    EXPECT_EQ(unit.nameStr(), "test");
}
Without tests, reviewers are understandably cautious.
Tests are what makes fast merging possible (e.g. in C4) because a heavy burden is lifted off the reviewer's back.
User avatar
chennes
Veteran
Posts: 3868
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: C++ Unit testing framework up and running

Post by chennes »

Regarding using FetchContent -- according to the cMake documentation, FetchContent_MakeAvailable will use find_package first, and will only attempt to download the code itself if it cannot find it some other way. My understanding of our earlier discussion is that is basically exactly the behavior we want, right? It replicates the idea of having a git submodule, but only if that submodule is actually needed. @berniev I didn't follow the original discussion -- why did you end up removing that from the PR?
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
berniev
Posts: 247
Joined: Wed Apr 13, 2022 10:45 pm
Location: Oz

Re: C++ Unit testing framework up and running

Post by berniev »

I don't remember noticing that FetchContent_MakeAvailable will try find_package first. Good spot! I used it because it (from memory) was google's reccommended way.

I did have this in a PR, but while it languished The Boss did a commit sticking with the lib in the project source, so who was I to argue -- we were making progress. The next version was just a tidy-up of the directory structure without changing how the lib gets where it is.

I have no issue if you want to go that way.
berniev
Posts: 247
Joined: Wed Apr 13, 2022 10:45 pm
Location: Oz

Re: C++ Unit testing framework up and running

Post by berniev »

This discussion is very relevant to ongoing discussions re fmt library as well.
abdullah
Post Reply