Skip to content

Commit

Permalink
Refactor Simulator Localization Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladislav Alekseev committed Dec 30, 2019
1 parent 607c3e9 commit c1a5eb4
Show file tree
Hide file tree
Showing 16 changed files with 125 additions and 31 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.


## 2019-12-30

- Simulator settings now provided as JSON inside test arg file instead of URLs to JSON inside ZIP archive. See `SimulatorSetttings`, `SimulatorLocalizationSettings` and `WatchdogSettings` for format description.

## 2019-12-25

- `auxiliaryResources` key has been removed from queue server run configuration JSON file because only plugin URLs are required in order to start up the queue.
Expand Down
1 change: 1 addition & 0 deletions Sources/EmceeLib/Commands/DumpRuntimeTestsCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public final class DumpRuntimeTestsCommand: Command {
let configuration = RuntimeDumpConfiguration(
developerDir: testArgFileEntry.toolchainConfiguration.developerDir,
runtimeDumpMode: try RuntimeDumpModeDeterminer.runtimeDumpMode(testArgFileEntry: testArgFileEntry),
simulatorSettings: testArgFileEntry.simulatorSettings,
testDestination: testArgFileEntry.testDestination,
testExecutionBehavior: TestExecutionBehavior(
environment: testArgFileEntry.environment,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public final class TestEntriesValidator {
runtimeDumpMode: try RuntimeDumpModeDeterminer.runtimeDumpMode(
testArgFileEntry: testArgFileEntry
),
simulatorSettings: testArgFileEntry.simulatorSettings,
testDestination: testArgFileEntry.testDestination,
testExecutionBehavior: TestExecutionBehavior(
environment: testArgFileEntry.environment,
Expand Down
5 changes: 0 additions & 5 deletions Sources/Models/ResourceAliases.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ public typealias FbsimctlLocation = TypedResourceLocation<FbsimctlResourceLocati
public typealias FbxctestLocation = TypedResourceLocation<FbxctestResourceLocationType>
public typealias PluginLocation = TypedResourceLocation<PluginResourceLocationType>
public typealias RunnerAppLocation = TypedResourceLocation<RunnerAppResourceLocationType>
public typealias SimulatorLocalizationLocation = TypedResourceLocation<SimulatorLocalizationResourceLocationType>
public typealias TestBundleLocation = TypedResourceLocation<TestBundleResourceLocationType>
public typealias QueueServerRunConfigurationLocation = TypedResourceLocation<QueueServerRunConfigurationLocationType>
public typealias AnalyticsConfigurationLocation = TypedResourceLocation<AnalyticsConfigurationLocationType>
Expand Down Expand Up @@ -40,10 +39,6 @@ public final class RunnerAppResourceLocationType: ResourceLocationType {
public static let name = "xct runner app"
}

public final class SimulatorLocalizationResourceLocationType: ResourceLocationType {
public static let name = "simulator localization settings"
}

public final class TestBundleResourceLocationType: ResourceLocationType {
public static let name = "xctest bundle"
}
Expand Down
3 changes: 3 additions & 0 deletions Sources/Models/RuntimeDumpConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Foundation
public struct RuntimeDumpConfiguration {
public let developerDir: DeveloperDir
public let runtimeDumpMode: RuntimeDumpMode
public let simulatorSettings: SimulatorSettings
public let testDestination: TestDestination
public let testExecutionBehavior: TestExecutionBehavior
public let testRunnerTool: TestRunnerTool
Expand All @@ -13,6 +14,7 @@ public struct RuntimeDumpConfiguration {
public init(
developerDir: DeveloperDir,
runtimeDumpMode: RuntimeDumpMode,
simulatorSettings: SimulatorSettings,
testDestination: TestDestination,
testExecutionBehavior: TestExecutionBehavior,
testRunnerTool: TestRunnerTool,
Expand All @@ -22,6 +24,7 @@ public struct RuntimeDumpConfiguration {
) {
self.developerDir = developerDir
self.runtimeDumpMode = runtimeDumpMode
self.simulatorSettings = simulatorSettings
self.testDestination = testDestination
self.testExecutionBehavior = testExecutionBehavior
self.testRunnerTool = testRunnerTool
Expand Down
33 changes: 33 additions & 0 deletions Sources/Models/SimulatorLocalizationSettings.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import Foundation

public struct SimulatorLocalizationSettings: Codable, CustomStringConvertible, Hashable {
public let localeIdentifier: String
public let keyboards: [String]
public let passcodeKeyboards: [String]
public let languages: [String]
public let addingEmojiKeybordHandled: Bool
public let enableKeyboardExpansion: Bool
public let didShowInternationalInfoAlert: Bool

public init(
localeIdentifier: String,
keyboards: [String],
passcodeKeyboards: [String],
languages: [String],
addingEmojiKeybordHandled: Bool,
enableKeyboardExpansion: Bool,
didShowInternationalInfoAlert: Bool
) {
self.localeIdentifier = localeIdentifier
self.keyboards = keyboards
self.passcodeKeyboards = passcodeKeyboards
self.languages = languages
self.addingEmojiKeybordHandled = addingEmojiKeybordHandled
self.enableKeyboardExpansion = enableKeyboardExpansion
self.didShowInternationalInfoAlert = didShowInternationalInfoAlert
}

public var description: String {
return "<\(type(of: self)) \(localeIdentifier), keyboards: \(keyboards), passcodeKeyboards: \(passcodeKeyboards), languages: \(languages), addingEmojiKeybordHandled \(addingEmojiKeybordHandled), enableKeyboardExpansion \(enableKeyboardExpansion), didShowInternationalInfoAlert \(didShowInternationalInfoAlert)>"
}
}
7 changes: 3 additions & 4 deletions Sources/Models/SimulatorSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@ import Foundation
public struct SimulatorSettings: Codable, Hashable, CustomStringConvertible {
/// Location of JSON file with localization settings for Simulator.
/// These settings will be applied after simulator has been created and before it will be booted.
public let simulatorLocalizationSettings: SimulatorLocalizationLocation?
public let simulatorLocalizationSettings: SimulatorLocalizationSettings
public let watchdogSettings: WatchdogSettings

public init(
simulatorLocalizationSettings: SimulatorLocalizationLocation?,
simulatorLocalizationSettings: SimulatorLocalizationSettings,
watchdogSettings: WatchdogSettings
) {
self.simulatorLocalizationSettings = simulatorLocalizationSettings
self.watchdogSettings = watchdogSettings
}

public var description: String {
let localization = String(describing: simulatorLocalizationSettings)
return "<\((type(of: self))): localization: \(localization), watchdogSettings: \(watchdogSettings)>"
return "<\((type(of: self))): simulatorLocalizationSettings: \(simulatorLocalizationSettings), watchdogSettings: \(watchdogSettings)>"
}
}
8 changes: 2 additions & 6 deletions Sources/RuntimeDump/RuntimeTestQuerierImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,6 @@ public final class RuntimeTestQuerierImpl: RuntimeTestQuerier {
dumpConfiguration: RuntimeDumpConfiguration,
runtimeEntriesJSONPath: AbsolutePath
) -> RunnerConfiguration {
let simulatorSettings = SimulatorSettings(
simulatorLocalizationSettings: nil,
watchdogSettings: WatchdogSettings(bundleIds: [], timeout: 0)
)
let environment = self.environment(configuration: dumpConfiguration, runtimeEntriesJSONPath: runtimeEntriesJSONPath)

switch dumpConfiguration.runtimeDumpMode {
Expand All @@ -134,7 +130,7 @@ public final class RuntimeTestQuerierImpl: RuntimeTestQuerier {
)
),
environment: environment,
simulatorSettings: simulatorSettings,
simulatorSettings: dumpConfiguration.simulatorSettings,
testRunnerTool: dumpConfiguration.testRunnerTool,
testTimeoutConfiguration: dumpConfiguration.testTimeoutConfiguration,
testType: .logicTest
Expand All @@ -151,7 +147,7 @@ public final class RuntimeTestQuerierImpl: RuntimeTestQuerier {
additionalApplicationBundles: []
),
environment: environment,
simulatorSettings: simulatorSettings,
simulatorSettings: dumpConfiguration.simulatorSettings,
testRunnerTool: dumpConfiguration.testRunnerTool,
testTimeoutConfiguration: dumpConfiguration.testTimeoutConfiguration,
testType: .appTest
Expand Down
26 changes: 16 additions & 10 deletions Sources/fbxctest/FbxctestBasedTestRunner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import TemporaryStuff
public final class FbxctestBasedTestRunner: TestRunner {
private let fbxctestLocation: FbxctestLocation
private let resourceLocationResolver: ResourceLocationResolver
private let encoder = JSONEncoder()

public init(
fbxctestLocation: FbxctestLocation,
Expand Down Expand Up @@ -141,22 +142,27 @@ public final class FbxctestBasedTestRunner: TestRunner {
] + resolvableAdditionalAppBundles).map { $0.asArgument() }
arguments += [JoinedSubprocessArgument(components: components, separator: ":")]

if let simulatorLocatizationSettings = simulatorSettings.simulatorLocalizationSettings {
arguments += [
"-simulator-localization-settings",
resourceLocationResolver.resolvable(withRepresentable: simulatorLocatizationSettings).asArgument()
]
}
let simulatorLocalizationFile = FbxctestSimulatorLocalizationFile(
localeIdentifier: simulatorSettings.simulatorLocalizationSettings.localeIdentifier,
keyboards: simulatorSettings.simulatorLocalizationSettings.keyboards,
passcodeKeyboards: simulatorSettings.simulatorLocalizationSettings.passcodeKeyboards,
languages: simulatorSettings.simulatorLocalizationSettings.languages,
addingEmojiKeybordHandled: simulatorSettings.simulatorLocalizationSettings.addingEmojiKeybordHandled,
enableKeyboardExpansion: simulatorSettings.simulatorLocalizationSettings.enableKeyboardExpansion,
didShowInternationalInfoAlert: simulatorSettings.simulatorLocalizationSettings.didShowInternationalInfoAlert
)
let simulatorLocalizationFilePath = fbxctestWorkingDirectory.appending(component: "simulator_localization_settings.json")
try encoder.encode(simulatorLocalizationFile).write(to: simulatorLocalizationFilePath.fileUrl)
arguments += [
"-simulator-localization-settings", simulatorLocalizationFilePath
]

let watchdogFile = FbxctestWatchdogFile(
bundleIds: simulatorSettings.watchdogSettings.bundleIds,
timeout: simulatorSettings.watchdogSettings.timeout
)

let encoder = JSONEncoder()
let watchdogFileContents = try encoder.encode(watchdogFile)
let watchdogFilePath = fbxctestWorkingDirectory.appending(component: "watchdog_settings.json")
try watchdogFileContents.write(to: watchdogFilePath.fileUrl)
try encoder.encode(watchdogFile).write(to: watchdogFilePath.fileUrl)
arguments += [
"-watchdog-settings", watchdogFilePath
]
Expand Down
21 changes: 21 additions & 0 deletions Sources/fbxctest/FbxctestSimulatorLocalizationFile.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Foundation

struct FbxctestSimulatorLocalizationFile: Encodable {
let localeIdentifier: String
let keyboards: [String]
let passcodeKeyboards: [String]
let languages: [String]
let addingEmojiKeybordHandled: Bool
let enableKeyboardExpansion: Bool
let didShowInternationalInfoAlert: Bool

enum CodingKeys: String, CodingKey {
case localeIdentifier = "locale_identifier"
case keyboards = "keyboards"
case passcodeKeyboards = "passcode_keyboards"
case languages = "languages"
case addingEmojiKeybordHandled = "adding_emoji_keybord_handled"
case enableKeyboardExpansion = "enable_keyboard_expansion"
case didShowInternationalInfoAlert = "did_show_international_info_alert"
}
}
26 changes: 26 additions & 0 deletions Tests/ModelsTestHelpers/SimulatorLocalizationSettings.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Foundation
import Models

public final class SimulatorLocalizationSettingsFixture {
public var localeIdentifier = "ru_US"
public var keyboards = ["ru_RU@sw=Russian;hw=Automatic", "en_US@sw=QWERTY;hw=Automatic"]
public var passcodeKeyboards = ["ru_RU@sw=Russian;hw=Automatic", "en_US@sw=QWERTY;hw=Automatic"]
public var languages = ["ru-US", "en", "ru-RU"]
public var addingEmojiKeybordHandled = true
public var enableKeyboardExpansion = true
public var didShowInternationalInfoAlert = true

public init() {}

public func simulatorLocalizationSettings() -> SimulatorLocalizationSettings {
return SimulatorLocalizationSettings(
localeIdentifier: localeIdentifier,
keyboards: keyboards,
passcodeKeyboards: passcodeKeyboards,
languages: languages,
addingEmojiKeybordHandled: addingEmojiKeybordHandled,
enableKeyboardExpansion: enableKeyboardExpansion,
didShowInternationalInfoAlert: didShowInternationalInfoAlert
)
}
}
4 changes: 2 additions & 2 deletions Tests/ModelsTestHelpers/SimulatorSettingsFixtures.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import Foundation
import Models

public final class SimulatorSettingsFixtures {
var simulatorLocalizationSettings: SimulatorLocalizationLocation?
var simulatorLocalizationSettings: SimulatorLocalizationSettings = SimulatorLocalizationSettingsFixture().simulatorLocalizationSettings()
var watchdogSettings: WatchdogSettings = WatchdogSettings(bundleIds: [], timeout: 0)

public init() {}

public func with(simulatorLocalizationSettings: SimulatorLocalizationLocation?) -> SimulatorSettingsFixtures {
public func with(simulatorLocalizationSettings: SimulatorLocalizationSettings) -> SimulatorSettingsFixtures {
self.simulatorLocalizationSettings = simulatorLocalizationSettings
return self
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Models
public final class TestEntryConfigurationFixtures {
public var buildArtifacts = BuildArtifactsFixtures.fakeEmptyBuildArtifacts()
public var simulatorSettings = SimulatorSettings(
simulatorLocalizationSettings: nil,
simulatorLocalizationSettings: SimulatorLocalizationSettingsFixture().simulatorLocalizationSettings(),
watchdogSettings: WatchdogSettings(bundleIds: [], timeout: 0)
)
public var testDestination = TestDestinationFixtures.testDestination
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ final class GroupedTestEntryConfigurationsTests: XCTestCase {
let testEntryConfigurations2 = TestEntryConfigurationFixtures()
.add(testEntry: TestEntryFixtures.testEntry(className: "class", methodName: "test3"))
.with(simulatorSettings: SimulatorSettingsFixtures()
.with(simulatorLocalizationSettings: Optional(SimulatorLocalizationLocation(.localFilePath("/l10n"))))
.with(watchdogSettings: WatchdogSettings(bundleIds: ["a.p.p"], timeout: 123))
.simulatorSettings())
.testEntryConfigurations()
let mixedTestEntryConfigurations = [
Expand Down
12 changes: 10 additions & 2 deletions Tests/ModelsTests/TestArgFileTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,15 @@ final class TestArgFileTests: XCTestCase {
"toolchainConfiguration": {"developerDir": {"kind": "current"}},
"scheduleStrategy": "unsplit",
"simulatorSettings": {
"simulatorLocalizationSettings": "/l10n",
"simulatorLocalizationSettings": {
"localeIdentifier": "ru_US",
"keyboards": ["ru_RU@sw=Russian;hw=Automatic", "en_US@sw=QWERTY;hw=Automatic"],
"passcodeKeyboards": ["ru_RU@sw=Russian;hw=Automatic", "en_US@sw=QWERTY;hw=Automatic"],
"languages": ["ru-US", "en", "ru-RU"],
"addingEmojiKeybordHandled": true,
"enableKeyboardExpansion": true,
"didShowInternationalInfoAlert": true
},
"watchdogSettings": {
"bundleIds": ["sample.app"],
"timeout": 42
Expand All @@ -57,7 +65,7 @@ final class TestArgFileTests: XCTestCase {
numberOfRetries: 42,
scheduleStrategy: .unsplit,
simulatorSettings: SimulatorSettings(
simulatorLocalizationSettings: SimulatorLocalizationLocation(.localFilePath("/l10n")),
simulatorLocalizationSettings: SimulatorLocalizationSettingsFixture().simulatorLocalizationSettings(),
watchdogSettings: WatchdogSettings(bundleIds: ["sample.app"], timeout: 42)
),
testDestination: try TestDestination(deviceType: "iPhone SE", runtime: "11.3"),
Expand Down
1 change: 1 addition & 0 deletions Tests/RuntimeDumpTests/RuntimeTestQuerierTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ final class RuntimeTestQuerierTests: XCTestCase {
return RuntimeDumpConfiguration(
developerDir: DeveloperDir.current,
runtimeDumpMode: .logicTest(applicationTestSupport?.simulatorControlTool ?? .simctl),
simulatorSettings: SimulatorSettingsFixtures().simulatorSettings(),
testDestination: TestDestinationFixtures.testDestination,
testExecutionBehavior: TestExecutionBehavior(environment: [:], numberOfRetries: 0),
testRunnerTool: TestRunnerToolFixtures.fakeFbxctestTool,
Expand Down

0 comments on commit c1a5eb4

Please sign in to comment.