Class: Scan::Runner
- Inherits:
-
Object
- Object
- Scan::Runner
- Defined in:
- scan/lib/scan/runner.rb
Instance Method Summary collapse
- #copy_simulator_logs ⇒ Object
- #handle_results(tests_exit_status) ⇒ Object
-
#initialize ⇒ Runner
constructor
A new instance of Runner.
- #open_simulator_for_device(device) ⇒ Object
- #run ⇒ Object
- #test_app ⇒ Object
- #test_results ⇒ Object
Constructor Details
#initialize ⇒ Runner
Returns a new instance of Runner.
17 18 19 |
# File 'scan/lib/scan/runner.rb', line 17 def initialize @test_command_generator = TestCommandGenerator.new end |
Instance Method Details
#copy_simulator_logs ⇒ Object
110 111 112 113 114 115 116 117 118 |
# File 'scan/lib/scan/runner.rb', line 110 def copy_simulator_logs return unless Scan.config[:include_simulator_logs] UI.header("Collecting system logs") Scan.devices.each do |device| log_identity = "#{device.name}_#{device.os_type}_#{device.os_version}" FastlaneCore::Simulator.copy_logs(device, log_identity, Scan.config[:output_directory]) end end |
#handle_results(tests_exit_status) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'scan/lib/scan/runner.rb', line 61 def handle_results(tests_exit_status) result = TestResultParser.new.parse_result(test_results) SlackPoster.new.run(result) if result[:failures] > 0 failures_str = result[:failures].to_s.red else failures_str = result[:failures].to_s.green end puts(Terminal::Table.new({ title: "Test Results", rows: [ ["Number of tests", result[:tests]], ["Number of failures", failures_str] ] })) puts("") copy_simulator_logs if result[:failures] > 0 UI.test_failure!("Tests have failed") end unless tests_exit_status == 0 UI.test_failure!("Test execution failed. Exit status: #{tests_exit_status}") end if !Helper.ci? && Scan.cache[:open_html_report_path] `open --hide '#{Scan.cache[:open_html_report_path]}'` end end |
#open_simulator_for_device(device) ⇒ Object
120 121 122 123 124 125 126 127 |
# File 'scan/lib/scan/runner.rb', line 120 def open_simulator_for_device(device) return unless FastlaneCore::Env.truthy?('FASTLANE_EXPLICIT_OPEN_SIMULATOR') UI.("Killing all running simulators") `killall Simulator &> /dev/null` FastlaneCore::Simulator.launch(device) end |
#run ⇒ Object
21 22 23 |
# File 'scan/lib/scan/runner.rb', line 21 def run handle_results(test_app) end |
#test_app ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'scan/lib/scan/runner.rb', line 25 def test_app # We call this method, to be sure that all other simulators are killed # And a correct one is freshly launched. Switching between multiple simulator # in case the user specified multiple targets works with no issues # This way it's okay to just call it for the first simulator we're using for # the first test run open_simulator_for_device(Scan.devices.first) if Scan.devices command = @test_command_generator.generate prefix_hash = [ { prefix: "Running Tests: ", block: proc do |value| value.include?("Touching") end } ] exit_status = 0 FastlaneCore::CommandExecutor.execute(command: command, print_all: true, print_command: true, prefix: prefix_hash, loading: "Loading...", error: proc do |error_output| begin exit_status = $?.exitstatus ErrorHandler.handle_build_error(error_output) rescue => ex SlackPoster.new.run({ build_errors: 1 }) raise ex end end) exit_status end |
#test_results ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'scan/lib/scan/runner.rb', line 95 def test_results temp_junit_report = Scan.cache[:temp_junit_report] return File.read(temp_junit_report) if temp_junit_report && File.file?(temp_junit_report) # Something went wrong with the temp junit report for the test success/failures count. # We'll have to regenerate from the xcodebuild log, like we did before version 2.34.0. UI.("Generating test results. This may take a while for large projects.") = XCPrettyReporterOptionsGenerator.new(false, [], [], "", false) = . cmd = "cat #{@test_command_generator.xcodebuild_log_path.shellescape} | xcpretty #{.join(' ')} &> /dev/null" system(cmd) File.read(Scan.cache[:temp_junit_report]) end |