Angband.oook.cz
Angband.oook.cz
AboutVariantsLadderForumCompetitionComicScreenshotsFunniesLinks

Go Back   Angband Forums > Angband > Development

Reply
 
Thread Tools Display Modes
Old December 2, 2015, 21:48   #1
Therem Harth
Knight
 
Therem Harth's Avatar
 
Join Date: Jan 2008
Location: New England winter
Posts: 921
Therem Harth is on a distinguished road
Implementing unit tests in Angband variants

What would be a sensible way of doing this?

My first thought is along the lines of
- Put the unit tests in a shared object library
- LD_PRELOAD it when you want them to run
- Somehow make sure the tests are run by main() when the library is preloaded
- ???
- Profit!

This does not seem ideal. My second thought is more along the lines of
- Put the function unit tests in the same files as the code they test
- Put the module unit tests in separate files with sensible names
- Compile everything into the default binary
- Have a testing build flag, which enables running all those tests on startup

This does not seem ideal either.

Third thought:
- Have some fancy preprocessor macros for enabling the tests when building a test binary
- Additionally, have command line switches to invoke various tests as needed on startup
- etc. etc. etc.

Far from being ideal, this seems outright insane.

Is there any good way to unit test a single-binary game, with no clean separation between interface and implementation and whatever else? Or does the lack of such a thing just come with the territory?

(Why yes, I am still working on Neoband, whyever do you ask...)
Therem Harth is offline   Reply With Quote
Old December 2, 2015, 21:57   #2
Nick
Vanilla maintainer
 
Nick's Avatar
 
Join Date: Apr 2007
Location: Canberra, Australia
Age: 54
Posts: 7,836
Donated: $60
Nick will become famous soon enough
Have you seen the way the Vanilla unit tests work? This seems pretty good (my involvement in it has been minimal ) - the main improvement would be writing more tests. See src/tests/README (and also tests/README for end-to-end tests).
__________________
One for the Dark Lord on his dark throne
In the Land of Mordor where the Shadows lie.
Nick is offline   Reply With Quote
Old December 3, 2015, 03:00   #3
Therem Harth
Knight
 
Therem Harth's Avatar
 
Join Date: Jan 2008
Location: New England winter
Posts: 921
Therem Harth is on a distinguished road
Hadn't even noticed that V had those. Thanks. I'll take a look tomorrow.
Therem Harth is offline   Reply With Quote
Old December 7, 2015, 12:00   #4
Therem Harth
Knight
 
Therem Harth's Avatar
 
Join Date: Jan 2008
Location: New England winter
Posts: 921
Therem Harth is on a distinguished road
Whoops, life interceded and I took a while to get to it. Let's see.

... Okay I really goofed on the Neoband bookless magic system, most of the functions are very difficult to test.

But thanks, this looks a lot better than what I was working on earlier! We'll see, I guess.

Edit: wait, the test data is hardcoded in one header file? I'm confused.
Therem Harth is offline   Reply With Quote
Old December 7, 2015, 18:22   #5
takkaria
Veteran
 
takkaria's Avatar
 
Join Date: Apr 2007
Posts: 1,936
Donated: $40
takkaria is on a distinguished road
Quote:
Originally Posted by Therem Harth View Post
Whoops, life interceded and I took a while to get to it. Let's see.

... Okay I really goofed on the Neoband bookless magic system, most of the functions are very difficult to test.

But thanks, this looks a lot better than what I was working on earlier! We'll see, I guess.

Edit: wait, the test data is hardcoded in one header file? I'm confused.
I suggest reading the README, it explains everything pretty well!
__________________
takkaria whispers something about options. -more-
takkaria is offline   Reply With Quote
Old December 9, 2015, 16:47   #6
Therem Harth
Knight
 
Therem Harth's Avatar
 
Join Date: Jan 2008
Location: New England winter
Posts: 921
Therem Harth is on a distinguished road
Right... D'oh. I fail at reading comprehension. Anyway I may finally get to this today, who knows...
Therem Harth is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Implementing the restructure changes PowerWyrm Development 244 October 28, 2015 17:55
What are the current Angband variants? Monarch1st Variants 2 December 10, 2013 09:19
List of all Angband variants relic Variants 10 May 14, 2012 06:07
Implementing different difficulty levels Greebley Vanilla 14 January 11, 2012 15:39
New features for Angband from variants andrewdoull Vanilla 100 October 19, 2007 04:14


All times are GMT +1. The time now is 08:43.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.