Skip to content

Commit

Permalink
Unit test instead of integration tests
Browse files Browse the repository at this point in the history
Adding clib classpath to nscplugin in test scope
I couldn't find a way to reproduce the compiler crash without using
clib
  • Loading branch information
tanishiking committed Jan 29, 2024
1 parent c0a1341 commit 1a3dbcc
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,23 @@ class NIRCompilerTest3 {
|""".stripMargin
)

@Test def opaqueTypes(): Unit = nativeCompilation(
"""
|import scalanative.libc.stdio
|import scalanative.unsafe.*
|import scalanative.unsigned.*
|
|opaque type cmark_event_type = CUnsignedInt
|object cmark_event_type:
| inline def define(inline a: Long): cmark_event_type = a.toUInt
| val CMARK_EVENT_NONE = define(0)
|
|@main def hello(): Unit =
| val evtype = cmark_event_type.CMARK_EVENT_NONE
| stdio.printf(c"bla: %s, hello: %d", evtype)
|""".stripMargin
)

@Test def inlineExternFunction(): Unit = {
val err = assertThrows(
classOf[CompilationFailedException],
Expand Down
10 changes: 7 additions & 3 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ object Build {
.mapBinaryVersions(_ => _.dependsOn(testingCompilerInterface % "test"))
.dependsOnSource(nirJVM)
.dependsOnSource(utilJVM)
.zippedSettings(Seq("testingCompiler", "nativelib")) {
case Seq(testingCompiler, nativelib) =>
.zippedSettings(Seq("testingCompiler", "nativelib", "clib")) {
case Seq(testingCompiler, nativelib, clib) =>
Test / javaOptions ++= {
val nscCompilerJar =
(Compile / Keys.`package`).value.getAbsolutePath()
Expand All @@ -159,10 +159,14 @@ object Build {
val nativelibCp = (nativelib / Compile / fullClasspath).value.files
.map(_.getAbsolutePath)
.mkString(pathSeparator)
val clibCp = (clib / Compile / fullClasspath).value.files
.map(_.getAbsolutePath)
.mkString(pathSeparator)
Seq(
"-Dscalanative.nscplugin.jar=" + nscCompilerJar,
"-Dscalanative.testingcompiler.cp=" + testingCompilerCp,
"-Dscalanative.nativeruntime.cp=" + nativelibCp
"-Dscalanative.nativeruntime.cp=" + nativelibCp,
"-Dscalanative.clib.cp=" + clibCp
)
}
}
Expand Down
11 changes: 0 additions & 11 deletions scripted-tests/scala3/opaque-type/build.sbt

This file was deleted.

9 changes: 0 additions & 9 deletions scripted-tests/scala3/opaque-type/project/scala-native.sbt

This file was deleted.

13 changes: 0 additions & 13 deletions scripted-tests/scala3/opaque-type/src/main/scala/Hello.scala

This file was deleted.

1 change: 0 additions & 1 deletion scripted-tests/scala3/opaque-type/test

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ class NIRCompiler(outputDir: Path) extends api.NIRCompiler {
private case object ScalaNative
extends CompilerPlugin(
jarPath = sys props "scalanative.nscplugin.jar",
classpath = List(sys props "scalanative.nativeruntime.cp")
classpath = List(
sys.props("scalanative.nativeruntime.cp"),
sys.props("scalanative.clib.cp")
)
)

/** Returns an instance of `Global` configured according to the given options.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ class NIRCompiler(outputDir: Path) extends api.NIRCompiler {
private def compile(sources: Seq[SourceFile]): Seq[Path] = {
val outPath = outputDir.toAbsolutePath
val jarPath = sys.props("scalanative.nscplugin.jar")
val classpath = List(sys.props("scalanative.nativeruntime.cp"))
val classpath = List(
sys.props("scalanative.nativeruntime.cp"),
sys.props("scalanative.clib.cp")
)
.filterNot(_.isEmpty)
.mkString("-cp ", File.pathSeparator, "")

Expand Down

0 comments on commit 1a3dbcc

Please sign in to comment.