This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'pathname' | |
| # Swift pacakge manager code coverage | |
| # | |
| # Usage: | |
| # ruby codecov.rb $(swift test --show-codecov-path) | |
| class Codecov | |
| def initialize(path) | |
| # /Users/<user-name>/<package-name>/.build/x86_64-apple-macosx/debug/codecov/<package-name>.json | |
| @path = Pathname.new(path) |
| Type | Launched by | Launchable from | Lifetime | Cancellation | Inherits from origin |
|---|---|---|---|---|---|
| async-let tasks | async let |
async functions | scoped by statement | automatic | prioprity, task-local values |
| Group tasks | group.async |
withTaskGroup | scoped by task group | automatic | prioprity, task-local values |
| Unstructured tasks | Task.init |
anywhere | unscoped | Task.cancel() |
prioprity, task-local values, actor |
| Detached tasks | Task.detached |
anywhere | unscoped | Task.cancel() |
nothing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json | |
| import subprocess | |
| from pathlib import Path | |
| def shell(cmd, stdout=None) -> str: | |
| return subprocess.run(cmd.split(' '), stdout=stdout, check=True, text=True).stdout | |
| def get_package() -> dict: | |
| return json.loads(shell('swift package describe --type json', stdout=subprocess.PIPE)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct ServerRoute { | |
| typealias Handler = (_ request: Request, _ count: Int) -> Response? | |
| enum Method: String { | |
| case GET, POST | |
| } | |
| let method: Method | |
| let pattern: String | |
| let handler: Handler |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @resultBuilder | |
| enum ArrayBuilder { | |
| @inlinable | |
| static func buildExpression<T>(_ expression: T) -> [T] { | |
| [expression] | |
| } | |
| @inlinable | |
| static func buildBlock<T>(_ components: [T]...) -> [T] { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| swift test --enable-code-coverage | |
| BINARY_PATH=".build/x86_64-apple-macosx/debug/CombineCoreDataPackageTests.xctest/Contents/MacOS/CombineCoreDataPackageTests" | |
| PROF_DATA_PATH=".build/x86_64-apple-macosx/debug/codecov/default.profdata" | |
| xcrun llvm-cov report \ | |
| $BINARY_PATH \ | |
| --format=text \ | |
| -instr-profile="$PROF_DATA_PATH" \ | |
| -ignore-filename-regex=Tests |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [1, 2].publisher // Publishers.Sequence<[Int], Never> | |
| Result<Int, Never>.success(1).publisher // Result<Int, Never>.Publisher | |
| Optinal.some(1).publisher // Error! But have Optional.Publisher | |
| // Missing extention | |
| extension Optional { | |
| public var publisher: Optional.Publisher { | |
| Optional.Publisher(self) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func == <T, U>( | |
| keyPath: KeyPath<T, U>, | |
| value: U | |
| ) -> (T) -> Bool where U: Equatable { | |
| return { $0[keyPath: keyPath] == value } | |
| } | |
| struct User { | |
| let name: String | |
| } |