Skip to content

Commit

Permalink
Add ability to override 'timeout' via --user-options (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiikhliustin authored Feb 29, 2024
1 parent e5bb686 commit c16fd2f
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ OPTIONS:
For test specs:
'SomePod/UnitTests.runner := //:SomeTestsRunner'
'SomePod/UnitTests.test_host := //:SomeTestHostApp'
'SomePod/UnitTests.timeout := eternal'
--deps-prefix <deps-prefix>
Dependencies prefix (default: //Pods)
--pods-root <pods-root> Pods root relative to workspace. Used for headers search paths (default: Pods)
Expand Down Expand Up @@ -148,6 +149,7 @@ OPTIONS:
For test specs:
'SomePod/UnitTests.runner := //:SomeTestsRunner'
'SomePod/UnitTests.test_host := //:SomeTestHostApp'
'SomePod/UnitTests.timeout := eternal'
--deps-prefix <deps-prefix>
Dependencies prefix (default: //Pods)
--pods-root <pods-root> Pods root relative to workspace. Used for headers search paths (default: Pods)
Expand Down
1 change: 1 addition & 0 deletions Sources/BazelPods/BazelPods.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ Platform specific:
For test specs:
'SomePod/UnitTests.runner := //:SomeTestsRunner'
'SomePod/UnitTests.test_host := //:SomeTestHostApp'
'SomePod/UnitTests.timeout := eternal'
"""
)
var userOptions: [String] = []
Expand Down
4 changes: 3 additions & 1 deletion Sources/BazelPodsCore/Analyzer/TestSpec/RunnerAnalyzer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ struct RunnerAnalyzer<S: SchemeRepresentable> {
struct Result {
var runnerName: String?
var testHost: String?
var timeout: TestsTimeout?
}

private let spec: S
Expand All @@ -29,7 +30,8 @@ struct RunnerAnalyzer<S: SchemeRepresentable> {
private func run() -> Result {
return Result(
runnerName: nil,
testHost: nil
testHost: nil,
timeout: nil
)
}
}
4 changes: 2 additions & 2 deletions Sources/BazelPodsCore/Build/PodBuildFile+makeTestspecs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ extension PodBuildFile {
sources: analyzer.sourcesInfo,
resources: analyzer.resourcesInfo,
deps: deps,
timeout: options.testsTimeout?.rawValue ?? "",
timeout: analyzer.runnerInfo.timeout?.rawValue ?? options.testsTimeout?.rawValue ?? "",
testHost: testHost,
infoPlist: infoPlist.name,
environment: analyzer.environmentInfo.environmentVariables,
Expand All @@ -88,7 +88,7 @@ extension PodBuildFile {
sources: analyzer.sourcesInfo,
resources: analyzer.resourcesInfo,
deps: deps,
timeout: options.testsTimeout?.rawValue ?? "",
timeout: analyzer.runnerInfo.timeout?.rawValue ?? options.testsTimeout?.rawValue ?? "",
testHost: testHost,
infoPlist: infoPlist.name,
environment: analyzer.environmentInfo.environmentVariables,
Expand Down
18 changes: 18 additions & 0 deletions Sources/BazelPodsCore/Core/UserOption.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public struct UserOption {
case link_dynamic(Bool)
case runner(String)
case test_host(String)
case timeout(TestsTimeout)
}
public enum KeyPath: String, CaseIterable {
case sdk_frameworks
Expand All @@ -67,6 +68,7 @@ public struct UserOption {
case link_dynamic
case runner
case test_host
case timeout
}

public init?(_ string: String) {
Expand Down Expand Up @@ -195,6 +197,22 @@ public struct UserOption {
return nil
}
attribute = .test_host(last)
case .timeout:
guard opt == .replace else {
log_error("Incorrect option for \(string). '\(keyPath)' supports only \(Opt.replace.rawValue) operator. Skipping...")
return nil
}
guard
value.count == 1,
let last = value.last?.trim,
let timeout = TestsTimeout(rawValue: last)
else {
log_error(
"Incorrect value for \(string). Should be one of \(TestsTimeout.allCases.map({ $0.rawValue }).joined(separator: ", "))). Skipping..."
)
return nil
}
attribute = .timeout(timeout)
}
self.name = name
self.opt = opt
Expand Down
5 changes: 5 additions & 0 deletions Sources/BazelPodsCore/Patches/UserOptionsPatch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ struct UserOptionsPatch: Patch, TestSpecSpecificPatch {
case .test_host:
// test spec specific option
break
case .timeout:
// test spec specific option
break
}
}
}
Expand Down Expand Up @@ -117,6 +120,8 @@ struct UserOptionsPatch: Patch, TestSpecSpecificPatch {
runnerInfo.runnerName = string
case .test_host(let string):
runnerInfo.testHost = string
case .timeout(let timeout):
runnerInfo.timeout = timeout
default:
break
}
Expand Down

0 comments on commit c16fd2f

Please sign in to comment.