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

Please add simple example of what you mean in "Why do my tests take so long to compile? page". #632

Closed
sldr opened this issue Apr 4, 2016 · 9 comments

Comments

@sldr
Copy link

sldr commented Apr 4, 2016

You say to have a single file with #define CATCH_CONFIG_MAIN and #include "catch.hpp", but I don't understand where the tests would be. Are you saying that you would have foo.cpp foo_test.cpp and catch.cpp (with the two lines) all compiled together. Then you might have bar.cpp so you would compile bar.cpp, bar_test.cpp and catch.cpp together for testing bar code? Then if you had foobar.cpp (that depends on foo and bar) you would compile foo.cpp, foo_test.cpp, bar.cpp, bar_test.cpp, foobar.cpp, foobar_test.cpp, and catch.cpp all together?

You do a great job of explaining why it is slow but don't explain very well what a solution would look like other than saying a single cpp file with the two lines. I think the simple example (of a real world situation) would make everything clear.

Thanks,
SLDR
(Stephen L. De Rudder)

URL: https://github.com/philsquared/Catch/blob/master/docs/slow-compiles.md

PS: Call it best practices if you don't want everyone just blindly doing it this way, but for people with large projects that don't want to blaze their own path or reinvent the wheel; an example for many c++ modules with dependencies would get them off the ground quick.

PSS: My $0.02 worth.

@lichray
Copy link
Contributor

lichray commented Apr 19, 2016

Compile all test files, including catch.cpp which contains the two lines, into their object files, like catch.o, test_bar.o, test_foo.o, and link them together, along with the library you want to test against, into one executable. Any build system will normally do this. For CMake, that will be:

file(GLOB tests_srcs tests/*.cc)   # let's say your test_*.cc files are under "tests" folder
add_executable(run ${tests_srcs})  # and the test executable is "run"
target_link_libraries(run your_library_target)
add_test(testall tests/run)        # and the executable also lies under "tests" folder

@martinmoene
Copy link
Collaborator

martinmoene commented Apr 20, 2016

Or, see my gist CATCH - Small complete multi-file example.

@martinmoene
Copy link
Collaborator

martinmoene commented Feb 11, 2017

I think it would be instructional to include simple compilation commands with examples, like

Compile file with main once:

g++ -c tests-main.cpp

Subsequently use above object file:

g++ -o tests-main tests-main.o tests-factorial.cpp && tests-main

@horenmar
Copy link
Member

@martinmoene How about changing the last paragraph to this?

After compiling tests-main.cpp once, by doing g++ -c tests-main.cpp, it is enough to link the resulting object file with separately compiled tests-factorial.cpp, like so g++ tests-main.o tests-factorial.cpp -o tests. This means that adding more tests to tests-factorial.cpp, will not result in recompiling Catch's main and the resulting compilation times will decrease substantially.

@martinmoene
Copy link
Collaborator

martinmoene commented Feb 12, 2017

The text nicely explains it. Adding a simple commandline (in some form) may make it easier to quickly see the point.

@martinmoene
Copy link
Collaborator

My suggestion comes from how we scan-read (web) pages to find the information we need. Just like titles, a command line stands off from the main text and draws our attention helping find what we need and determine if we need/want to read the nearby text any further.

In general, I think it's helping a reader to present examples with compilation command and output. Doing so obviates the need for the reader to guess what's not there (even if that may seem obvious for the writer) and it reassures the reader they are understanding the matter at hand.

@horenmar
Copy link
Member

Ok, I expanded the section a bit more yet.

@martinmoene
Copy link
Collaborator

@horenmar Now even better that I imagined 😄
PS I think the first line of the final command set can/should be removed.

@horenmar
Copy link
Member

That was not supposed to be there!

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

No branches or pull requests

4 participants