Skip to content

Commit 55107f1

Browse files
committed
NIT Refactor SipScalaTests
- fix confusing 'restricted mode' naming in favor of `power mode` - misc fixes
1 parent 2862c21 commit 55107f1

File tree

1 file changed

+30
-27
lines changed

1 file changed

+30
-27
lines changed

modules/integration/src/test/scala/scala/cli/integration/SipScalaTests.scala

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ class SipScalaTests extends ScalaCliSuite {
1616
newCliPath
1717
}
1818
}
19-
def powerArgs(isRestricted: Boolean) = if (isRestricted) Nil else Seq("--power")
19+
def powerArgs(isPowerMode: Boolean): Seq[String] = if (isPowerMode) Seq("--power") else Nil
2020

21-
def testDirectoriesCommand(isRestricted: Boolean): Unit =
21+
def testDirectoriesCommand(isPowerMode: Boolean): Unit =
2222
TestInputs.empty.fromRoot { root =>
23-
val res = os.proc(TestUtil.cli, powerArgs(isRestricted), "directories").call(
23+
val res = os.proc(TestUtil.cli, powerArgs(isPowerMode), "directories").call(
2424
cwd = root,
2525
check = false,
2626
mergeErrIntoOut = true
2727
)
28-
if (isRestricted) {
28+
if (!isPowerMode) {
2929
expect(res.exitCode == 1)
3030
val output = res.out.text()
3131
expect(output.contains(
@@ -35,7 +35,7 @@ class SipScalaTests extends ScalaCliSuite {
3535
else expect(res.exitCode == 0)
3636
}
3737

38-
def testPublishDirectives(isRestricted: Boolean): Unit = TestInputs.empty.fromRoot { root =>
38+
def testPublishDirectives(isPowerMode: Boolean): Unit = TestInputs.empty.fromRoot { root =>
3939
val code =
4040
"""
4141
| //> using publish.name "my-library"
@@ -45,13 +45,13 @@ class SipScalaTests extends ScalaCliSuite {
4545
val source = root / "A.scala"
4646
os.write(source, code)
4747

48-
val res = os.proc(TestUtil.cli, powerArgs(isRestricted), "compile", source).call(
48+
val res = os.proc(TestUtil.cli, powerArgs(isPowerMode), "compile", source).call(
4949
cwd = root,
5050
check = false,
5151
mergeErrIntoOut = true
5252
)
5353

54-
if (isRestricted) {
54+
if (!isPowerMode) {
5555
expect(res.exitCode == 1)
5656
val output = res.out.text()
5757
expect(output.contains(s"directive is experimental"))
@@ -60,7 +60,7 @@ class SipScalaTests extends ScalaCliSuite {
6060
expect(res.exitCode == 0)
6161
}
6262

63-
def testMarkdownOptions(isRestricted: Boolean): Unit = TestInputs.empty.fromRoot { root =>
63+
def testMarkdownOptions(isPowerMode: Boolean): Unit = TestInputs.empty.fromRoot { root =>
6464
val code =
6565
"""
6666
| println("ala")
@@ -70,12 +70,12 @@ class SipScalaTests extends ScalaCliSuite {
7070
os.write(source, code)
7171

7272
val res =
73-
os.proc(TestUtil.cli, powerArgs(isRestricted), "--scala", "3", "--markdown", source).call(
73+
os.proc(TestUtil.cli, powerArgs(isPowerMode), "--scala", "3", "--markdown", source).call(
7474
cwd = root,
7575
check = false,
7676
mergeErrIntoOut = true
7777
)
78-
if (isRestricted) {
78+
if (!isPowerMode) {
7979
expect(res.exitCode == 1)
8080
val output = res.out.text()
8181
expect(output.contains(s"option is experimental"))
@@ -97,42 +97,45 @@ class SipScalaTests extends ScalaCliSuite {
9797
}
9898
}
9999

100-
def testDefaultHelpOutput(isRestricted: Boolean): Unit = TestInputs.empty.fromRoot { root =>
100+
def testDefaultHelpOutput(isPowerMode: Boolean): Unit = TestInputs.empty.fromRoot { root =>
101101
for (helpOptions <- HelpTests.variants) {
102102
val output =
103-
os.proc(TestUtil.cli, powerArgs(isRestricted), helpOptions).call(cwd = root).out.trim()
103+
os.proc(TestUtil.cli, powerArgs(isPowerMode), helpOptions).call(cwd = root).out.trim()
104104
val restrictedFeaturesMentioned = output.contains("package")
105-
if (isRestricted) expect(!restrictedFeaturesMentioned)
105+
if (!isPowerMode) expect(!restrictedFeaturesMentioned)
106106
else expect(restrictedFeaturesMentioned)
107107
}
108108
}
109109

110-
def testReplHelpOutput(isRestricted: Boolean): Unit = TestInputs.empty.fromRoot { root =>
110+
def testReplHelpOutput(isPowerMode: Boolean): Unit = TestInputs.empty.fromRoot { root =>
111111
val output =
112-
os.proc(TestUtil.cli, powerArgs(isRestricted), "repl", "--help-full").call(cwd =
112+
os.proc(TestUtil.cli, powerArgs(isPowerMode), "repl", "--help-full").call(cwd =
113113
root
114114
).out.trim()
115115
val restrictedFeaturesMentioned = output.contains("--amm")
116116
val experimentalFeaturesMentioned = output.contains("--python")
117-
if (isRestricted) expect(!restrictedFeaturesMentioned && !experimentalFeaturesMentioned)
117+
if (!isPowerMode) expect(!restrictedFeaturesMentioned && !experimentalFeaturesMentioned)
118118
else expect(restrictedFeaturesMentioned && experimentalFeaturesMentioned)
119119
}
120120

121-
for (isRestricted <- Seq(false, true)) {
122-
test(s"test directories command when restricted mode is enabled: $isRestricted") {
123-
testDirectoriesCommand(isRestricted)
121+
for {
122+
isPowerMode <- Seq(false, true)
123+
powerModeString = if (isPowerMode) "enabled" else "disabled"
124+
} {
125+
test(s"test directories command when power mode is $powerModeString") {
126+
testDirectoriesCommand(isPowerMode)
124127
}
125-
test(s"test publish directives when restricted mode is enabled: $isRestricted") {
126-
testPublishDirectives(isRestricted)
128+
test(s"test publish directives when power mode is $powerModeString") {
129+
testPublishDirectives(isPowerMode)
127130
}
128-
test(s"test markdown options when restricted mode is enabled: $isRestricted") {
129-
testMarkdownOptions(isRestricted)
131+
test(s"test markdown options when power mode is $powerModeString") {
132+
testMarkdownOptions(isPowerMode)
130133
}
131-
test(s"test default help when restricted mode is enabled: $isRestricted") {
132-
testDefaultHelpOutput(isRestricted)
134+
test(s"test default help when power mode is $powerModeString") {
135+
testDefaultHelpOutput(isPowerMode)
133136
}
134-
test(s"test repl help when restricted mode is enabled: $isRestricted") {
135-
testReplHelpOutput(isRestricted)
137+
test(s"test repl help when power mode is $powerModeString") {
138+
testReplHelpOutput(isPowerMode)
136139
}
137140
}
138141

0 commit comments

Comments
 (0)