How to use hash method of CodableTargetDependency class

Best Mockingbird code snippet using CodableTargetDependency.hash

Run Mockingbird automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

CodableTarget.swift

Source: CodableTarget.swift Github

copy
1//
2//  CodableTarget.swift
3//  MockingbirdGenerator
4//
5//  Created by Andrew Chang on 9/29/19.
6//
7
8import Foundation
9import PathKit
10import XcodeProj
11
12public struct SourceFile: Codable, Hashable {
13  public let path: Path
14  public let hash: String?
15}
16
17/// A sparse representation of dependencies is used since caching only relies on the unique set of
18/// dependency sources for a single module being mocked.
19public class CodableTargetDependency: TargetDependency, Codable {
20  public let target: CodableTarget?
21  
22  init?<D: TargetDependency>(from dependency: D,
23                             sourceRoot: Path,
24                             ignoredDependencies: inout Set<String>,
25                             environment: () -> [String: Any]) throws {
26    guard let target = dependency.target else { return nil }
27    self.target = try CodableTarget(from: target,
28                                    sourceRoot: sourceRoot,
29                                    ignoredDependencies: &ignoredDependencies,
30                                    environment: environment)
31  }
32  
33  init(target: CodableTarget) {
34    self.target = target
35  }
36  
37  public static func == (lhs: CodableTargetDependency, rhs: CodableTargetDependency) -> Bool {
38    return lhs.target == rhs.target
39  }
40  
41  public func hash(into hasher: inout Hasher) {
42    hasher.combine(target)
43  }
44}
45
46public class CodableTarget: Target, Codable {
47  public let name: String
48  public let productModuleName: String
49  public let dependencies: [CodableTargetDependency]
50  
51  public let sourceRoot: Path
52  public let sourceFilePaths: [SourceFile]
53  
54  public init<T: Target>(from target: T,
55                         sourceRoot: Path,
56                         dependencies: [CodableTargetDependency]? = nil,
57                         ignoredDependencies: inout Set<String>,
58                         environment: () -> [String: Any]) throws {
59    self.name = target.name
60    self.productModuleName = target.resolveProductModuleName(environment: environment)
61    if let dependencies = dependencies {
62      self.dependencies = dependencies
63    } else {
64      self.dependencies = try target.dependencies
65        .filter({
66          !ignoredDependencies.contains(
67            $0.target?.resolveProductModuleName(environment: environment) ?? ""
68          )
69        })
70        .compactMap({
71          try CodableTargetDependency(from: $0,
72                                      sourceRoot: sourceRoot,
73                                      ignoredDependencies: &ignoredDependencies,
74                                      environment: environment)
75        })
76    }
77    ignoredDependencies.formUnion(self.dependencies.map({ $0.target?.productModuleName ?? "" }))
78    self.sourceFilePaths = try target.findSourceFilePaths(sourceRoot: sourceRoot)
79      .map({ $0.absolute() })
80      .sorted()
81      .map({
82        let data = (try? $0.read()) ?? Data()
83        return try SourceFile(path: $0, hash: data.generateSha1Hash())
84      })
85    self.sourceRoot = sourceRoot.absolute()
86  }
87  
88  init(name: String,
89       productModuleName: String,
90       dependencies: [CodableTargetDependency],
91       sourceRoot: Path,
92       sourceFilePaths: [SourceFile]) {
93    self.name = name
94    self.productModuleName = productModuleName
95    self.dependencies = dependencies
96    self.sourceRoot = sourceRoot
97    self.sourceFilePaths = sourceFilePaths
98  }
99  
100  public func resolveProductModuleName(environment: () -> [String : Any]) -> String {
101    return productModuleName
102  }
103  
104  public func findSourceFilePaths(sourceRoot: Path) -> [Path] {
105    guard sourceRoot.absolute() == self.sourceRoot.absolute() else {
106      // Should not happen unless the `.xcodeproj` is moved relative to `SRCROOT`.
107      logWarning("Cached source root does not match the input source root")
108      return []
109    }
110    return sourceFilePaths.map({ $0.path })
111  }
112  
113  public static func == (lhs: CodableTarget, rhs: CodableTarget) -> Bool {
114    return lhs.productModuleName == rhs.productModuleName
115  }
116  
117  public func hash(into hasher: inout Hasher) {
118    hasher.combine(productModuleName)
119  }
120}
121
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Most used method in CodableTargetDependency

Trigger hash code on LambdaTest Cloud Grid

Execute automation tests with hash on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)