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

Get unit tests building again. #8360

Merged
merged 7 commits into from
May 24, 2015

Conversation

kevingranade
Copy link
Member

Reverse some of the bitrot of the minimal unit tests.
I'm looking into some header-only unit test frameworks to include so that people don't have to grab a dependency to build/run the unit tests. Recommendations are welcome.
The front runner at the moment is https://github.com/philsquared/Catch

@KA101 KA101 assigned KA101 and unassigned KA101 Jul 28, 2014
@kevingranade
Copy link
Member Author

line_test compiles, runs and seems to be working, player_test compiles and runs, but crashes during initialization like so:
Program received signal SIGABRT, Aborted.
0x000000346f835c39 in raise () from /lib64/libc.so.6
Missing separate debuginfos, use: debuginfo-install glibc-2.18-12.fc20.x86_64 libgcc-4.8.2-7.fc20.x86_64 libstdc++-4.8.2-7.fc20.x86_64 ncurses-libs-5.9-12.20130511.fc20.x86_64
(gdb) bt
#0 0x000000346f835c39 in raise () from /lib64/libc.so.6
#1 0x000000346f837348 in abort () from /lib64/libc.so.6
#2 0x0000003472cb35f5 in __gnu_debug::_Error_formatter::_M_error() const () from /lib64/libstdc++.so.6
#3 0x00000000007b2f6e in __gnu_debug::_Safe_iterator<std::_Rb_tree_const_iterator<std::pair<std::string const, regional_settings> >, std::__debug::map<std::string, regional_settings, std::lessstd::string, std::allocator<std::pair<std::string const, regional_settings> > > >::operator-> (this=0x7ffffffa9b80) at /usr/include/c++/4.8.2/debug/safe_iterator.h:277
#4 0x0000000000809e21 in overmap::overmap (this=0x7ffffffa9ca0, x=0, y=0) at src/overmap.cpp:639
#5 0x0000000000ab8947 in overmapbuffer::get (this=0x1336400 <overmap_buffer>, x=0, y=0) at src/overmapbuffer.cpp:55
#6 0x0000000000410604 in ____C_A_T_C_H____T_E_S_T____61 () at player_test.cpp:87
#7 0x0000000000420aa6 in Catch::FreeFunctionTestCase::invoke (this=0x1343510) at catch/catch.hpp:5500
#8 0x000000000040b41d in Catch::TestCase::invoke (this=0x137ffd0) at catch/catch.hpp:6382
#9 0x000000000041e7bd in Catch::RunContext::runCurrentTest (this=0x7fffffffd830, redirectedCout="", redirectedCerr="") at catch/catch.hpp:5124
#10 0x000000000041d66f in Catch::RunContext::runTest (this=0x7fffffffd830, testCase=...) at catch/catch.hpp:4994
#11 0x000000000041f298 in Catch::Runner::runTests (this=0x7fffffffdc70) at catch/catch.hpp:5268
#12 0x0000000000420135 in Catch::Session::run (this=0x7fffffffdf90) at catch/catch.hpp:5388
#13 0x0000000000420000 in Catch::Session::run (this=0x7fffffffdf90, argc=1, argv=0x7fffffffe1d8) at catch/catch.hpp:5371
#14 0x000000000040fee0 in main (argc=1, argv=0x7fffffffe1d8) at catch/catch.hpp:8802
(gdb) f 4
#4 0x0000000000809e21 in overmap::overmap (this=0x7ffffffa9ca0, x=0, y=0) at src/overmap.cpp:639
639 settings = rsit->second;
(gdb)

The problem seems to be that ACTIVE_WORLD_OPTIONS isn't getting initialized.

@boydkr
Copy link
Contributor

boydkr commented Oct 25, 2014

@kevingranade I was considering trying to add Google Test and Google Mock support. It would probably have to be included as source and compiled along with any unit tests in order to support all of the cross platform stuff.

Would you be open to that, or are you opposed to adding that dependency?

gtest and gmock are some of the easiest to use of the c++ testing frameworks IMO, and well supported.

@kevingranade
Copy link
Member Author

I'm not a fan of adding dependencies, but since testing isn't mandatory for building, this could be a reasonable exception. If you make a PR with some working and useful tests to get the ball rolling, I can't see turning it down.
I'm curious though, what about google test makes it better than e.g. Catch? I'm finding that most of the pain seems to be getting the test code to run at all, reporting test results in particular is trivial in comparison.

@boydkr
Copy link
Contributor

boydkr commented Oct 26, 2014

I guess it's really the mocking frameworks that are more differentiated than the testing frameworks themselves.

I don't have more than a passing familiarity with Catch, does it support mocking?

Being able to break internal dependencies (and external dependencies) with mocks makes testing complicated stuff an order of magnitude easier.

@kevingranade
Copy link
Member Author

Refreshed again, this should build on any platform dda can build on in the first place since Catch is pulled into the repository, and it has some reasonable tests now.

@@ -14,9 +14,10 @@ SOURCE_OBJS = $(patsubst %,../$(ODIR)/%,$(filter-out main.o,$(_OBJS)))

ODIR := obj

LDFLAGS += -L. -ltap++ -lboost_regex -lpthread
LDFLAGS += -L.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On my system, I need to add -lrt to get clock_gettime.

@kevingranade
Copy link
Member Author

Good to go I think, the player temperature test still doesn't work, but the right fix for that is breaking the player/game/map dependency thicket, and that's going to take some time.

@kevingranade
Copy link
Member Author

Anybody? I can guarantee it's not going to break anything >_<

@Rivet-the-Zombie
Copy link
Member

I've held off on this because I'm not familiar enough with unit tests to properly mergetest it. If nobody else does so before then, I'll attempt to mergetest it in a few days.

@kevingranade
Copy link
Member Author

kevingranade commented May 21, 2015 via email

@Rivet-the-Zombie Rivet-the-Zombie self-assigned this May 24, 2015
Rivet-the-Zombie added a commit that referenced this pull request May 24, 2015
@Rivet-the-Zombie Rivet-the-Zombie merged commit 4b850a0 into CleverRaven:master May 24, 2015
@kevingranade kevingranade deleted the unittest-build-fix branch April 30, 2018 01:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
(S2 - Confirmed) Bug that's been confirmed to exist
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants