On Thu Apr 4 19:23:35 2024 +0000, Piotr Caban wrote:
I don't like how the tests are written. It seems to be over complicated while not testing much on Windows (because of the broken case). The tests are also not deleting some files. Did you consider something along these lines to detect if FILE is buffered?
struct UCRT_FILE *err = (struct UCRT_FILE *)stderr; int fd = fileno(stderr); ok(fd == err->_file, "unknown FILE layout\n"); err->_file = 0; ok(freopen("test.log", "w", stderr) != NULL, "freopen failed\n"); ok(fprintf(stderr, "out\n") == 4, "fprintf failed\n"); ok(_tell(fileno(stderr)) == 4, "expected file to be unbuffered\n"); fflush(stderr); close(fileno(stderr)); err->_file = fd;
It reduces the information we need to know about FILE layout to one field (_file). It's also hacky but looks much simpler for me. Also it would be nice to find a way to detect older versions of ucrtbase so you don't end doing:
long pos = _tell(fileno(stderr)); ok(pos == 4 || broken(!pos), ...);
Do you know if there's a new function export that can be used to skip the tests on older version of ucrtbase?
I think it's even better to test stderr in new process so we don't have to restore it after test. This way we don't need to know FILE layout at all.