-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathMiscTests.swift
69 lines (63 loc) · 2.68 KB
/
MiscTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
66
67
68
69
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2025 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
import Foundation
import Testing
import SWBTestSupport
import SWBUtil
@Suite fileprivate struct MiscTests {
@Test
func userCacheDir() throws {
switch try ProcessInfo.processInfo.hostOperatingSystem() {
case .windows:
#expect(SWBUtil.userCacheDir().str.hasSuffix("\\AppData\\Local\\Temp"))
case .macOS, .iOS, .tvOS, .watchOS, .visionOS:
#expect(SWBUtil.userCacheDir().str.hasPrefix("/var/folders"))
case .android:
#expect(SWBUtil.userCacheDir().str.hasPrefix("/data/local/tmp"))
case .linux, .freebsd, .openbsd, .unknown:
#expect(SWBUtil.userCacheDir().str.hasPrefix("/tmp"))
}
}
@Test
func parsingUmbrellaHeaderFromModuleMap() {
let contentWithUmbrellaHeader = """
framework module FrameworkName [extern_c] {
umbrella header "TheUmbrellaHeader.h"
export *
}
"""
#expect(parseUmbrellaHeaderName(contentWithUmbrellaHeader) == "TheUmbrellaHeader.h")
let contentWithoutUmbrellaHeader = """
framework module FrameworkName [extern_c] {
header "NonUmbrellaHeader.h"
export *
}
"""
#expect(parseUmbrellaHeaderName(contentWithoutUmbrellaHeader) == nil)
}
/// Tests that a linker-signed binary is not detected as code-signed by PbxCp.
@Test(.requireHostOS(.macOS))
func linkerSignedBinaryDetection() async throws {
try await withTemporaryDirectory { tmpDir -> Void in
struct Lookup: PlatformInfoLookup {
func lookupPlatformInfo(platform: BuildVersion.Platform) -> (any PlatformInfoProvider)? {
nil
}
}
let xcode = try await InstalledXcode.currentlySelected()
let path = try await xcode.compileFramework(path: tmpDir, platform: .iOS, infoLookup: Lookup(), archs: ["arm64"], useSwift: false)
#expect(!pbxcp_path_is_code_signed(path), "binary was unexpectedly code signed")
_ = try await runProcess(["/usr/bin/codesign", "-s", "-", path.str])
#expect(pbxcp_path_is_code_signed(path), "binary was unexpectedly NOT code signed")
}
}
}