@@ -10,64 +10,76 @@ trait CompilerPluginTestDefinitions { _: CompileTestDefinitions =>
10
10
CompilerPluginUtil .compilerPluginForScala3(pluginName, pluginErrorMsg)
11
11
else CompilerPluginUtil .compilerPluginForScala2(pluginName, pluginErrorMsg)
12
12
13
- test(" build a custom compiler plugin and use it" ) {
14
- val pluginName = " divbyzero"
15
- val usePluginFile = " Main.scala"
16
- val outputJar = " div-by-zero.jar"
17
- val pluginErrorMsg = " definitely division by zero"
18
- compilerPluginInputs(pluginName, pluginErrorMsg)
19
- .add(os.rel / usePluginFile ->
20
- s """ //> using option -Xplugin: $outputJar
21
- |
22
- |object Test {
23
- | val five = 5
24
- | val amount = five / 0
25
- | def main(args: Array[String]): Unit = {
26
- | println(amount)
27
- | }
28
- |}
29
- | """ .stripMargin)
30
- .fromRoot { root =>
31
- // build the compiler plugin
32
- os.proc(
33
- TestUtil .cli,
34
- " package" ,
35
- s " $pluginName.scala " ,
36
- " --power" ,
37
- " --with-compiler" ,
38
- " --library" ,
39
- " -o" ,
40
- outputJar,
41
- extraOptions
42
- ).call(cwd = root)
43
- expect(os.isFile(root / outputJar))
13
+ for {
14
+ pluginViaDirective <- Seq (true , false )
15
+ testLabel = if (pluginViaDirective) " use plugin via directive" else " use plugin via CLI option"
16
+ }
17
+ test(s " build a custom compiler plugin and use it ( $testLabel) " ) {
18
+ val pluginName = " divbyzero"
19
+ val usePluginFile = " Main.scala"
20
+ val outputJar = " div-by-zero.jar"
21
+ val pluginErrorMsg = " definitely division by zero"
22
+ compilerPluginInputs(pluginName, pluginErrorMsg)
23
+ .add(os.rel / usePluginFile ->
24
+ s """ ${if (pluginViaDirective) s " //> using option -Xplugin: $outputJar" else " " }
25
+ |
26
+ |object Test {
27
+ | val five = 5
28
+ | val amount = five / 0
29
+ | def main(args: Array[String]): Unit = {
30
+ | println(amount)
31
+ | }
32
+ |}
33
+ | """ .stripMargin)
34
+ .fromRoot { root =>
35
+ // build the compiler plugin
36
+ os.proc(
37
+ TestUtil .cli,
38
+ " package" ,
39
+ s " $pluginName.scala " ,
40
+ " --power" ,
41
+ " --with-compiler" ,
42
+ " --library" ,
43
+ " -o" ,
44
+ outputJar,
45
+ extraOptions
46
+ ).call(cwd = root)
47
+ expect(os.isFile(root / outputJar))
44
48
45
- // verify the plugin is loaded
46
- val pluginListResult = os.proc(
47
- TestUtil .cli,
48
- " compile" ,
49
- s " -Xplugin: $outputJar" ,
50
- " -Xplugin-list" ,
51
- extraOptions
52
- ).call(cwd = root, mergeErrIntoOut = true )
53
- expect(pluginListResult.out.text().contains(pluginName))
49
+ // verify the plugin is loaded
50
+ val pluginListResult = os.proc(
51
+ TestUtil .cli,
52
+ " compile" ,
53
+ s " -Xplugin: $outputJar" ,
54
+ " -Xplugin-list" ,
55
+ extraOptions
56
+ ).call(cwd = root, mergeErrIntoOut = true )
57
+ expect(pluginListResult.out.text().contains(pluginName))
54
58
55
- // verify the compiler plugin phase is being added correctly
56
- os.proc(
57
- TestUtil .cli,
58
- " compile" ,
59
- s " -Xplugin: $outputJar" ,
60
- " -Xshow-phases" ,
61
- extraOptions
62
- ).call(cwd = root, mergeErrIntoOut = true )
63
- expect(pluginListResult.out.text().contains(pluginName))
59
+ // verify the compiler plugin phase is being added correctly
60
+ os.proc(
61
+ TestUtil .cli,
62
+ " compile" ,
63
+ s " -Xplugin: $outputJar" ,
64
+ " -Xshow-phases" ,
65
+ extraOptions
66
+ ).call(cwd = root, mergeErrIntoOut = true )
67
+ expect(pluginListResult.out.text().contains(pluginName))
64
68
65
- // verify the compiler plugin is working
66
- // TODO: this shouldn't require running with --server=false
67
- val res = os.proc(TestUtil .cli, " compile" , usePluginFile, " --server=false" , extraOptions)
68
- .call(cwd = root, mergeErrIntoOut = true , check = false )
69
- expect(res.exitCode == 1 )
70
- expect(res.out.text().contains(pluginErrorMsg))
71
- }
72
- }
69
+ val pluginOptions = if (pluginViaDirective) Nil else Seq (s " -Xplugin: $outputJar" )
70
+ // verify the compiler plugin is working
71
+ // TODO: this shouldn't require running with --server=false
72
+ val res = os.proc(
73
+ TestUtil .cli,
74
+ " compile" ,
75
+ pluginOptions,
76
+ usePluginFile,
77
+ " --server=false" ,
78
+ extraOptions
79
+ )
80
+ .call(cwd = root, mergeErrIntoOut = true , check = false )
81
+ expect(res.exitCode == 1 )
82
+ expect(res.out.text().contains(pluginErrorMsg))
83
+ }
84
+ }
73
85
}
0 commit comments