Class: Scan::TestCommandGenerator
- Inherits:
-
Object
- Object
- Scan::TestCommandGenerator
- Defined in:
- scan/lib/scan/test_command_generator.rb
Overview
Responsible for building the fully working xcodebuild command
Instance Method Summary collapse
- #actions ⇒ Object
-
#build_path ⇒ Object
The path to set the Derived Data to.
-
#destination ⇒ Object
Generate destination parameters.
- #generate ⇒ Object
-
#options ⇒ Object
rubocop:disable Metrics/PerceivedComplexity.
- #pipe ⇒ Object
- #prefix ⇒ Object
-
#project_path_array ⇒ Array
Path to the project or workspace as parameter This will also include the scheme (if given).
- #result_bundle_path ⇒ Object
- #suffix ⇒ Object
-
#xcodebuild_log_path ⇒ Object
Store the raw file.
Instance Method Details
#actions ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'scan/lib/scan/test_command_generator.rb', line 67 def actions config = Scan.config actions = [] actions << :clean if config[:clean] if config[:build_for_testing] actions << "build-for-testing" elsif config[:test_without_building] || config[:xctestrun] actions << "test-without-building" else actions << :build unless config[:skip_build] actions << :test end actions end |
#build_path ⇒ Object
The path to set the Derived Data to
150 151 152 153 154 155 156 157 158 |
# File 'scan/lib/scan/test_command_generator.rb', line 150 def build_path unless Scan.cache[:build_path] day = Time.now.strftime("%F") # e.g. 2015-08-07 Scan.cache[:build_path] = File.("~/Library/Developer/Xcode/Archives/#{day}/") FileUtils.mkdir_p(Scan.cache[:build_path]) end Scan.cache[:build_path] end |
#destination ⇒ Object
Generate destination parameters
142 143 144 145 146 147 |
# File 'scan/lib/scan/test_command_generator.rb', line 142 def destination unless Scan.cache[:destination] Scan.cache[:destination] = [*Scan.config[:destination]].map { |dst| "-destination '#{dst}'" }.join(' ') end Scan.cache[:destination] end |
#generate ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'scan/lib/scan/test_command_generator.rb', line 6 def generate parts = prefix parts << Scan.config[:xcodebuild_command] parts += parts += actions parts += suffix parts += pipe parts end |
#options ⇒ Object
rubocop:disable Metrics/PerceivedComplexity
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 60 61 62 63 64 65 |
# File 'scan/lib/scan/test_command_generator.rb', line 30 def # rubocop:disable Metrics/PerceivedComplexity config = Scan.config = [] += project_path_array unless config[:xctestrun] << "-sdk '#{config[:sdk]}'" if config[:sdk] << destination # generated in `detect_values` << "-toolchain '#{config[:toolchain]}'" if config[:toolchain] << "-derivedDataPath '#{config[:derived_data_path]}'" if config[:derived_data_path] << "-resultBundlePath '#{result_bundle_path}'" if config[:result_bundle] if FastlaneCore::Helper.xcode_at_least?(10) << "-parallel-testing-worker-count #{config[:concurrent_workers]}" if config[:concurrent_workers] << "-maximum-concurrent-test-simulator-destinations #{config[:max_concurrent_simulators]}" if config[:max_concurrent_simulators] << "-disable-concurrent-testing" if config[:disable_concurrent_testing] end << "-enableCodeCoverage #{config[:code_coverage] ? 'YES' : 'NO'}" unless config[:code_coverage].nil? << "-enableAddressSanitizer #{config[:address_sanitizer] ? 'YES' : 'NO'}" unless config[:address_sanitizer].nil? << "-enableThreadSanitizer #{config[:thread_sanitizer] ? 'YES' : 'NO'}" unless config[:thread_sanitizer].nil? if FastlaneCore::Helper.xcode_at_least?(11) << "-testPlan '#{config[:testplan]}'" if config[:testplan] # detect_values will ensure that these values are present as Arrays if # they are present at all += config[:only_test_configurations].map { |name| "-only-test-configuration '#{name}'" } if config[:only_test_configurations] += config[:skip_test_configurations].map { |name| "-skip-test-configuration '#{name}'" } if config[:skip_test_configurations] end << "-xctestrun '#{config[:xctestrun]}'" if config[:xctestrun] << config[:xcargs] if config[:xcargs] # detect_values will ensure that these values are present as Arrays if # they are present at all += config[:only_testing].map { |test_id| "-only-testing:#{test_id.shellescape}" } if config[:only_testing] += config[:skip_testing].map { |test_id| "-skip-testing:#{test_id.shellescape}" } if config[:skip_testing] end |
#pipe ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'scan/lib/scan/test_command_generator.rb', line 90 def pipe pipe = ["| tee '#{xcodebuild_log_path}'"] if Scan.config[:disable_xcpretty] || Scan.config[:output_style] == 'raw' return pipe end formatter = [] if (custom_formatter = Scan.config[:formatter]) if custom_formatter.end_with?(".rb") formatter << "-f '#{custom_formatter}'" else formatter << "-f `#{custom_formatter}`" end elsif FastlaneCore::Env.truthy?("TRAVIS") formatter << "-f `xcpretty-travis-formatter`" UI.success("Automatically switched to Travis formatter") end if Helper.colors_disabled? formatter << "--no-color" end if Scan.config[:output_style] == 'basic' formatter << "--no-utf" end if Scan.config[:output_style] == 'rspec' formatter << "--test" end @reporter_options_generator = XCPrettyReporterOptionsGenerator.new(Scan.config[:open_report], Scan.config[:output_types], Scan.config[:output_files] || Scan.config[:custom_report_file_name], Scan.config[:output_directory], Scan.config[:use_clang_report_name], Scan.config[:xcpretty_args]) = @reporter_options_generator. reporter_xcpretty_args = @reporter_options_generator. return pipe << "| xcpretty #{formatter.join(' ')} #{.join(' ')} #{reporter_xcpretty_args}" end |
#prefix ⇒ Object
17 18 19 |
# File 'scan/lib/scan/test_command_generator.rb', line 17 def prefix ["set -o pipefail &&"] end |
#project_path_array ⇒ Array
Path to the project or workspace as parameter This will also include the scheme (if given)
24 25 26 27 28 |
# File 'scan/lib/scan/test_command_generator.rb', line 24 def project_path_array proj = Scan.project.xcodebuild_parameters return proj if proj.count > 0 UI.user_error!("No project/workspace found") end |
#result_bundle_path ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 |
# File 'scan/lib/scan/test_command_generator.rb', line 160 def result_bundle_path unless Scan.cache[:result_bundle_path] ext = FastlaneCore::Helper.xcode_version.to_i >= 11 ? '.xcresult' : '.test_result' path = File.join(Scan.config[:output_directory], Scan.config[:scheme]) + ext if File.directory?(path) FileUtils.remove_dir(path) end Scan.cache[:result_bundle_path] = path end return Scan.cache[:result_bundle_path] end |
#suffix ⇒ Object
85 86 87 88 |
# File 'scan/lib/scan/test_command_generator.rb', line 85 def suffix suffix = [] suffix end |
#xcodebuild_log_path ⇒ Object
Store the raw file
133 134 135 136 137 138 139 |
# File 'scan/lib/scan/test_command_generator.rb', line 133 def xcodebuild_log_path file_name = "#{Scan.config[:app_name] || Scan.project.app_name}-#{Scan.config[:scheme]}.log" containing = File.(Scan.config[:buildlog_path]) FileUtils.mkdir_p(containing) return File.join(containing, file_name) end |