@@ -63,6 +63,18 @@ class FmtTests extends ScalaCliSuite {
6363 os.rel / " Foo.scala" -> simpleInputsUnformattedContent
6464 )
6565
66+ val simpleInputsWithoutConf : TestInputs = TestInputs (
67+ os.rel / " Foo.scala" -> simpleInputsUnformattedContent
68+ )
69+
70+ private def workspaceConfPath (root : os.Path ): os.Path =
71+ root / Constants .workspaceDirName / confFileName
72+
73+ private def expectNoWorkspaceScalafmtConf (root : os.Path ): Unit = {
74+ expect(! os.exists(workspaceConfPath(root)))
75+ expect(! os.exists(root / Constants .workspaceDirName))
76+ }
77+
6678 private def noCrLf (input : String ): String =
6779 input.replaceAll(" \r\n " , " \n " )
6880
@@ -175,12 +187,73 @@ class FmtTests extends ScalaCliSuite {
175187 }
176188 }
177189
190+ test(" complete .scalafmt.conf is not duplicated under .scala-build" ) {
191+ simpleInputs.fromRoot { root =>
192+ os.proc(TestUtil .cli, " fmt" , " ." ).call(cwd = root)
193+ val updatedContent = noCrLf(os.read(root / " Foo.scala" ))
194+ expect(updatedContent == expectedSimpleInputsFormattedContent)
195+ expectNoWorkspaceScalafmtConf(root)
196+ }
197+ }
198+
199+ test(" complete .scalafmt.conf + matching --scalafmt-version still avoids .scala-build" ) {
200+ simpleInputs.fromRoot { root =>
201+ os.proc(
202+ TestUtil .cli,
203+ " fmt" ,
204+ " ." ,
205+ " --scalafmt-version" ,
206+ Constants .defaultScalafmtVersion
207+ ).call(cwd = root)
208+ val updatedContent = noCrLf(os.read(root / " Foo.scala" ))
209+ expect(updatedContent == expectedSimpleInputsFormattedContent)
210+ expectNoWorkspaceScalafmtConf(root)
211+ }
212+ }
213+
214+ test(" complete .scalafmt.conf + matching --scalafmt-dialect still avoids .scala-build" ) {
215+ simpleInputs.fromRoot { root =>
216+ os.proc(TestUtil .cli, " fmt" , " ." , " --scalafmt-dialect" , " scala213" ).call(cwd = root)
217+ val updatedContent = noCrLf(os.read(root / " Foo.scala" ))
218+ expect(updatedContent == expectedSimpleInputsFormattedContent)
219+ expectNoWorkspaceScalafmtConf(root)
220+ }
221+ }
222+
223+ test(" complete .scalafmt.conf in git root is used in place" ) {
224+ simpleInputs.fromRoot { root =>
225+ TestUtil .initializeGit(root)
226+ val subdir = root / " subdir"
227+ os.makeDir.all(subdir)
228+ os.move(root / " Foo.scala" , subdir / " Foo.scala" )
229+ os.proc(TestUtil .cli, " fmt" , " ." ).call(cwd = subdir)
230+ val updatedContent = noCrLf(os.read(subdir / " Foo.scala" ))
231+ expect(updatedContent == expectedSimpleInputsFormattedContent)
232+ expectNoWorkspaceScalafmtConf(subdir)
233+ expectNoWorkspaceScalafmtConf(root)
234+ }
235+ }
236+
237+ test(" no .scalafmt.conf still triggers .scala-build" ) {
238+ simpleInputsWithoutConf.fromRoot { root =>
239+ // Isolate from the enclosing scala-cli git repo
240+ // (whose .scalafmt.conf would otherwise be discovered)
241+ TestUtil .initializeGit(root)
242+ val confPath = workspaceConfPath(root)
243+ expect(! os.exists(confPath))
244+ os.proc(TestUtil .cli, " fmt" , " ." ).call(cwd = root)
245+ expect(os.exists(confPath))
246+ val updatedContent = noCrLf(os.read(root / " Foo.scala" ))
247+ expect(updatedContent == expectedSimpleInputsFormattedContent)
248+ }
249+ }
250+
178251 test(" creating workspace conf file" ) {
179252 simpleInputsWithDialectOnly.fromRoot { root =>
180- val workspaceConfPath = root / Constants .workspaceDirName / confFileName
181- expect(! os.exists(workspaceConfPath ))
253+ val confPath = workspaceConfPath( root)
254+ expect(! os.exists(confPath ))
182255 os.proc(TestUtil .cli, " fmt" , " ." ).call(cwd = root)
183- expect(os.exists(workspaceConfPath ))
256+ expect(os.exists(confPath ))
184257 val updatedContent = noCrLf(os.read(root / " Foo.scala" ))
185258 expect(updatedContent == expectedSimpleInputsFormattedContent)
186259 }
0 commit comments