File tree Expand file tree Collapse file tree 3 files changed +70
-4
lines changed
tests/src/test/scala/org/scalanative/bindgen
tools/src/main/scala/org/scalanative/bindgen Expand file tree Collapse file tree 3 files changed +70
-4
lines changed Original file line number Diff line number Diff line change 1+ package org .scalanative .bindgen
2+
3+ import java .io .{File , PrintWriter }
4+
5+ import org .scalatest .FunSpec
6+
7+ class BindgenReportingSpec extends FunSpec {
8+ describe(" Bindgen" ) {
9+
10+ val bindgenPath = System .getProperty(" bindgen.path" )
11+
12+ def writeToFile (file : File , input : String ): Unit = {
13+ new PrintWriter (file) {
14+ try {
15+ write(input)
16+ } finally {
17+ close()
18+ }
19+ }
20+ }
21+
22+ def bindgen (input : String ): Bindings = {
23+ val tempFile = File .createTempFile(" scala-native-bindgen-tests" , " .h" )
24+ try {
25+ writeToFile(tempFile, input)
26+
27+ Bindgen ()
28+ .bindgenExecutable(new File (bindgenPath))
29+ .header(tempFile)
30+ .name(" BindgenTests" )
31+ .link(" bindgentests" )
32+ .packageName(" org.scalanative.bindgen.samples" )
33+ .excludePrefix(" __" )
34+ .generate()
35+
36+ } finally {
37+ tempFile.delete()
38+ }
39+ }
40+
41+ it(" Skips functions that pass struct or union by value" ) {
42+ val bindings =
43+ bindgen(input = """ struct s { int a; };
44+ |void useStruct(struct s);
45+ |typedef struct s s;
46+ |s returnStruct();
47+ |
48+ |union u { int a; };
49+ |void useUnion(union u);
50+ |typedef union u u;
51+ |u returnUnion();
52+ |""" .stripMargin)
53+ assert(
54+ bindings.errs ==
55+ """ Warning: Function useStruct is skipped because Scala Native does not support passing structs and arrays by value.
56+ |Warning: Function returnStruct is skipped because Scala Native does not support passing structs and arrays by value.
57+ |Warning: Function useUnion is skipped because Scala Native does not support passing structs and arrays by value.
58+ |Warning: Function returnUnion is skipped because Scala Native does not support passing structs and arrays by value.""" .stripMargin
59+ )
60+ }
61+ }
62+ }
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ package org.scalanative.bindgen
33import java .io .File
44
55import scala .collection .immutable .Seq
6- import scala .sys .process .Process
6+ import scala .sys .process .{ Process , ProcessLogger }
77
88sealed trait Bindgen {
99
@@ -129,9 +129,13 @@ object Bindgen {
129129 withArgs(" --extra-arg-before" , extraArgBefore) ++
130130 Seq (header.get.getAbsolutePath, " --" )
131131
132- val output = Process (cmd). !!
132+ var errs = Seq [ String ]()
133133
134- new Bindings (output)
134+ val output = Process (cmd).!! (ProcessLogger { err : String =>
135+ errs :+= err
136+ })
137+
138+ new Bindings (output, errs.mkString(" \n " ))
135139 }
136140 }
137141}
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ package org.scalanative.bindgen
22
33import java .io .{File , PrintWriter }
44
5- class Bindings (private val bindings : String ) {
5+ class Bindings (private val bindings : String , val errs : String ) {
66 def writeToFile (file : File ): Unit = {
77 file.getParentFile.mkdirs()
88 new PrintWriter (file) {
You can’t perform that action at this time.
0 commit comments