Skip to content

Commit d56596b

Browse files
committed
simplify normalizeNewlines verified with git core.autocrlf=true; fix for 3769
1 parent 2f55c0a commit d56596b

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

modules/build/src/main/scala/scala/build/internal/AmmUtil.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ object AmmUtil {
2121
def encodeScalaSourcePath(path: Seq[Name]) = path.map(_.backticked).mkString(".")
2222

2323
def normalizeNewlines(s: String)(using newLine: String = lineSeparator): String =
24-
s.replace("\r", "").replace("\n", newLine)
24+
s.replace("\r", "")
2525

26-
lazy val lineSeparator: String =
27-
if EnvVar.Misc.shell.valueOpt.nonEmpty then "\n" else System.lineSeparator()
26+
lazy val lineSeparator: String = "\n"
2827
}

modules/build/src/test/scala/scala/build/tests/ActionableDiagnosticTests.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class ActionableDiagnosticTests extends TestUtil.ScalaCliBuildSuite {
2323
)
2424
val buildThreads = BuildThreads.create()
2525

26+
def path2url(p: os.Path): String = p.toIO.toURI.toURL.toString
27+
2628
test("using outdated os-lib") {
2729
val dependencyOsLib = "com.lihaoyi::os-lib:0.7.8"
2830
val testInputs = TestInputs(
@@ -160,7 +162,7 @@ class ActionableDiagnosticTests extends TestUtil.ScalaCliBuildSuite {
160162
)
161163
val withRepoBuildOptions = baseOptions.copy(
162164
classPathOptions =
163-
baseOptions.classPathOptions.copy(extraRepositories = Seq(s"file:${repoTmpDir.toString}"))
165+
baseOptions.classPathOptions.copy(extraRepositories = Seq(path2url(repoTmpDir)))
164166
)
165167
testInputs.withBuild(withRepoBuildOptions, buildThreads, None, actionableDiagnostics = true) {
166168
(_, _, maybeBuild) =>
@@ -222,7 +224,7 @@ class ActionableDiagnosticTests extends TestUtil.ScalaCliBuildSuite {
222224
val withRepoBuildOptions = baseOptions.copy(
223225
classPathOptions =
224226
baseOptions.classPathOptions.copy(extraRepositories =
225-
Seq(s"file:${repoTmpDir.toString.replace('\\', '/')}")
227+
Seq(path2url(repoTmpDir))
226228
)
227229
)
228230
testInputs.withBuild(withRepoBuildOptions, buildThreads, None, actionableDiagnostics = true) {

modules/build/src/test/scala/scala/build/tests/markdown/MarkdownCodeWrapperTests.scala

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,28 +166,34 @@ class MarkdownCodeWrapperTests extends TestUtil.ScalaCliBuildSuite {
166166
expect(result == (None, None, Some(expectedScala)))
167167
}
168168

169+
def stringPrep(s: String): String = AmmUtil.normalizeNewlines(s)
170+
169171
test("multiple test Scala snippets are glued together correctly") {
170-
val snippet1 =
172+
val snippet1 = stringPrep(
171173
"""//> using dep org.scalameta::munit:0.7.29
172174
|class Test1 extends munit.FunSuite {
173175
| assert(true)
174176
|}""".stripMargin
177+
)
175178
val codeBlock1 = MarkdownCodeBlock(TestScalaInfo, snippet1, 3, 6)
176-
val snippet2 =
179+
val snippet2 = stringPrep(
177180
"""class Test2 extends munit.FunSuite {
178181
| assert(true)
179182
|}""".stripMargin
183+
)
180184
val codeBlock2 = MarkdownCodeBlock(TestScalaInfo, snippet2, 8, 10)
181185
val preprocessedCodeBlocks = PreprocessedMarkdownCodeBlocks(Seq(codeBlock1, codeBlock2))
182186
val markdown = PreprocessedMarkdown(testCodeBlocks = preprocessedCodeBlocks)
183187
val expectedScala = MarkdownCodeWrapper.WrappedMarkdownCode(
184-
s"""
185-
|
186-
|
187-
|$snippet1
188-
|
189-
|$snippet2
190-
|""".stripMargin
188+
stringPrep(
189+
s"""
190+
|
191+
|
192+
|$snippet1
193+
|
194+
|$snippet2
195+
|""".stripMargin
196+
)
191197
)
192198
val result = MarkdownCodeWrapper(os.sub / "Example.md", markdown)
193199
showDiffs(result, expectedScala.code)
@@ -208,6 +214,7 @@ class MarkdownCodeWrapperTests extends TestUtil.ScalaCliBuildSuite {
208214
s.code
209215
case _ =>
210216
result.toString
217+
211218
}
212219
if actual.toString != expect.toString then
213220
for (((a, b), i) <- (actual zip expect).zipWithIndex)

0 commit comments

Comments
 (0)