-
Notifications
You must be signed in to change notification settings - Fork 187
Allow allocators in testing #2320
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
base: master
Are you sure you want to change the base?
Conversation
|
I discourage this change. Sharing allocators, or in more general terms, resources across tests may result in absurd interactions which are very hard to track down. |
IntegratedQuantum
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also reroute the stack allocator to the testing_allocator, the testing code should run without any additional setup, and most importantly it should do leak tests without you having to remember to call deinitThreadLocals.
| globalArenaAllocator = undefined; | ||
| if(globalGpa.deinit() == .leak) { | ||
| std.log.err("Memory leak", .{}); | ||
| if(!builtin.is_test) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function shouldn't be called during testing.
| pub var globalGpa = std.heap.GeneralPurposeAllocator(.{.thread_safe = true}){}; | ||
| pub var handledGpa = ErrorHandlingAllocator.init(globalGpa.allocator()); | ||
| pub var globalGpa: std.heap.GeneralPurposeAllocator(.{.thread_safe = true}) = if(builtin.is_test) undefined else .init; | ||
| pub var handledGpa = ErrorHandlingAllocator.init(if(builtin.is_test) std.testing.allocator else globalGpa.allocator()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion this should be done at the declaration of the interface. Instead I'd propose to have a globally accessible testing allocator that is std.testing.allocator wrapped in the error handling allocator.
Fixes #1286