Skip to content

Commit

Permalink
update settings and CI
Browse files Browse the repository at this point in the history
  • Loading branch information
JARMourato committed May 31, 2024
1 parent 8794174 commit 66b5a7a
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 23 deletions.
27 changes: 19 additions & 8 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,33 @@ jobs:
env:
PACKAGE_NAME: Injection

runs-on: macos-11
runs-on: macos-latest

steps:
- uses: actions/checkout@v2
- name: Check out code
uses: actions/checkout@v3

- name: Set up Xcode
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: latest-stable

- name: Prepare Build
run: brew bundle
- name: Build
run: swift build

- name: Lint
if: startsWith(github.ref, 'refs/tags/') != true
run: swiftformat --lint . && swiftlint

- name: Run tests
run: swift test --enable-code-coverage

- name: Prepare Code Coverage
run: xcrun llvm-cov export -format="lcov" -instr-profile=$(find .build -name default.profdata) $(find .build -name ${{ env.PACKAGE_NAME }}PackageTests) > info.lcov
- name: Upload to CodeCov.io
uses: codecov/codecov-action@v2
run: xcrun llvm-cov export -format="lcov" .build/debug/${{ env.SP_NAME }}PackageTests.xctest/Contents/MacOS/${{ env.SP_NAME }}PackageTests -instr-profile .build/debug/codecov/default.profdata > coverage.lcov

- name: Upload coverage to CodeCov.io
uses: codecov/codecov-action@v4
with:
files: ./info.lcov
fail_ci_if_error: true
files: ./coverage.lcov
token: ${{ secrets.CODECOV_TOKEN }}
2 changes: 1 addition & 1 deletion Brewfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
brew "swiftformat"
brew "swiftformat"
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 João Mourato
Copyright (c) 2024 João Mourato

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
lint:
swiftformat .
swiftlint --fix
6 changes: 2 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
// swift-tools-version:5.4
// swift-tools-version:5.10
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "Injection",
platforms: [
.iOS(.v11), .macOS(.v10_13), .tvOS(.v11), .watchOS(.v4),
],
platforms: [.iOS(.v13), .macOS(.v12), .watchOS(.v6), .tvOS(.v13)],
products: [
.library(name: "Injection", targets: ["Injection"]),
],
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
**Features:**
- `Singleton`, dependencies that are only instantiated once and are shared amongst its users
- `LazySingleton`, dependencies that are only instantiated once, lazily, and are shared amongst its users
- `Factory`, dependencies that are instancied upon usage, unique to each user
- `Factory`, dependencies that are instancied upon usage, unique to each usage
- Utility property wrappers


Expand Down
2 changes: 1 addition & 1 deletion Sources/Injection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,5 +180,5 @@ public func module(@DependenciesBuilder makeChildren: () -> [Dependency]) -> [De
///
/// - Note: It should be used only once.
public func inject(@DependenciesBuilder makeDependencies: () throws -> [Dependency]) throws {
try Dependencies.shared.inject(try makeDependencies())
try Dependencies.shared.inject(makeDependencies())
}
14 changes: 7 additions & 7 deletions Tests/InjectionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,26 @@ final class InjectionTests: XCTestCase {
}

func testDependencyContainerEmptyInjection() {
assert(try container.inject([]), throws: Injection.InjectionError.noDependenciesInjected)
try assert(container.inject([]), throws: Injection.InjectionError.noDependenciesInjected)
}

func testDependencyContainerDuplicateInjection() {
let duplicates = [
DependencyContainer(isSingleton: true, factory: { A() }),
DependencyContainer(isSingleton: false, factory: { A() }),
]
assert(try container.inject(duplicates), throws: Injection.InjectionError.duplicateDependency("A"))
try assert(container.inject(duplicates), throws: Injection.InjectionError.duplicateDependency("A"))
}

func testDependencyContainerMultipleInjections() {
let first = [DependencyContainer(isSingleton: true, factory: { A() })]
XCTAssertNoThrow(try container.inject(first))
let second = [DependencyContainer(isSingleton: true, factory: { B() })]
assert(try container.inject(second), throws: Injection.InjectionError.multipleDependencyInjection)
try assert(container.inject(second), throws: Injection.InjectionError.multipleDependencyInjection)
}

func testDependencyContainerCannotResolveDependency() {
assert(try container.resolve() as C, throws: Injection.InjectionError.failedToResolveDependency("C"))
try assert(container.resolve() as C, throws: Injection.InjectionError.failedToResolveDependency("C"))
}

func testDependencyContainerProperInjection() {
Expand Down Expand Up @@ -234,16 +234,16 @@ final class InjectionTests: XCTestCase {

func test_factoryCreationWithFailure_wontThrowError() {
XCTAssertNoThrow(try inject { factory { try Failable.create() } })
assert(try resolve() as Failable, throws: Fail.mock)
try assert(resolve() as Failable, throws: Fail.mock)
}

func test_lazySingletonCreationWithFailure_wontThrowError() {
XCTAssertNoThrow(try inject { lazySingleton { try Failable.create() } })
assert(try resolve() as Failable, throws: Fail.mock)
try assert(resolve() as Failable, throws: Fail.mock)
}

func test_singletonCreationWithFailure_willThrowErrorImmediately() {
assert(try inject { try singleton { try Failable.create() } }, throws: Fail.mock)
try assert(inject { try singleton { try Failable.create() } }, throws: Fail.mock)
}
}

Expand Down

0 comments on commit 66b5a7a

Please sign in to comment.