Giter Site home page Giter Site logo

Disable tests by default about beenum HOT 11 OPEN

tigertv avatar tigertv commented on August 28, 2024
Disable tests by default

from beenum.

Comments (11)

saxbophone avatar saxbophone commented on August 28, 2024

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.

tigertv avatar tigertv commented on August 28, 2024

@saxbophone, OK, Great!
Could you add a pull request?

from beenum.

saxbophone avatar saxbophone commented on August 28, 2024

@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.

tigertv avatar tigertv commented on August 28, 2024

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.

saxbophone avatar saxbophone commented on August 28, 2024

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.

tigertv avatar tigertv commented on August 28, 2024

@saxbophone ,
Is it hard?

from beenum.

saxbophone avatar saxbophone commented on August 28, 2024

@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.

tigertv avatar tigertv commented on August 28, 2024

OK.

from beenum.

tigertv avatar tigertv commented on August 28, 2024

Somebody lies on the Internet again...

from beenum.

saxbophone avatar saxbophone commented on August 28, 2024

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.

tigertv avatar tigertv commented on August 28, 2024

Paroles, paroles :)

from beenum.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.