Files
purchases-ios/Sources/FoundationExtensions/ProcessInfo+Extensions.swift
T
NachoSoto 9bbd5b1ee7 Tests: ensure Purchases is not configured multiple times (#2100)
Continuing to look into [CSDK-517], I found this several times in the
logs:
> Purchases instance already set. Did you mean to configure two
Purchases objects?

In order to ensure that tests don't leave around unwanted state, I've
turned this error into an assertion _only when running tests_, as well
as fixed those cases.

[CSDK-517]:
https://revenuecats.atlassian.net/browse/CSDK-517?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
2022-12-08 16:59:51 -08:00

53 lines
1.2 KiB
Swift

//
// Copyright RevenueCat Inc. All Rights Reserved.
//
// Licensed under the MIT License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/MIT
//
// ProcessInfo+Extensions.swift
//
// Created by Nacho Soto on 11/29/22.
import Foundation
enum EnvironmentKey: String {
case XCTestConfigurationFile = "XCTestConfigurationFilePath"
case RCRunningTests = "RCRunningTests"
case RCRunningIntegrationTests = "RCRunningIntegrationTests"
}
extension ProcessInfo {
static subscript(key: EnvironmentKey) -> String? {
return Self.processInfo.environment[key.rawValue]
}
}
#if DEBUG
extension ProcessInfo {
static var isRunningUnitTests: Bool {
return self[.XCTestConfigurationFile] != nil
}
/// `true` when running unit or integration tests (configured in .xctestplan files).
static var isRunningRevenueCatTests: Bool {
return self[.RCRunningTests] == "1"
}
/// `true` when running integration tests (configured in .xctestplan files).
static var isRunningIntegrationTests: Bool {
return self[.RCRunningIntegrationTests] == "1"
}
}
#endif