-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Report error if scala script not exists (#538)
- Loading branch information
Showing
4 changed files
with
51 additions
and
15 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
modules/build/src/main/scala/scala/build/preprocessing/PreprocessingUtil.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package scala.build.preprocessing | ||
|
||
import java.nio.charset.StandardCharsets | ||
|
||
import scala.build.errors.{BuildException, FileNotFoundException} | ||
|
||
object PreprocessingUtil { | ||
|
||
private def defaultCharSet = StandardCharsets.UTF_8 | ||
|
||
def maybeRead(f: os.Path): Either[BuildException, String] = | ||
if (os.isFile(f)) Right(os.read(f, defaultCharSet)) | ||
else Left(new FileNotFoundException(f)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
modules/build/src/test/scala/scala/build/tests/PreprocessingTests.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package scala.build.tests | ||
|
||
import scala.build.Inputs | ||
import scala.build.preprocessing.{ScalaPreprocessor, ScriptPreprocessor} | ||
import com.eed3si9n.expecty.Expecty.{expect, assert => expect} | ||
|
||
import scala.build.internal.CustomCodeWrapper | ||
|
||
class PreprocessingTests extends munit.FunSuite { | ||
|
||
test("Report error if scala file not exists") { | ||
val logger = TestLogger() | ||
val scalaFile = Inputs.ScalaFile(os.temp.dir(), os.SubPath("NotExists.scala")) | ||
|
||
val res = ScalaPreprocessor.preprocess(scalaFile, logger) | ||
val expectedMessage = s"File not found: ${scalaFile.path}" | ||
|
||
assert(res.nonEmpty) | ||
assert(res.get.isLeft) | ||
expect(res.get.left.get.message == expectedMessage) | ||
} | ||
|
||
test("Report error if scala script not exists") { | ||
val logger = TestLogger() | ||
val scalaScript = Inputs.Script(os.temp.dir(), os.SubPath("NotExists.sc")) | ||
|
||
val res = ScriptPreprocessor(CustomCodeWrapper).preprocess(scalaScript, logger) | ||
val expectedMessage = s"File not found: ${scalaScript.path}" | ||
|
||
assert(res.nonEmpty) | ||
assert(res.get.isLeft) | ||
expect(res.get.left.get.message == expectedMessage) | ||
} | ||
} |