Implementing unit tests in Angband variants

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Therem Harth
    Knight
    • Jan 2008
    • 926

    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...)
  • Nick
    Vanilla maintainer
    • Apr 2007
    • 9638

    #2
    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.

    Comment

    • Therem Harth
      Knight
      • Jan 2008
      • 926

      #3
      Hadn't even noticed that V had those. Thanks. I'll take a look tomorrow.

      Comment

      • Therem Harth
        Knight
        • Jan 2008
        • 926

        #4
        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.

        Comment

        • takkaria
          Veteran
          • Apr 2007
          • 1951

          #5
          Originally posted by Therem Harth
          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-

          Comment

          • Therem Harth
            Knight
            • Jan 2008
            • 926

            #6
            Right... D'oh. I fail at reading comprehension. Anyway I may finally get to this today, who knows...

            Comment

            Working...
            😀
            😂
            🥰
            😘
            🤢
            😎
            😞
            😡
            👍
            👎