Since ref tests were only stored whenever winit requested the window
close, they would not get stored properly when the terminal was closed
through Alacritty using `exit`, Ctrl+D or similar.
This moves the ref test code to the and of the main entry point, which
will always be executed regardless of how the terminal was shutdown.
Fixes#2613.