New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add unit tests #3571
Add unit tests #3571
Conversation
This is a proof on concept to evaluate writing unit tests for Nix using google test (https://github.com/google/googletest). In order to execute tests: $ make unit-tests $ ./unit-tests The Makefile rules for `unit-tests` is a complete hack.
No need to use `c_str()` in combination with `ASSERT_STREQ`. It's possible to just use ASSERT_EQ on std::string
The function isn't being used anywhere so it seems safe to remove
@Kha thanks, fixed! |
@gilligan I've integrated the tests into |
Adjusted the doc comment for `dirOf` to reflect the implementation behavior.
Add note about removal of trailing slashes in the doc comment of baseNameOf and enabled the test.
Update comment and enable the test
@edolstra From my point of view this would now be ready to be merged. There are 2 remaining Anything else you would like to see done to get this over the finishing line? |
This is phenomenal! Thanks guys! |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
Overview
This PR adds unit tests for libutil using https://github.com/google/googletest - The idea was to start somewhere and see how well writing tests works out and then open a PR to get some feedback and also some help.
Motivation
For now Nix has only ever had functional tests. They are super useful and can catch a lot of problems but unit tests can provide added benefits like documentation and making it easier to refactor or port code.
Notes
I picked some simple module (libutil) for testing first. There are going to be other parts of the code base which are more tricky to test and in various cases it just won't make any sense to try to do so. That being said it would be nice to gradually improve the amount of tests and to encourage contributors to provide tests when they change code/add features.
TODOs
tests/unit-tests/local.mk
is a total hack)