Skip to content

Implement BindgenReportingSpec #129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package org.scalanative.bindgen

import java.io.{File, PrintWriter}

import org.scalatest.FunSpec

class BindgenReportingSpec extends FunSpec {
describe("Bindgen") {

val bindgenPath = System.getProperty("bindgen.path")

def writeToFile(file: File, input: String): Unit = {
new PrintWriter(file) {
try {
write(input)
} finally {
close()
}
}
}

def bindgen(input: String): Bindings = {
val tempFile = File.createTempFile("scala-native-bindgen-tests", ".h")
try {
writeToFile(tempFile, input)

Bindgen()
.bindgenExecutable(new File(bindgenPath))
.header(tempFile)
.name("BindgenTests")
.link("bindgentests")
.packageName("org.scalanative.bindgen.samples")
.excludePrefix("__")
.generate()

} finally {
tempFile.delete()
}
}

it("Skips functions that pass struct or union by value") {
val bindings =
bindgen(input = """struct s { int a; };
|void useStruct(struct s);
|typedef struct s s;
|s returnStruct();
|
|union u { int a; };
|void useUnion(union u);
|typedef union u u;
|u returnUnion();
|""".stripMargin)
assert(
bindings.errs ==
"""Warning: Function useStruct is skipped because Scala Native does not support passing structs and arrays by value.
|Warning: Function returnStruct is skipped because Scala Native does not support passing structs and arrays by value.
|Warning: Function useUnion is skipped because Scala Native does not support passing structs and arrays by value.
|Warning: Function returnUnion is skipped because Scala Native does not support passing structs and arrays by value.""".stripMargin
)
}
}
}
10 changes: 7 additions & 3 deletions tools/src/main/scala/org/scalanative/bindgen/Bindgen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package org.scalanative.bindgen
import java.io.File

import scala.collection.immutable.Seq
import scala.sys.process.Process
import scala.sys.process.{Process, ProcessLogger}

sealed trait Bindgen {

Expand Down Expand Up @@ -129,9 +129,13 @@ object Bindgen {
withArgs("--extra-arg-before", extraArgBefore) ++
Seq(header.get.getAbsolutePath, "--")

val output = Process(cmd).!!
var errs = Seq[String]()

new Bindings(output)
val output = Process(cmd).!!(ProcessLogger { err: String =>
errs :+= err
})

new Bindings(output, errs.mkString("\n"))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.scalanative.bindgen

import java.io.{File, PrintWriter}

class Bindings(private val bindings: String) {
class Bindings(private val bindings: String, val errs: String) {
def writeToFile(file: File): Unit = {
file.getParentFile.mkdirs()
new PrintWriter(file) {
Expand Down