@@ -2,6 +2,8 @@ package scala.cli.integration
2
2
3
3
import com .eed3si9n .expecty .Expecty .expect
4
4
5
+ import scala .util .Properties
6
+
5
7
trait FixScalafixRulesTestDefinitions {
6
8
_ : FixTestDefinitions =>
7
9
protected val scalafixConfFileName : String = " .scalafix.conf"
@@ -293,37 +295,58 @@ trait FixScalafixRulesTestDefinitions {
293
295
}
294
296
}
295
297
296
- test(" scalafix rules requiring SemanticDB run correctly with test scope sources" ) {
297
- val compilerOptions =
298
- if (actualScalaVersion.startsWith(" 2.12" )) Seq (" -Ywarn-unused-import" )
299
- else Seq (" -Wunused:imports" )
300
- TestInputs (
301
- os.rel / scalafixConfFileName ->
302
- """ rules = [
303
- | DisableSyntax,
304
- | LeakingImplicitClassVal,
305
- | NoValInForComprehension,
306
- | ExplicitResultTypes,
307
- | OrganizeImports
308
- |]
309
- |ExplicitResultTypes.fetchScala3CompilerArtifactsOnVersionMismatch = true
310
- |""" .stripMargin,
311
- os.rel / projectFileName ->
312
- s """ //> using test.dep org.scalameta::munit:: ${Constants .munitVersion}
313
- |//> using options ${compilerOptions.mkString(" " )}
314
- | """ .stripMargin,
315
- os.rel / " example.test.scala" ->
316
- """ import munit.FunSuite
317
- |
318
- |class Munit extends FunSuite {
319
- | test("foo") {
320
- | assert(2 + 2 == 4)
321
- | println("Hello from Munit")
322
- | }
323
- |}
324
- |""" .stripMargin
325
- ).fromRoot { root =>
326
- os.proc(TestUtil .cli, " fix" , " ." , " --power" , extraOptions).call(cwd = root)
327
- }
298
+ for {
299
+ (semanticDbOptions, expectedSuccess) <- Seq (
300
+ Nil -> true , // .semanticdb files should be implicitly generated when Scalafix is run
301
+ Seq (" --semanticdb" ) -> true ,
302
+ Seq (" --semanticdb=false" ) -> false
303
+ )
304
+ semanticDbOptionsDescription =
305
+ if (semanticDbOptions.nonEmpty) s " ( ${semanticDbOptions.mkString(" " )}) "
306
+ else " "
307
+ verb = if (expectedSuccess) " run" else " fail"
308
+ if ! Properties .isWin || expectedSuccess
328
309
}
310
+ test(
311
+ s " scalafix rules requiring SemanticDB $verb correctly with test scope sources $semanticDbOptionsDescription"
312
+ ) {
313
+ val compilerOptions =
314
+ if (actualScalaVersion.startsWith(" 2.12" )) Seq (" -Ywarn-unused-import" )
315
+ else Seq (" -Wunused:imports" )
316
+ TestInputs (
317
+ os.rel / scalafixConfFileName ->
318
+ """ rules = [
319
+ | DisableSyntax,
320
+ | LeakingImplicitClassVal,
321
+ | NoValInForComprehension,
322
+ | ExplicitResultTypes,
323
+ | OrganizeImports
324
+ |]
325
+ |ExplicitResultTypes.fetchScala3CompilerArtifactsOnVersionMismatch = true
326
+ |""" .stripMargin,
327
+ os.rel / projectFileName ->
328
+ s """ //> using test.dep org.scalameta::munit:: ${Constants .munitVersion}
329
+ |//> using options ${compilerOptions.mkString(" " )}
330
+ | """ .stripMargin,
331
+ os.rel / " example.test.scala" ->
332
+ """ import munit.FunSuite
333
+ |
334
+ |class Munit extends FunSuite {
335
+ | test("foo") {
336
+ | assert(2 + 2 == 4)
337
+ | println("Hello from Munit")
338
+ | }
339
+ |}
340
+ |""" .stripMargin
341
+ ).fromRoot { root =>
342
+ val res = os.proc(TestUtil .cli, " fix" , " ." , " --power" , semanticDbOptions, extraOptions)
343
+ .call(cwd = root, check = false , stderr = os.Pipe )
344
+ val successful = res.exitCode == 0
345
+ expect(successful == expectedSuccess)
346
+ if (! expectedSuccess)
347
+ expect(
348
+ res.err.trim().contains(" SemanticDB files' generation was explicitly set to false" )
349
+ )
350
+ }
351
+ }
329
352
}
0 commit comments