@@ -21,30 +21,45 @@ import ShellOut
2121import Testing
2222
2323
24+ private extension DependenciesProvider {
25+ static var `default` : Self {
26+ . init {
27+ $0. logger = . noop
28+ $0. shell = . liveValue
29+ }
30+ }
31+ }
32+
33+
34+ extension AllTests {
35+ @Suite ( . dependencies( . default) ) struct GitLiveTests { }
36+ }
37+
38+
2439extension AllTests . GitLiveTests {
2540
2641 @Test func commitCount( ) async throws {
27- try await withGitRepository ( defaultDependencies ) { path throws in
42+ try await withGitRepository { path throws in
2843 #expect( try await Git . commitCount ( at: path) == 57 )
2944 }
3045 }
3146
3247 @Test func firstCommitDate( ) async throws {
33- try await withGitRepository ( defaultDependencies ) { path throws in
48+ try await withGitRepository { path throws in
3449 #expect( try await Git . firstCommitDate ( at: path)
3550 == Date ( timeIntervalSince1970: 1426918070 ) ) // Sat, 21 March 2015
3651 }
3752 }
3853
3954 @Test func lastCommitDate( ) async throws {
40- try await withGitRepository ( defaultDependencies ) { path throws in
55+ try await withGitRepository { path throws in
4156 #expect( try await Git . lastCommitDate ( at: path)
4257 == Date ( timeIntervalSince1970: 1554248253 ) ) // Sat, 21 March 2015
4358 }
4459 }
4560
4661 @Test func getTags( ) async throws {
47- try await withGitRepository ( defaultDependencies ) { path throws in
62+ try await withGitRepository { path throws in
4863 #expect(
4964 try await Git . getTags ( at: path) == [
5065 . tag( 0 , 2 , 0 ) ,
@@ -72,14 +87,14 @@ extension AllTests.GitLiveTests {
7287 }
7388
7489 @Test func hasBranch( ) async throws {
75- try await withGitRepository ( defaultDependencies ) { path throws in
90+ try await withGitRepository { path throws in
7691 #expect( try await Git . hasBranch ( . branch( " master " ) , at: path) == true )
7792 #expect( try await Git . hasBranch ( . branch( " main " ) , at: path) == false )
7893 }
7994 }
8095
8196 @Test func revisionInfo( ) async throws {
82- try await withGitRepository ( defaultDependencies ) { path throws in
97+ try await withGitRepository { path throws in
8398 #expect( try await Git . revisionInfo ( . tag( 0 , 5 , 2 ) , at: path)
8499 == . init( commit: " 178566b112afe6bef3770678f1bbab6e5c626993 " ,
85100 date: . init( timeIntervalSince1970: 1554248253 ) ) )
@@ -90,7 +105,7 @@ extension AllTests.GitLiveTests {
90105 }
91106
92107 @Test func shortlog( ) async throws {
93- try await withGitRepository ( defaultDependencies ) { path throws in
108+ try await withGitRepository { path throws in
94109 #expect( try await Git . shortlog ( at: path) == """
95110 36 \t Neil Pankey
96111 21 \t Jacob Williams
@@ -101,30 +116,11 @@ extension AllTests.GitLiveTests {
101116}
102117
103118
104- private func withGitRepository(
105- _ updateValuesForOperation: ( inout DependencyValues ) async throws -> Void = { _ in } ,
106- _ test: ( _ zipFilePath: String ) async throws -> Void
107- ) async throws {
108- try await withDependencies ( updateValuesForOperation) {
109- try await withTempDir { tempDir in
110- let fixtureFile = fixturesDirectory ( ) . appendingPathComponent ( " ErrNo.zip " ) . path
111- try await ShellOut . shellOut ( to: . init( command: " unzip " , arguments: [ fixtureFile] ) , at: tempDir)
112- let path = " \( tempDir) /ErrNo "
113- try await test ( path)
114- }
115- }
116- }
117-
118-
119- extension AllTests . GitLiveTests {
120- #if compiler(>=6.1)
121- #warning("Move this into a trait on @Test")
122- // See https://forums.swift.org/t/converting-xctest-invoketest-to-swift-testing/77692/4 for details
123- #endif
124- var defaultDependencies : ( inout DependencyValues ) async throws -> Void {
125- {
126- $0. logger = . noop
127- $0. shell = . liveValue
128- }
119+ private func withGitRepository( _ test: ( _ zipFilePath: String ) async throws -> Void ) async throws {
120+ try await withTempDir { tempDir in
121+ let fixtureFile = fixturesDirectory ( ) . appendingPathComponent ( " ErrNo.zip " ) . path
122+ try await ShellOut . shellOut ( to: . init( command: " unzip " , arguments: [ fixtureFile] ) , at: tempDir)
123+ let path = " \( tempDir) /ErrNo "
124+ try await test ( path)
129125 }
130126}
0 commit comments