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

Partially resolve #257: video_test #270

Merged
merged 3 commits into from
Aug 19, 2023
Merged

Partially resolve #257: video_test #270

merged 3 commits into from
Aug 19, 2023

Conversation

smcv
Copy link
Contributor

@smcv smcv commented Aug 19, 2023

PR Description

This brings py-sdl2 a bit closer to fully resolving #257, by reducing the number of places where it assumes SDL_GetError != '' implies that there was an error. #267, #269, etc. are targeted versions of this addressing places where a newer SDL2 release does break that assumption, whereas this PR is a preventative version addressing places where a newer SDL2 release might break that assumption but has not done so yet.

This PR only covers video_test, treating all other tests as out-of-scope. Many other test modules will eventually need a change similar to this one.

  • video_test: Don't check error unless a function failed

    Helps: Incorrect use of SDL_GetError() to check whether calls failed #257

  • video_test: Use _check_error_msg() a bit more often

  • video_test: Mitigate unsuitability of SDL_GetError() for detecting failure

    SDL_GetError() is like errno: it's documented not to be suitable for
    detecting failure, only for getting more details if failure was already
    detected (its result is unspecified on success, because a successful
    API call might have been implemented by doing something that failed,
    detecting that, and falling back to doing something different).
    However, some functions in SDL2 return void, so we have no other way
    to tell whether they have failed (they do return a result in SDL3).

    To make it less likely that upgrading SDL2 will make these tests regress,
    clear the error indicator immediately before calling the function under
    test. It is still not guaranteed to be empty on success, but at least
    this way we make sure it doesn't already contain an error message from
    a previous function call.

    Helps: Incorrect use of SDL_GetError() to check whether calls failed #257

Merge Checklist

  • the PR has been reviewed and all comments are resolved
  • all CI checks pass
  • (if applicable): the PR description includes the phrase closes #<issue-number> to automatically close an issue
  • (if applicable): bug fixes, new features, or API changes are documented in news.rst

…ilure

SDL_GetError() is like errno: it's documented not to be suitable for
detecting failure, only for getting more details if failure was already
detected (its result is unspecified on success, because a successful
API call might have been implemented by doing something that failed,
detecting that, and falling back to doing something different).
However, some functions in SDL2 return void, so we have no other way
to tell whether they have failed (they do return a result in SDL3).

To make it less likely that upgrading SDL2 will make these tests regress,
clear the error indicator immediately before calling the function under
test. It is still not guaranteed to be empty on success, but at least
this way we make sure it doesn't already contain an error message from
a previous function call.

Helps: py-sdl#257
Signed-off-by: Simon McVittie <[email protected]>
@a-hurst
Copy link
Member

a-hurst commented Aug 19, 2023

Thanks again, I'll try combing through the other test modules and fixing the other spots I missed!

I also like the convention of documenting the checks that aren't 100% safe for the functions that return void, I'll try to keep that up elsewhere too.

@a-hurst a-hurst merged commit ed28ea6 into py-sdl:master Aug 19, 2023
32 checks passed
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

Successfully merging this pull request may close these issues.

None yet

2 participants