@@ -6,32 +6,40 @@ import scala.util.Properties
6
6
7
7
class SipScalaTests extends ScalaCliSuite {
8
8
9
- def noDirectoriesCommandTest (binaryName : String ): Unit =
10
- TestInputs .empty.fromRoot { root =>
11
- val cliPath = os.Path (TestUtil .cliPath, os.pwd)
9
+ implicit class BinaryNameOps (binaryName : String ) {
10
+ def prepareBinary (root : os.Path ): os.Path = {
11
+ val cliPath = os.Path (TestUtil .cliPath, os.pwd)
12
+ val ext = if (Properties .isWin) " .exe" else " "
13
+ val newCliPath = root / s " $binaryName$ext"
14
+ os.copy(cliPath, newCliPath)
15
+ if (! Properties .isWin) os.perms.set(newCliPath, " rwxr-xr-x" )
16
+ newCliPath
17
+ }
12
18
13
- os.proc(cliPath, " directories" ).call(cwd = root)
14
- os.proc(cliPath, " compile" , " --help" ).call(cwd = root)
15
- os.proc(cliPath, " run" , " --help" ).call(cwd = root)
19
+ def isSip : Boolean = binaryName == " scala" || binaryName.endsWith(" sip" )
20
+ }
16
21
17
- os.copy(cliPath, root / binaryName)
18
- os.perms.set(root / binaryName, " rwxr-xr-x" )
22
+ def testDirectoriesCommand (binaryName : String ): Unit =
23
+ TestInputs .empty.fromRoot { root =>
24
+ val binary = binaryName.prepareBinary(root)
19
25
20
- os.proc(root / binaryName , " compile" , " --help" ).call(cwd = root)
21
- os.proc(root / binaryName , " run" , " --help" ).call(cwd = root)
26
+ os.proc(binary , " compile" , " --help" ).call(cwd = root)
27
+ os.proc(binary , " run" , " --help" ).call(cwd = root)
22
28
23
- val res = os.proc(root / binaryName , " directories" ).call(
29
+ val res = os.proc(binary , " directories" ).call(
24
30
cwd = root,
25
31
check = false ,
26
32
mergeErrIntoOut = true
27
33
)
28
- expect(res.exitCode == 1 )
29
- val output = res.out.text()
30
- expect(output.contains(s " directories: not found " ))
31
-
34
+ if (binaryName.isSip) {
35
+ expect(res.exitCode == 1 )
36
+ val output = res.out.text()
37
+ expect(output.contains(s " directories: not found " ))
38
+ }
39
+ else expect(res.exitCode == 0 )
32
40
}
33
41
34
- def noPublishDirectives ( ): Unit = TestInputs .empty.fromRoot { root =>
42
+ def testPublishDirectives ( binaryName : String ): Unit = TestInputs .empty.fromRoot { root =>
35
43
val code =
36
44
"""
37
45
| //> using publish.name "my-library"
@@ -41,24 +49,24 @@ class SipScalaTests extends ScalaCliSuite {
41
49
val source = root / " A.scala"
42
50
os.write(source, code)
43
51
44
- val cliPath = os. Path ( TestUtil .cliPath, os.pwd )
52
+ val binary = binaryName.prepareBinary(root )
45
53
46
- os.proc(cliPath, " compile" , source).call(cwd = root)
47
-
48
- os.copy(cliPath, root / " scala" )
49
- os.perms.set(root / " scala" , " rwxr-xr-x" )
50
-
51
- val res = os.proc(root / " scala" , " compile" , source).call(
54
+ val res = os.proc(binary, " compile" , source).call(
52
55
cwd = root,
53
56
check = false ,
54
57
mergeErrIntoOut = true
55
58
)
56
- expect(res.exitCode == 1 )
57
- val output = res.out.text()
58
- expect(output.contains(s " directive is not supported " ))
59
+
60
+ if (binaryName.isSip) {
61
+ expect(res.exitCode == 1 )
62
+ val output = res.out.text()
63
+ expect(output.contains(s " directive is not supported " ))
64
+ }
65
+ else
66
+ expect(res.exitCode == 0 )
59
67
}
60
68
61
- def noMarkdownOptions ( ): Unit = TestInputs .empty.fromRoot { root =>
69
+ def testMarkdownOptions ( binaryName : String ): Unit = TestInputs .empty.fromRoot { root =>
62
70
val code =
63
71
"""
64
72
| println("ala")
@@ -67,90 +75,64 @@ class SipScalaTests extends ScalaCliSuite {
67
75
val source = root / " A.sc"
68
76
os.write(source, code)
69
77
70
- val cliPath = os. Path ( TestUtil .cliPath, os.pwd )
78
+ val binary = binaryName.prepareBinary(root )
71
79
72
- os.proc(cliPath, " --markdown" , source).call(cwd = root)
73
-
74
- os.copy(cliPath, root / " scala" )
75
- os.perms.set(root / " scala" , " rwxr-xr-x" )
76
-
77
- val res = os.proc(root / " scala" , " --markdown" , source).call(
80
+ val res = os.proc(binary, " --markdown" , source).call(
78
81
cwd = root,
79
82
check = false ,
80
83
mergeErrIntoOut = true
81
84
)
82
- expect(res.exitCode == 1 )
83
- val output = res.out.text()
84
- expect(output.contains(s " option is not supported " ))
85
- }
86
-
87
- if (TestUtil .isNativeCli && ! Properties .isWin) {
88
- test(" no directories command when run as scala" ) {
89
- noDirectoriesCommandTest(" scala" )
90
- }
91
- test(" no directories command when run as scala-cli-sip" ) {
92
- noDirectoriesCommandTest(" scala-cli-sip" )
93
- }
94
-
95
- test(" no publish directives when run as scala" ) {
96
- noPublishDirectives()
97
- }
98
-
99
- test(" no markdown option when run as scala" ) {
100
- noMarkdownOptions()
85
+ if (binaryName.isSip) {
86
+ expect(res.exitCode == 1 )
87
+ val output = res.out.text()
88
+ expect(output.contains(s " option is not supported " ))
101
89
}
90
+ else expect(res.exitCode == 0 )
102
91
}
103
92
104
- def runVersionCommand (binaryName : String ) =
93
+ def testVersionCommand (binaryName : String ): Unit =
105
94
TestInputs .empty.fromRoot { root =>
106
- val cliPath = os.Path (TestUtil .cliPath, os.pwd)
107
- val ext = if (Properties .isWin) " .exe" else " "
108
- val newCliPath = root / s " $binaryName$ext"
109
- os.copy(cliPath, newCliPath)
110
-
95
+ val binary = binaryName.prepareBinary(root)
111
96
for { versionOption <- Seq (" version" , " -version" , " --version" ) } {
112
- val version = os.proc(newCliPath , versionOption).call(check = false )
97
+ val version = os.proc(binary , versionOption).call(check = false )
113
98
assert(
114
99
version.exitCode == 0 ,
115
100
clues(version, version.out.text(), version.err.text(), version.exitCode)
116
101
)
117
102
val expectedLauncherVersion =
118
- if (binaryName == " scala " ) " Scala code runner version:"
103
+ if (binaryName.isSip ) " Scala code runner version:"
119
104
else " Scala CLI version:"
120
105
expect(version.out.text().contains(expectedLauncherVersion))
121
106
expect(version.out.text().contains(s " Scala version (default): ${Constants .defaultScala}" ))
122
107
}
123
108
}
124
109
125
- def checkHelp (binaryName : String ): Unit = TestInputs .empty.fromRoot { root =>
126
- val cliPath = os.Path (TestUtil .cliPath, os.pwd)
127
- val ext = if (Properties .isWin) " .exe" else " "
128
- val newCliPath = root / s " $binaryName$ext"
129
- os.copy(cliPath, newCliPath)
130
-
110
+ def testHelpOutput (binaryName : String ): Unit = TestInputs .empty.fromRoot { root =>
111
+ val binary = binaryName.prepareBinary(root)
131
112
for { helpOption <- Seq (" help" , " -help" , " --help" ) } {
132
- val res = os.proc(newCliPath , helpOption).call(cwd = root)
113
+ val res = os.proc(binary , helpOption).call(cwd = root)
133
114
val restrictedFeaturesMentioned = res.out.trim().contains(" package" )
134
- if (binaryName == " scala " ) expect(! restrictedFeaturesMentioned)
115
+ if (binaryName.isSip ) expect(! restrictedFeaturesMentioned)
135
116
else expect(restrictedFeaturesMentioned)
136
117
}
137
118
}
138
119
139
- if (TestUtil .isNativeCli) {
140
- test(" version command print detailed info run as scala" ) {
141
- runVersionCommand(" scala" )
142
- }
143
-
144
- test(" version command print detailed info run as scala-cli" ) {
145
- runVersionCommand(" scala-cli" )
146
- }
147
-
148
- test(" help command mentions non-restricted features only when run as scala" ) {
149
- checkHelp(" scala" )
150
- }
151
-
152
- test(" help command mentions all core features when run as scala" ) {
153
- checkHelp(" scala-cli" )
120
+ if (TestUtil .isNativeCli)
121
+ for (binaryName <- Seq (" scala" , " scala-cli" , " scala-cli-sip" )) {
122
+ test(s " test directories command when run as $binaryName" ) {
123
+ testDirectoriesCommand(binaryName)
124
+ }
125
+ test(s " test publish directives when run as $binaryName" ) {
126
+ testPublishDirectives(binaryName)
127
+ }
128
+ test(s " test markdown options when run as $binaryName" ) {
129
+ testMarkdownOptions(binaryName)
130
+ }
131
+ test(s " test version command when run as $binaryName" ) {
132
+ testVersionCommand(binaryName)
133
+ }
134
+ test(s " test help when run as $binaryName" ) {
135
+ testHelpOutput(binaryName)
136
+ }
154
137
}
155
- }
156
138
}
0 commit comments