@@ -21,30 +21,45 @@ import ShellOut
21
21
import Testing
22
22
23
23
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
+
24
39
extension AllTests . GitLiveTests {
25
40
26
41
@Test func commitCount( ) async throws {
27
- try await withGitRepository ( defaultDependencies ) { path throws in
42
+ try await withGitRepository { path throws in
28
43
#expect( try await Git . commitCount ( at: path) == 57 )
29
44
}
30
45
}
31
46
32
47
@Test func firstCommitDate( ) async throws {
33
- try await withGitRepository ( defaultDependencies ) { path throws in
48
+ try await withGitRepository { path throws in
34
49
#expect( try await Git . firstCommitDate ( at: path)
35
50
== Date ( timeIntervalSince1970: 1426918070 ) ) // Sat, 21 March 2015
36
51
}
37
52
}
38
53
39
54
@Test func lastCommitDate( ) async throws {
40
- try await withGitRepository ( defaultDependencies ) { path throws in
55
+ try await withGitRepository { path throws in
41
56
#expect( try await Git . lastCommitDate ( at: path)
42
57
== Date ( timeIntervalSince1970: 1554248253 ) ) // Sat, 21 March 2015
43
58
}
44
59
}
45
60
46
61
@Test func getTags( ) async throws {
47
- try await withGitRepository ( defaultDependencies ) { path throws in
62
+ try await withGitRepository { path throws in
48
63
#expect(
49
64
try await Git . getTags ( at: path) == [
50
65
. tag( 0 , 2 , 0 ) ,
@@ -72,14 +87,14 @@ extension AllTests.GitLiveTests {
72
87
}
73
88
74
89
@Test func hasBranch( ) async throws {
75
- try await withGitRepository ( defaultDependencies ) { path throws in
90
+ try await withGitRepository { path throws in
76
91
#expect( try await Git . hasBranch ( . branch( " master " ) , at: path) == true )
77
92
#expect( try await Git . hasBranch ( . branch( " main " ) , at: path) == false )
78
93
}
79
94
}
80
95
81
96
@Test func revisionInfo( ) async throws {
82
- try await withGitRepository ( defaultDependencies ) { path throws in
97
+ try await withGitRepository { path throws in
83
98
#expect( try await Git . revisionInfo ( . tag( 0 , 5 , 2 ) , at: path)
84
99
== . init( commit: " 178566b112afe6bef3770678f1bbab6e5c626993 " ,
85
100
date: . init( timeIntervalSince1970: 1554248253 ) ) )
@@ -90,7 +105,7 @@ extension AllTests.GitLiveTests {
90
105
}
91
106
92
107
@Test func shortlog( ) async throws {
93
- try await withGitRepository ( defaultDependencies ) { path throws in
108
+ try await withGitRepository { path throws in
94
109
#expect( try await Git . shortlog ( at: path) == """
95
110
36 \t Neil Pankey
96
111
21 \t Jacob Williams
@@ -101,30 +116,11 @@ extension AllTests.GitLiveTests {
101
116
}
102
117
103
118
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)
129
125
}
130
126
}
0 commit comments