pygame-community / pygame-ce

🐍🎮 pygame - Community Edition is a FOSS Python library for multimedia applications (like games). Built on top of the excellent SDL library.
https://pyga.me
883 stars 145 forks source link

Writing tests for C-API functions? #2467

Open oddbookworm opened 1 year ago

oddbookworm commented 1 year ago

I think it would be a good idea to start having some tests for the underlying C code. All we have now is basically integration testing in a lot of places, which has given a lot of weird and oddly specific bugs. I'm not immediately sure how best we could do this, but I'm looking for opinions before I try to dig too deep into it

Starbuck5 commented 1 year ago

Most internals are strongly tied to specific functions, I'm not sure where exactly we would get good opportunities and upside from this.

The other question is "how"-- you might be able to extract C functions from how the internal pygame APIs publish functions for each (in pycapsules I think).

oddbookworm commented 1 year ago

@MyreMylar suggested making a dedicated module that tests return values of internal functions in python-callable functions. I've been tossing around a few other ideas, but I volunteered to do this in discord if I can find a solution I'm happy with

oddbookworm commented 1 year ago

Where I work, we test our code by compiling in a test harness that allows us to test our code line-by-line practically. That would be super useful to have here, but way overkill methinks

oddbookworm commented 1 year ago

The purpose would be to test edge cases where possible. Like if a function has a calculation internally, we could try to create an overflow condition and see what happens

Starbuck5 commented 1 year ago

Internals-aware edge cases can be tested as part of the overall test for the function.

Check out things like pygame.surface._PYGAME_C_API, these things are already sort of accessible.

MyreMylar commented 1 year ago

My suggestion was based on CPythons C API test module.

On Thu, 28 Sept 2023, 04:22 Charlie Hayden, @.***> wrote:

Internals-aware edge cases can be tested as part of the overall test for the function.

Check out things like pygame.surface._PYGAME_C_API, these things are already sort of accessible.

— Reply to this email directly, view it on GitHub https://github.com/pygame-community/pygame-ce/issues/2467#issuecomment-1738378991, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADGDGGTRNP2XT7YZXFRJAU3X4TUPFANCNFSM6AAAAAA5ET35SY . You are receiving this because you were mentioned.Message ID: @.***>