From 57fb2d4b57db3fef5245d40e16f5ea811c3806a4 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Fri, 12 Jan 2024 03:03:31 -0800 Subject: [PATCH] clean up test mocks before aborting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Scenario: modify a test to fail in the source editor delete any settings in the 'config' file in the save dir start lines.love press C-e to switch to source editor Before this commit, this scenario led to the following events: the C-e keypress invokes App.run_tests_and_initialize() the failing test results in a call to error() the call to error() is trapped by the xpcall around the event handler in love.run handle_error runs Current_app is 'source', so love.event.quit() is triggered love.quit() is invoked source.settings() is invoked App.screen.position() is invoked, which calls the test mock Since App.screen.move was never invoked, App.screen.position() returns nil The 'config' file is written without values for source.x and source.y As a result, future runs fail to open. This is likely a corner case only I will ever run into, since I'm careful to never commit failing unit tests. Still, I spent some time trying to figure out the best place to fix this. Options: * don't write config if Error_message is set but we do want config written in this scenario: * we hit an error, source editor opens * we spend some time debugging and don't immediately fix the issue * we quit, with some new files opened in various places * hardcode source.settings() to call love.window.getPosition() rather than App.screen.position(). drawback: weird special case * clean up test mocks before aborting this seems like something we always want I'm not very sure of my choice. This bug doesn't leave me feeling very great about my whole app. Arguably everything I've done is bullshit hacks piled on hacks. Perhaps the issue is: - naked error() in LÖVE apps never invokes love.quit(), but - an unhandled error within my handle_error invokes love.quit() (via love.event.quit) Perhaps LÖVE should provide a way to abort without invoking the quit handler. There's literally no other way in LÖVE to request a quit. --- app.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/app.lua b/app.lua index 725d380..ac8e709 100644 --- a/app.lua +++ b/app.lua @@ -53,6 +53,7 @@ function handle_error(err) App.undo_initialize() App.run_tests_and_initialize() else + if App.disable_tests then App.disable_tests() end love.event.quit() end end