-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ff5491e
commit 0048a24
Showing
3 changed files
with
137 additions
and
78 deletions.
There are no files selected for viewing
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
83 changes: 83 additions & 0 deletions
83
tests/src/test/scala/org/scalanative/bindgen/BindgenReportingSpec.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,83 @@ | ||
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 variable with opaque type") { | ||
val bindings = | ||
bindgen(input = """struct undefinedStruct; | ||
|extern struct undefinedStruct removedExtern; | ||
|#define removedExternAlias removedExtern | ||
|""".stripMargin) | ||
assert( | ||
bindings.errs == """Error: Variable removedExtern is skipped because it has incomplete type. | ||
|Error: Variable alias removedExternAlias is skipped because it has incomplete type.""".stripMargin) | ||
|
||
} | ||
|
||
it("Skips function that has parameter of opaque type") { | ||
val bindings = | ||
bindgen(input = """struct undefinedStruct; | ||
|void useUndefinedStruct(struct undefinedStruct); | ||
|""".stripMargin) | ||
assert( | ||
bindings.errs == "Warning: Function useUndefinedStruct is skipped because Scala Native does not " + | ||
"support passing structs and arrays by value.") | ||
} | ||
|
||
it("Skips function that has return value of opaque type") { | ||
val bindings = | ||
bindgen(input = """struct undefinedStruct; | ||
|typedef struct undefinedStruct aliasForUndefinedStruct; | ||
|aliasForUndefinedStruct returnUndefinedStruct(); | ||
|""".stripMargin) | ||
assert( | ||
bindings.errs == "Warning: Function returnUndefinedStruct is skipped because Scala Native does not " + | ||
"support passing structs and arrays by value.") | ||
} | ||
|
||
it("Skips unused alias for opaque type") { | ||
val bindings = | ||
bindgen(input = """union undefinedUnion; | ||
|typedef union undefinedUnion aliasForUndefinedUnion; | ||
|""".stripMargin) | ||
assert( | ||
bindings.errs == "Warning: type alias aliasForUndefinedUnion is skipped because it is unused alias for incomplete type.") | ||
} | ||
} | ||
} |
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