Skip to content
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

Disable tests by default #4

Open
tigertv opened this issue Jul 18, 2022 · 11 comments
Open

Disable tests by default #4

tigertv opened this issue Jul 18, 2022 · 11 comments
Labels
enhancement New feature or request

Comments

@tigertv
Copy link
Owner

tigertv commented Jul 18, 2022

It would be better if there was an option to disable tests while importing the library, like that - mekhovyyekulaki@4dcf417
They get interferred with the project's tests which make the library less comfortable to use.

(from PR#3)

@tigertv tigertv changed the title Disable test by default Disable tests by default Jul 18, 2022
@tigertv tigertv added the enhancement New feature or request label Jul 23, 2022
@saxbophone
Copy link

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

@tigertv
Copy link
Owner Author

tigertv commented Feb 5, 2023

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

@saxbophone
Copy link

saxbophone commented Feb 6, 2023

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

@tigertv
Copy link
Owner Author

tigertv commented Feb 6, 2023

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?

@saxbophone
Copy link

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!

@tigertv
Copy link
Owner Author

tigertv commented Feb 14, 2023

@saxbophone ,
Is it hard?

@saxbophone
Copy link

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

@tigertv
Copy link
Owner Author

tigertv commented Feb 15, 2023

OK.

@tigertv
Copy link
Owner Author

tigertv commented Mar 1, 2023

Somebody lies on the Internet again...

@saxbophone
Copy link

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.

@tigertv
Copy link
Owner Author

tigertv commented Mar 1, 2023

Paroles, paroles :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants