Skip to content

Commit

Permalink
Merge pull request #68 from bartoszj/derivedData
Browse files Browse the repository at this point in the history
Added support for `-derivedDataPath` and `-resultBundlePath` options.
  • Loading branch information
KrauseFx committed Jan 15, 2016
2 parents 189e2de + fb81229 commit eae6bfb
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/scan/options.rb
Expand Up @@ -73,6 +73,17 @@ def self.available_options
env_name: "SCAN_BUILDLOG_PATH",
description: "The directory were to store the raw log",
default_value: "~/Library/Logs/scan"),
FastlaneCore::ConfigItem.new(key: :derived_data_path,
short_option: "-j",
env_name: "SCAN_DERIVED_DATA_PATH",
description: "The directory where build products and other derived data will go",
optional: true),
FastlaneCore::ConfigItem.new(key: :result_bundle,
short_option: "-z",
env_name: "SCAN_RESULT_BUNDLE",
is_string: false,
description: "Produce the result bundle describing what occurred will be placed",
optional: true),
FastlaneCore::ConfigItem.new(key: :sdk,
short_option: "-k",
env_name: "SCAN_SDK",
Expand Down
9 changes: 9 additions & 0 deletions lib/scan/test_command_generator.rb
Expand Up @@ -34,6 +34,8 @@ def options
options << "-configuration '#{config[:configuration]}'" if config[:configuration]
options << "-sdk '#{config[:sdk]}'" if config[:sdk]
options << "-destination '#{config[:destination]}'" # generated in `detect_values`
options << "-derivedDataPath '#{config[:derived_data_path]}'" if config[:derived_data_path]
options << "-resultBundlePath '#{result_bundle_path}'" if config[:result_bundle]
options << "-enableCodeCoverage YES" if config[:code_coverage]
options << "-xcconfig '#{config[:xcconfig]}'" if config[:xcconfig]
options << config[:xcargs] if config[:xcargs]
Expand Down Expand Up @@ -100,6 +102,13 @@ def build_path
end
Scan.cache[:build_path]
end

def result_bundle_path
unless Scan.cache[:result_bundle_path]
Scan.cache[:result_bundle_path] = File.join(Scan.config[:output_directory], Scan.config[:scheme]) + ".test_result"
end
return Scan.cache[:result_bundle_path]
end
end
end
end
123 changes: 123 additions & 0 deletions spec/test_command_generator_spec.rb
@@ -0,0 +1,123 @@
describe Scan do
describe Scan::TestCommandGenerator do
it "raises an exception when project path wasn't found" do
expect do
options = { project: "/notExistent" }
Scan.config = FastlaneCore::Configuration.create(Scan::Options.available_options, options)
end.to raise_error "Project file not found at path '/notExistent'".red
end

it "supports additional parameters" do
log_path = File.expand_path("~/Library/Logs/scan/app-app.log")

xcargs_hash = { DEBUG: "1", BUNDLE_NAME: "Example App" }
xcargs = xcargs_hash.map do |k, v|
"#{k.to_s.shellescape}=#{v.shellescape}"
end.join ' '
options = { project: "./examples/standard/app.xcodeproj", sdk: "9.0", xcargs: xcargs }
Scan.config = FastlaneCore::Configuration.create(Scan::Options.available_options, options)

result = Scan::TestCommandGenerator.generate
expect(result).to start_with([
"set -o pipefail &&",
"env NSUnbufferedIO=YES xcodebuild",
"-scheme 'app'",
"-project './examples/standard/app.xcodeproj'",
"-sdk '9.0'",
"-destination '#{Scan.config[:destination]}'",
"DEBUG=1 BUNDLE_NAME=Example\\ App",
:build,
:test
])
end

describe "Standard Example" do
before do
options = { project: "./examples/standard/app.xcodeproj" }
Scan.config = FastlaneCore::Configuration.create(Scan::Options.available_options, options)
end

it "uses the correct build command with the example project with no additional parameters" do
log_path = File.expand_path("~/Library/Logs/scan/app-app.log")

result = Scan::TestCommandGenerator.generate
expect(result).to start_with([
"set -o pipefail &&",
"env NSUnbufferedIO=YES xcodebuild",
"-scheme 'app'",
"-project './examples/standard/app.xcodeproj'",
"-destination '#{Scan.config[:destination]}'",
:build,
:test
])
end

it "#project_path_array" do
result = Scan::TestCommandGenerator.project_path_array
expect(result).to eq(["-scheme 'app'", "-project './examples/standard/app.xcodeproj'"])
end

it "#build_path" do
result = Scan::TestCommandGenerator.build_path
regex = %r{Library/Developer/Xcode/Archives/\d\d\d\d\-\d\d\-\d\d}
expect(result).to match(regex)
end

it "#buildlog_path is used when provided" do
options = { project: "./examples/standard/app.xcodeproj", buildlog_path: "/tmp/my/path" }
Scan.config = FastlaneCore::Configuration.create(Scan::Options.available_options, options)
result = Scan::TestCommandGenerator.xcodebuild_log_path
expect(result).to include("/tmp/my/path")
end

it "#buildlog_path is not used when not provided" do
result = Scan::TestCommandGenerator.xcodebuild_log_path
expect(result.to_s).to include("Library/Logs/scan")
end
end

describe "Derived Data Example" do
before do
options = { project: "./examples/standard/app.xcodeproj", derived_data_path: "/tmp/my/derived_data" }
Scan.config = FastlaneCore::Configuration.create(Scan::Options.available_options, options)
end

it "uses the correct build command with the example project" do
log_path = File.expand_path("~/Library/Logs/scan/app-app.log")

result = Scan::TestCommandGenerator.generate
expect(result).to start_with([
"set -o pipefail &&",
"env NSUnbufferedIO=YES xcodebuild",
"-scheme 'app'",
"-project './examples/standard/app.xcodeproj'",
"-destination '#{Scan.config[:destination]}'",
"-derivedDataPath '/tmp/my/derived_data'",
:build,
:test
])
end
end

describe "Result Bundle Example" do
it "uses the correct build command with the example project" do
log_path = File.expand_path("~/Library/Logs/scan/app-app.log")

options = { project: "./examples/standard/app.xcodeproj", result_bundle: true }
Scan.config = FastlaneCore::Configuration.create(Scan::Options.available_options, options)

result = Scan::TestCommandGenerator.generate
expect(result).to start_with([
"set -o pipefail &&",
"env NSUnbufferedIO=YES xcodebuild",
"-scheme 'app'",
"-project './examples/standard/app.xcodeproj'",
"-destination '#{Scan.config[:destination]}'",
"-resultBundlePath './fastlane/test_output/app.test_result'",
:build,
:test
])
end
end
end
end

0 comments on commit eae6bfb

Please sign in to comment.