consistently save/restore state when running tests

[?]
Jan 24, 2023, 4:29 AM
JOLUCIT6HFXFKYQ6PNGSNBF4GBYDA6ATVOITT2SYGJH7HBURTDDAC

Dependencies

  • [2] LYIV4YOL make run_test look like run_tests
  • [3] LSWOBVHD undo font changes when running tests
  • [4] D5J7IZAD debug helper: run a single test
  • [5] LRDM35CE app running again
  • [6] K7YGVRXH generalize the protocol to return errors, etc.
  • [7] JNJ4R56X support running tests multiple times
  • [8] 5ZCQGZP5 save 2 more alternate formats for test failures
  • [9] FFFJ54GJ restore globals after running tests
  • [10] S4IAYCIR delete all tests once they've executed
  • [11] 3BRGOF7N return failing tests with every code change
  • [12] OETGXCQM rename
  • [13] 2NTKHMLG configurable error handler when running tests
  • [14] FFMMA7L2 send Test_failures _before_ restoring globals
  • [15] BC4SO6AR clean up a print
  • [16] AVTNUQYR basic test-enabled framework
  • [17] FCFJVYKY redundant check
  • [18] ORRSP7FV deduce test names on failures
  • [19] D76AELSV deduplicate an initialization
  • [20] CZQ3NJ4N Merge text0
  • [21] IMEJA43L snapshot
  • [22] 3QMTXKWN rename
  • [*] 3QNOKBFM beginnings of a test harness

Change contents

  • edit in live.lua at line 282
    [4.30][4.30:82](),[4.82][3.9:112]()
    local globals = live.shallow_copy_all_globals()
    local current_font = love.graphics.getFont()
    love.graphics.setFont(Love_snapshot.initial_font)
  • edit in live.lua at line 285
    [4.59][3.113:153](),[4.59][4.83:121](),[3.153][4.83:121](),[4.100][4.83:121](),[4.39][4.122:481]()
    love.graphics.setFont(current_font)
    live.restore_all_globals(globals)
    end
    end
    function live.shallow_copy_all_globals()
    local result = {}
    for k,v in pairs(_G) do
    result[k] = v
    end
    return result
    end
    function live.restore_all_globals(x)
    -- delete extra bindings
    for k,v in pairs(_G) do
    if x[k] == nil then
    _G[k] = nil
    end
    end
    -- restore previous bindings
    for k,v in pairs(x) do
    _G[k] = v
  • replacement in app.lua at line 431
    [4.8001][4.1935:1959]()
    local saved_app = App
    [4.8001]
    [4.1959]
    local globals = App.shallow_copy_all_globals()
  • edit in app.lua at line 433
    [4.1981]
    [4.8001]
    local saved_font = love.graphics.getFont()
    love.graphics.setFont(Love_snapshot.initial_font)
  • replacement in app.lua at line 440
    [4.7554][4.18:36]()
    App = saved_app
    [4.7554]
    [4.36]
    love.graphics.setFont(saved_font)
    -- restore all global state except Test_errors
    local test_errors = Test_errors
    App.restore_all_globals(globals)
    Test_errors = test_errors
  • replacement in app.lua at line 448
    [2.63][4.69:93](),[4.69][4.69:93]()
    local saved_app = App
    [2.63]
    [4.93]
    local globals = App.shallow_copy_all_globals()
  • replacement in app.lua at line 450
    [4.115][4.115:143](),[4.143][2.64:123](),[2.123][4.2065:2083](),[4.175][4.2065:2083](),[4.187][4.2065:2083](),[4.221][4.2065:2083](),[4.7564][4.2065:2083]()
    App.initialize_for_test()
    xpcall(test, function(err) record_error_fn('', err) end)
    App = saved_app
    [4.115]
    [4.7564]
    local saved_font = love.graphics.getFont()
    love.graphics.setFont(Love_snapshot.initial_font)
    App.initialize_for_test()
    xpcall(test, function(err) record_error_fn('', err) end)
    love.graphics.setFont(saved_font)
    -- restore all global state except Test_errors
    local test_errors = Test_errors
    App.restore_all_globals(globals)
    Test_errors = test_errors
    end
    function App.shallow_copy_all_globals()
    local result = {}
    for k,v in pairs(_G) do
    result[k] = v
    end
    return result
    end
    function App.restore_all_globals(x)
    -- delete extra bindings
    for k,v in pairs(_G) do
    if x[k] == nil then
    _G[k] = nil
    end
    end
    -- restore previous bindings
    for k,v in pairs(x) do
    _G[k] = v
    end