1
1
package org .scalasteward .core .edit
2
2
3
- import better .files .File
4
3
import cats .effect .unsafe .implicits .global
5
4
import munit .FunSuite
6
5
import org .scalasteward .core .TestInstances .dummyRepoCache
@@ -16,46 +15,39 @@ import org.scalasteward.core.scalafmt.ScalafmtAlg.opts
16
15
import org .scalasteward .core .scalafmt .{scalafmtBinary , scalafmtConfName , scalafmtDependency }
17
16
18
17
class EditAlgTest extends FunSuite {
19
- private def gitStatus (repoDir : File ): Cmd =
20
- Cmd .git(repoDir, " status" , " --porcelain" , " --untracked-files=no" , " --ignore-submodules" )
21
-
22
18
test(" applyUpdate" ) {
23
19
val repo = Repo (" edit-alg" , " test-1" )
24
20
val data = RepoData (repo, dummyRepoCache, RepoConfig .empty)
25
21
val repoDir = workspaceAlg.repoDir(repo).unsafeRunSync()
26
22
val update = (" org.typelevel" .g % " cats-core" .a % " 1.2.0" %> " 1.3.0" ).single
27
- val file1 = repoDir / " build.sbt"
28
- val file2 = repoDir / " project/Dependencies.scala"
23
+ val buildSbt = repoDir / " build.sbt"
24
+ val scalaFile = repoDir / " project/Dependencies.scala"
29
25
val gitignore = repoDir / " .gitignore"
30
26
31
27
val state = MockState .empty
32
- .addFiles(file1 -> """ val catsVersion = "1.2.0"""" , file2 -> " " , gitignore -> " " )
28
+ .copy(execCommands = true )
29
+ .initGitRepo(
30
+ repoDir,
31
+ buildSbt -> """ val catsVersion = "1.2.0"""" ,
32
+ scalaFile -> " " ,
33
+ gitignore -> " "
34
+ )
33
35
.flatMap(editAlg.applyUpdate(data, update).runS)
34
36
.unsafeRunSync()
35
37
36
38
val expected = MockState .empty.copy(
39
+ execCommands = true ,
37
40
trace = Vector (
38
- Cmd (" read" , gitignore.pathAsString),
39
- Cmd (" test" , " -f" , repoDir.pathAsString),
40
- Cmd (" test" , " -f" , gitignore.pathAsString),
41
- Cmd (" test" , " -f" , file1.pathAsString),
42
- Cmd (" read" , file1.pathAsString),
43
- Cmd (" test" , " -f" , (repoDir / " project" ).pathAsString),
44
- Cmd (" test" , " -f" , file2.pathAsString),
45
- Cmd (" read" , file2.pathAsString),
46
- Cmd (" read" , gitignore.pathAsString),
47
- Cmd (" test" , " -f" , repoDir.pathAsString),
48
- Cmd (" test" , " -f" , gitignore.pathAsString),
49
- Cmd (" test" , " -f" , file1.pathAsString),
50
- Cmd (" read" , file1.pathAsString),
51
- Cmd (" test" , " -f" , (repoDir / " project" ).pathAsString),
52
- Cmd (" test" , " -f" , file2.pathAsString),
53
- Cmd (" read" , file2.pathAsString),
54
- Cmd (" read" , file1.pathAsString),
55
- Cmd (" write" , file1.pathAsString),
56
- gitStatus(repoDir)
41
+ Cmd .gitGrep(repoDir, update.currentVersion.value),
42
+ Cmd (" read" , buildSbt.pathAsString),
43
+ Cmd .gitGrep(repoDir, update.groupId.value),
44
+ Cmd (" read" , buildSbt.pathAsString),
45
+ Cmd (" write" , buildSbt.pathAsString),
46
+ Cmd .gitStatus(repoDir),
47
+ Cmd .gitCommit(repoDir, " Update cats-core to 1.3.0" ),
48
+ Cmd .gitLatestSha1(repoDir)
57
49
),
58
- files = Map (file1 -> """ val catsVersion = "1.3.0"""" , file2 -> " " , gitignore -> " " )
50
+ files = Map (buildSbt -> """ val catsVersion = "1.3.0"""" , scalaFile -> " " , gitignore -> " " )
59
51
)
60
52
61
53
assertEquals(state, expected)
@@ -69,80 +61,67 @@ class EditAlgTest extends FunSuite {
69
61
val data = RepoData (repo, cache, RepoConfig .empty)
70
62
val repoDir = workspaceAlg.repoDir(repo).unsafeRunSync()
71
63
val update = (" org.scalameta" .g % " scalafmt-core" .a % " 2.0.0" %> " 2.1.0" ).single
72
- val gitignore = repoDir / " .gitignore"
64
+ val gitignore = ( repoDir / " .gitignore" ) -> " target/ "
73
65
val scalafmtConf = repoDir / scalafmtConfName
74
66
val scalafmtConfContent = """ maxColumn = 100
75
67
|version = 2.0.0
76
68
|align.openParenCallSite = false
77
69
|""" .stripMargin
78
- val buildSbt = repoDir / " build.sbt"
70
+ val buildSbt = ( repoDir / " build.sbt" ) -> " \n "
79
71
val target = repoDir / " target"
80
72
// this file should not be read because it's under target which is git ignored
81
73
val targetScalaFile = target / " SomeFile.scala"
82
74
83
75
val state = MockState .empty
84
- .addFiles(
85
- scalafmtConf -> scalafmtConfContent,
86
- buildSbt -> " " ,
87
- gitignore -> " target/" ,
88
- targetScalaFile -> " "
89
- )
76
+ .copy(execCommands = true )
77
+ .initGitRepo(repoDir, scalafmtConf -> scalafmtConfContent, buildSbt, gitignore)
78
+ .flatMap(_.addFiles(targetScalaFile -> s """ object Test {"2.0.0"} """ ))
90
79
.flatMap(editAlg.applyUpdate(data, update).runS)
91
80
.unsafeRunSync()
92
81
93
82
val expected = MockState .empty.copy(
83
+ execCommands = true ,
94
84
trace = Vector (
95
- Cmd (" read" , gitignore.pathAsString),
96
- Cmd (" test" , " -f" , repoDir.pathAsString),
97
- Cmd (" test" , " -f" , gitignore.pathAsString),
98
- Cmd (" test" , " -f" , scalafmtConf.pathAsString),
85
+ Cmd .gitGrep(repoDir, update.currentVersion.value),
99
86
Cmd (" read" , scalafmtConf.pathAsString),
100
- Cmd (" test" , " -f" , buildSbt.pathAsString),
101
- Cmd (" read" , buildSbt.pathAsString),
102
- Cmd (" test" , " -f" , target.pathAsString),
103
- Cmd (" test" , " -f" , targetScalaFile.pathAsString),
104
- Cmd (" read" , gitignore.pathAsString),
105
- Cmd (" test" , " -f" , repoDir.pathAsString),
106
- Cmd (" test" , " -f" , gitignore.pathAsString),
107
- Cmd (" test" , " -f" , scalafmtConf.pathAsString),
108
- Cmd (" read" , scalafmtConf.pathAsString),
109
- Cmd (" test" , " -f" , buildSbt.pathAsString),
110
- Cmd (" read" , buildSbt.pathAsString),
111
- Cmd (" test" , " -f" , target.pathAsString),
112
- Cmd (" test" , " -f" , targetScalaFile.pathAsString),
87
+ Cmd .gitGrep(repoDir, update.groupId.value),
113
88
Cmd (" read" , scalafmtConf.pathAsString),
114
89
Cmd (" write" , scalafmtConf.pathAsString),
115
90
Cmd .exec(repoDir, scalafmtBinary :: opts.nonInteractive :: opts.modeChanged: _* ),
116
- gitStatus(repoDir),
91
+ Cmd .gitStatus(repoDir),
92
+ Cmd .gitCommit(repoDir, " Update scalafmt-core to 2.1.0" ),
93
+ Cmd .gitLatestSha1(repoDir),
117
94
Log (
118
95
" Executing post-update hook for org.scalameta:scalafmt-core with command 'scalafmt --non-interactive'"
119
96
),
120
97
Cmd .exec(repoDir, scalafmtBinary, opts.nonInteractive),
121
- gitStatus(repoDir)
98
+ Cmd . gitStatus(repoDir)
122
99
),
123
100
files = Map (
124
101
scalafmtConf ->
125
102
""" maxColumn = 100
126
103
|version = 2.1.0
127
104
|align.openParenCallSite = false
128
105
|""" .stripMargin,
129
- buildSbt -> " " ,
130
- gitignore -> " target/ " ,
131
- targetScalaFile -> " "
106
+ buildSbt,
107
+ gitignore,
108
+ targetScalaFile -> s """ object Test { "2.0.0" }\n " ""
132
109
)
133
110
)
134
111
135
112
assertEquals(state, expected)
136
113
}
137
114
138
115
test(" applyUpdate with build Scalafix" ) {
139
- val repo = Repo (" edit-alg" , " test-3-1 " )
116
+ val repo = Repo (" edit-alg" , " test-3" )
140
117
val data = RepoData (repo, dummyRepoCache, RepoConfig .empty)
141
118
val repoDir = workspaceAlg.repoDir(repo).unsafeRunSync()
142
119
val update = (sbtGroupId % sbtArtifactId % " 1.4.9" %> " 1.5.5" ).single
143
120
144
121
val state = MockState .empty
145
- .addFiles(
122
+ .copy(execCommands = true )
123
+ .initGitRepo(
124
+ repoDir,
146
125
repoDir / " build.sbt" -> " " ,
147
126
repoDir / " project" / " build.properties" -> """ sbt.version=1.4.9"""
148
127
)
0 commit comments