homebrew-core/Formula/mockolo.rb

75 lines
2.8 KiB
Ruby

class Mockolo < Formula
desc "Efficient Mock Generator for Swift"
homepage "https://github.com/uber/mockolo"
url "https://github.com/uber/mockolo/archive/1.8.0.tar.gz"
sha256 "9d289eede8080bcf3f0fbd2ec4f6a0616a78743c09cd58575e48e6e4b946f357"
license "Apache-2.0"
bottle do
sha256 cellar: :any, arm64_ventura: "d15b1e0d9c4101d06bebcd24e12727cb8243cd76fa51cf2ccc539560876483b7"
sha256 cellar: :any, arm64_monterey: "0f4677a443def0c1db5736b49186f1e752ee8a4dcf3f01f471a1bd54f543c2dc"
sha256 cellar: :any_skip_relocation, arm64_big_sur: "ab052d6c093c64bbc22d54ef082487560b42ba812d28e4ecfca174da009a47bf"
sha256 cellar: :any, ventura: "60fb1bd8615d03b3b02e38b59341d2a792ac328f85c6b044c624772747ab38d5"
sha256 cellar: :any, monterey: "2de4ba04ddf7154f718147c4e198194a7e7eeb37312f26bb481deab5c9099995"
sha256 cellar: :any_skip_relocation, big_sur: "e042c9a875089f7a2fb8df3374ad94a3edd22ff4d24a51198fef77a20c85bb78"
end
depends_on xcode: ["12.5", :build]
depends_on :macos # depends on os.signpost, which is macOS-only.
def install
# Swift >= 5.6
if MacOS::Xcode.version >= "13.3"
require_internal_swift_syntax_parser = true
swift_rpath = ["-Xlinker", "-rpath", "-Xlinker", libexec]
end
system "swift", "build", "-c", "release", "--disable-sandbox", *swift_rpath
bin.install ".build/release/mockolo"
if require_internal_swift_syntax_parser
libexec.install ".build/release/lib_InternalSwiftSyntaxParser.dylib"
# lib_InternalSwiftSyntaxParser is taken from Xcode, so it's a universal binary.
deuniversalize_machos(libexec/"lib_InternalSwiftSyntaxParser.dylib")
end
end
test do
(testpath/"testfile.swift").write <<~EOS
/// @mockable
public protocol Foo {
var num: Int { get set }
func bar(arg: Float) -> String
}
EOS
system "#{bin}/mockolo", "-srcs", testpath/"testfile.swift", "-d", testpath/"GeneratedMocks.swift"
assert_predicate testpath/"GeneratedMocks.swift", :exist?
output = <<~EOS.gsub(/\s+/, "").strip
///
/// @Generated by Mockolo
///
public class FooMock: Foo {
public init() { }
public init(num: Int = 0) {
self.num = num
}
public private(set) var numSetCallCount = 0
public var num: Int = 0 { didSet { numSetCallCount += 1 } }
public private(set) var barCallCount = 0
public var barHandler: ((Float) -> (String))?
public func bar(arg: Float) -> String {
barCallCount += 1
if let barHandler = barHandler {
return barHandler(arg)
}
return ""
}
}
EOS
assert_equal output, shell_output("cat #{testpath/"GeneratedMocks.swift"}").gsub(/\s+/, "").strip
end
end