Skip to content

Commit 1432172

Browse files
Fix interpreter mistreating complex executable names (#15)
* Allow process interpreter to extract arguments from executable "names" * Add test for exxecutable "names" containing arguments
1 parent 358d3f1 commit 1432172

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/it/scala/smtlib/it/ProcessInterpreterTests.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ class ProcessInterpreterTests extends AnyFunSuite with TestHelpers {
1818
//TODO: properly get all interpreters
1919
def interpreters: Seq[Interpreter] = Seq(getZ3Interpreter)
2020

21+
test("Interpreter can be created with complex executable names") {
22+
// sometimes we are given arguments in the executable name itself;
23+
// check that these are split and processed correctly
24+
val z3Interpreter = new Z3Interpreter("z3 -in", Array("-smt2")) {}
25+
z3Interpreter.eval(trees.Commands.SetLogic(trees.Commands.AUFLIA()))
26+
z3Interpreter.eval(trees.Commands.CheckSat())
27+
z3Interpreter.interrupt()
28+
}
29+
2130
test("Interrupt after free does not throw an exception") {
2231
//TODO: check against all interpreters
2332
val z3Interpreter = getZ3Interpreter

src/main/scala/smtlib/interpreters/ProcessInterpreter.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,13 @@ object ProcessInterpreter {
130130
private def ctorHelper(executable: String,
131131
args: Array[String],
132132
parserCtor: BufferedReader => Parser): (Parser, Process, BufferedWriter, BufferedReader, BufferedReader) = {
133-
val process = java.lang.Runtime.getRuntime.exec(executable +: args)
133+
val (executableName, implicitArgs) = if (executable.contains(" ")) {
134+
val parts = executable.split(" ")
135+
(parts(0), parts.drop(1))
136+
} else {
137+
(executable, Array.empty[String])
138+
}
139+
val process = java.lang.Runtime.getRuntime.exec(executableName +: (implicitArgs ++ args))
134140
val in = new BufferedWriter(new OutputStreamWriter(process.getOutputStream))
135141
val out = new BufferedReader(new InputStreamReader(process.getInputStream))
136142
val err = new BufferedReader(new InputStreamReader(process.getErrorStream))

0 commit comments

Comments
 (0)