From 01a26cad5f0abcd9aeb010ba91d33bcdb570256f Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Wed, 6 Dec 2023 20:14:24 -0800 Subject: redo version checks This is still ugly, but hopefully easier to follow. --- Manual_tests.md | 5 +++-- app.lua | 17 ++++++++++++++--- main.lua | 37 ++++++++++++++++++++----------------- reference.md | 3 +++ 4 files changed, 40 insertions(+), 22 deletions(-) diff --git a/Manual_tests.md b/Manual_tests.md index 2b8df26..12d3a66 100644 --- a/Manual_tests.md +++ b/Manual_tests.md @@ -17,7 +17,7 @@ Initializing settings: - start out editing source, move window, press ctrl+e twice; window is editing source in same position+dimensions - no log file; switching to source works - - run with an unsupported version. Error message pops up and waits for a key. The app attempts to continue, and doesn't receive the key. + - run with an untested version. Error message pops up and waits for a key. The app attempts to continue, and doesn't receive the key. - run with a LÖVE v12 release candidate. No errors; it is a supported version. All tests pass. Code loading: @@ -30,7 +30,8 @@ Code loading: - analogously, how a shape precisely looks as you draw it * start out running the text editor, press ctrl+e to edit source, make a change to the source, press ctrl+e twice to return to the source editor; the change should be preserved. -* run with an unsupported version. Error message pops up and waits for a key. The app attempts to continue, and doesn't receive the key. Press ctrl+e to edit source. Source editor opens up without checking version. +* run with an untested version. Error message pops up. Press a key. Text editor comes up, and doesn't receive the key. Press ctrl+e. Source editor opens up. Press ctrl+e. Text editor returns. +* create a couple of spuriously failing tests. Run with an untested version. Error message includes message about untested version. ### Other compromises diff --git a/app.lua b/app.lua index 57533f1..32c6f00 100644 --- a/app.lua +++ b/app.lua @@ -8,11 +8,11 @@ -- and a source editor, while giving each the illusion of complete -- control. function love.run() - App.version_check() + Version, Major_version = App.love_version() App.snapshot_love() -- Tests always run at the start. App.run_tests_and_initialize() - App.version_check() + App.love_version_check() -- hack: we want to run this just the first time and not every time we bounce between 'run' and 'source' --? print('==') love.timer.step() @@ -86,6 +86,12 @@ end App = {} +function App.love_version() + local major_version, minor_version = love.getVersion() + local version = major_version..'.'..minor_version + return version, major_version +end + -- save/restore various framework globals we care about -- only on very first load function App.snapshot_love() if Love_snapshot then return end @@ -103,7 +109,12 @@ function App.run_tests_and_initialize() Test_errors = {} App.run_tests() if #Test_errors > 0 then - error(('There were %d test failures:\n\n%s'):format(#Test_errors, table.concat(Test_errors))) + local error_message = '' + if Warning_before_tests then + error_message = Warning_before_tests..'\n\n' + end + error_message = error_message .. ('There were %d test failures:\n%s'):format(#Test_errors, table.concat(Test_errors)) + error(error_message) end App.disable_tests() App.initialize_globals() diff --git a/main.lua b/main.lua index 034953e..af53451 100644 --- a/main.lua +++ b/main.lua @@ -72,24 +72,10 @@ function App.load() end end -function App.version_check() - -- available modes: run, error - Error_message = nil - Error_count = 0 - -- we'll reuse error mode on load for an initial version check - local supported_versions = {'11.5', '11.4', '12.0'} -- put the recommended version first - local minor_version - Major_version, minor_version = love.getVersion() - Version = Major_version..'.'..minor_version - if array.find(supported_versions, Version) == nil then - Current_app = 'error' - Error_message = ("This app doesn't support version %s; please use version %s. Press any key to try it with this version anyway."):format(Version, supported_versions[1]) - print(Error_message) - -- continue initializing everything; hopefully we won't have errors during initialization - end -end - function App.initialize_globals() + Supported_versions = {'11.5', '11.4', '12.0'} -- put the recommended version first + check_love_version_for_tests() + if Current_app == 'run' then run.initialize_globals() elseif Current_app == 'source' then @@ -105,6 +91,23 @@ function App.initialize_globals() Last_resize_time = 0 end +function check_love_version_for_tests() + if array.find(Supported_versions, Version) == nil then + Unsupported_version = true + -- warning to include in an error message if any tests failed + Warning_before_tests = ("This app hasn't been tested with LÖVE version %s."):format(Version) + end +end + +function App.love_version_check() + if Unsupported_version then + Current_app = 'error' + Error_message = ("This app hasn't been tested with LÖVE version %s; please switch to version %s if you run into issues. Press any key to continue."):format(Version, Supported_versions[1]) + print(Error_message) + -- continue initializing everything; hopefully we won't have errors during initialization + end +end + function App.initialize(arg) love.keyboard.setTextInput(true) -- bring up keyboard on touch screen love.keyboard.setKeyRepeat(true) diff --git a/reference.md b/reference.md index 4dde57d..916c8f4 100644 --- a/reference.md +++ b/reference.md @@ -11,6 +11,9 @@ automatically called for you as appropriate. * `flags` -- some properties of the app window. See [`flags` in `love.graphics.getMode`](https://love2d.org/wiki/love.window.getMode) for details. +* `Version` -- the running version of LÖVE as a string, e.g. '11.4'. +* `Major_version` -- just the part before the period as an int, e.g. 11. + ## Functions that get automatically called * `App.initialize_globals()` -- called before running each test and also -- cgit 1.4.1-2-gfad0