Comments (11)
For CMake-based projects, I usually check if my lib is being used as a sub-project with this hack:
if(NOT DEFINED PROJECT_NAME)
set(LIB_IS_SUBPROJECT OFF)
else()
set(LIB_IS_SUBPROJECT ON)
endif()
# call to project() MUST come after!
project(...)
and just use an implicit option ENABLE_TESTING
to switch on or off the tests, in combination with making sure we're not a sub-project:
if(ENABLE_TESTS AND NOT LIB_IS_SUBPROJECT)
message(STATUS "Unit Tests Enabled")
add_subdirectory(tests)
enable_testing()
endif()
One can then enable the tests explicitly by passing -DENABLE_TESTS=ON
on the cmake command-line at generate time.
Personally, I go a step further and detect when in debug mode and enable tests automatically in that case, disable them automatically in release mode (but they can be manually reënabled by passing the flag as mentioned above).
from beenum.
@saxbophone, OK, Great!
Could you add a pull request?
from beenum.
@saxbophone, OK, Great! Could you add a pull request?
I could. What behaviour do you want?
- Do you want the tests to not run by default unless explicitly enabled by the user?
- Or do you want the tests to run by default in Debug mode but not Release mode?
from beenum.
The case is the following:
Tests are disabled in Release mode, and they are enabled in Debug mode.
But user can change the behavior by passing the option ENABLE_TESTING.
What do you think?
from beenum.
The case is the following: Tests are disabled in Release mode, and they are enabled in Debug mode. But user can change the behavior by passing the option ENABLE_TESTING.
What do you think?
This is what I use for my own projects and it works well for me, is very convenient for CI and for manually building the tests in release mode if one's ever worried about compiler optimisations breaking them.
I can do this no problem!
from beenum.
@saxbophone ,
Is it hard?
from beenum.
@saxbophone , Is it hard?
No, I've just been busy doing other stuff and haven't got round to it yet. You will be able to see when I start working on it as I will fork your project.
from beenum.
OK.
from beenum.
Somebody lies on the Internet again...
from beenum.
Somebody lies on the Internet again...
You know, I really was going to do this for you when I found the time for it, but if that's your attitude then you know what, never mind. You can do it yourself.
The code samples I've already given in comments here should be a good enough starting point for you.
from beenum.
from beenum.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from beenum.