Skip to content

Commit cdea7b1

Browse files
committed
Add test for boolean options and imrove formatting
1 parent 36e8efc commit cdea7b1

File tree

5 files changed

+39
-11
lines changed

5 files changed

+39
-11
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,3 @@ Since options are dependent on the used version of scala-native-cli, please use
1414
## Logging
1515

1616
For logging purposes, a default Scala Native logger is used. By default it will only show `Error` messages, but its verbosity can be increased with a -v flag.
17-
18-

cli/src/test/scala/scala/scalanative/cli/ConfigConverterTest.scala

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ConfigConverterTest extends AnyFlatSpec {
2020
val dummyMiscOptions = MiscOptions()
2121

2222
val dummyArguments =
23-
Seq("$Main", "A.nir", "B.nir")
23+
Seq("Main$", "A.nir", "B.nir")
2424

2525
val dummyCliOptions = CliOptions(
2626
config = dummyConfigOptions,
@@ -34,7 +34,6 @@ class ConfigConverterTest extends AnyFlatSpec {
3434
assert(config.isRight)
3535
}
3636

37-
// TODO incomplete arguments check reporting
3837
it should "report incomplete arguments" in {
3938
val noArgs = Seq()
4039
val noArgsResult = ConfigConverter.convert(dummyCliOptions, noArgs)
@@ -52,7 +51,7 @@ class ConfigConverterTest extends AnyFlatSpec {
5251
"/home/dir/file",
5352
"/home/dirfile2",
5453
"/home/dir/with spaces/"
55-
) // check case app passing with spaces
54+
)
5655
val expected = Seq(
5756
Paths.get("/home/dir/file"),
5857
Paths.get("/home/dirfile2"),
@@ -147,4 +146,35 @@ class ConfigConverterTest extends AnyFlatSpec {
147146
assert(nativeConfig.config.compilerConfig.clang == expectedClangPath)
148147
assert(nativeConfig.config.compilerConfig.clangPP == expectedClangPPPath)
149148
}
149+
150+
it should "parse boolean options as opposite of default" in {
151+
val options = CliOptions(
152+
dummyConfigOptions,
153+
NativeConfigOptions(
154+
check = true,
155+
dump = true,
156+
noOptimize = true,
157+
linkStubs = true
158+
),
159+
dummyLoggerOptions,
160+
dummyMiscOptions
161+
)
162+
val default = ConfigConverter
163+
.convert(dummyCliOptions, dummyArguments)
164+
.right
165+
.get
166+
.config
167+
.compilerConfig
168+
val nonDefault = ConfigConverter
169+
.convert(options, dummyArguments)
170+
.right
171+
.get
172+
.config
173+
.compilerConfig
174+
175+
assert(nonDefault.check != default.check)
176+
assert(nonDefault.dump != default.dump)
177+
assert(nonDefault.optimize != default.optimize)
178+
assert(nonDefault.linkStubs != default.linkStubs)
179+
}
150180
}

cli/version_newer/src/main/scala/scala/scalanative/cli/utils/LinktimePropertyParser.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ object LinktimePropertyParser {
1919
ltpStrings
2020
.map { inputPattern =>
2121
val matcher = ltpPattern.matcher(inputPattern)
22-
if (!matcher.find() || matcher.groupCount() != 2 || matcher.group(1).isEmpty()) {
22+
if (
23+
!matcher
24+
.find() || matcher.groupCount() != 2 || matcher.group(1).isEmpty()
25+
) {
2326
Left(getLtpPatternException(inputPattern))
2427
} else {
2528
val (key, booleanString) = (matcher.group(1), matcher.group(2))

cli/version_newer/src/test/scala/scala/scalanative/cli/LinktimePropertyParserTest.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ class LinktimePropertyParserTest extends AnyFlatSpec {
77

88
"LinktimePropertyParser" should "handle boolean value types correctly" in {
99
val input = List("isTesting=true", "isNotTesting=False")
10-
val expected = Map[String, Any]("isTesting" -> true, "isNotTesting" -> false)
10+
val expected =
11+
Map[String, Any]("isTesting" -> true, "isNotTesting" -> false)
1112
val obtained = LinktimePropertyParser.toMap(input)
1213
assert(obtained.right.get == expected)
1314
}

scala-native-cli-integration-test-runner/src/test/run/integration-test/test

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,3 @@ $ mkdir native-dir
2929
> runCli --outpath target/out6 -v -v --workdir native-dir --dump Main$
3030
$ exists native-dir/optimized.hnir
3131
$ exists target/out6
32-
33-
# -- Fail on an incorrect link-time property
34-
> runCli --outpath target/out7 -v -v --ltp key=ok Main$
35-
-$ exists target/out7

0 commit comments

Comments
 (0)