From 13e096945f819ae85633308994f9f0c55f1176ff Mon Sep 17 00:00:00 2001 From: Thomas Thomassen Date: Tue, 3 Sep 2024 15:20:55 +0200 Subject: [PATCH] Catch Ruby error while TestUp runs the unit tests and dump it to a log file. --- README.md | 5 +++++ src/testup/app.rb | 12 +++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b7a1f2a..28c76dc 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,11 @@ Output: C:\Users\Thomas\SourceTree\TestUp2\tests\results.json # Overriding where the .log files from a test run will be saved. LogPath: C:\Users\Thomas\SourceTree\TestUp2\logs +# Optional: +# Path to a .log file that will be used if TestUp itself runs into any errors +# while running the tests. +ErrorLogPath: C:\Users\Thomas\SourceTree\TestUp2\testup_errors.log + # Optional: # Overriding where the .run files from a test run will be saved. SavedRunsPath: C:\Users\Thomas\SourceTree\TestUp2\logs diff --git a/src/testup/app.rb b/src/testup/app.rb index b6f7302..88cc2a4 100644 --- a/src/testup/app.rb +++ b/src/testup/app.rb @@ -28,7 +28,17 @@ def self.process_arguments # @param [Hash] config def self.ci_run(test_suite, config = {}) Execution.delay(1.0) do - API.run_suite_without_gui(test_suite, config) + begin + API.run_suite_without_gui(test_suite, config) + rescue Exception => error + # Ensure we log the error to a file so the CI system can log it. + if config['ErrorLogPath'] + File.open(config['ErrorLogPath'], 'w') { |file| + file.puts(error.inspect) + file.puts(error.backtrace.join("\n")) + } + end + end self.quit unless config['KeepOpen'] end end