Repository: joernio/joern
Pull request #701 (2021-11-09 18:52:39)

Use newc for script tests
We were still using fuzzyc for script tests. With this PR, we switch over to newc. Also fixes a minor bug in c2cpg: <operator>.minus was used where <operator>.subtract was required.


Patch:
diff --git a/joern-cli/build.sbt b/joern-cli/build.sbt
index ecd189499..4041b44af 100644
--- a/joern-cli/build.sbt
+++ b/joern-cli/build.sbt
@@ -3,7 +3,7 @@ name := "joern-cli"
 dependsOn(
   Projects.console,
   Projects.console % "test->test",
-  Projects.fuzzyc2cpg, // only needed for joern-parse - TODO MP consider to remove?
+  Projects.c2cpg,
   Projects.dataflowengineoss
 )
 
diff --git a/joern-cli/frontends/c2cpg/src/main/scala/io/joern/c2cpg/astcreation/AstForExpressionsCreator.scala b/joern-cli/frontends/c2cpg/src/main/scala/io/joern/c2cpg/astcreation/AstForExpressionsCreator.scala
index 370509cb7..f7e3593b8 100644
--- a/joern-cli/frontends/c2cpg/src/main/scala/io/joern/c2cpg/astcreation/AstForExpressionsCreator.scala
+++ b/joern-cli/frontends/c2cpg/src/main/scala/io/joern/c2cpg/astcreation/AstForExpressionsCreator.scala
@@ -18,7 +18,7 @@ trait AstForExpressionsCreator {
       case IASTBinaryExpression.op_divide           => Operators.division
       case IASTBinaryExpression.op_modulo           => Operators.modulo
       case IASTBinaryExpression.op_plus             => Operators.addition
-      case IASTBinaryExpression.op_minus            => Operators.minus
+      case IASTBinaryExpression.op_minus            => Operators.subtraction
       case IASTBinaryExpression.op_shiftLeft        => Operators.shiftLeft
       case IASTBinaryExpression.op_shiftRight       => Operators.arithmeticShiftRight
       case IASTBinaryExpression.op_lessThan         => Operators.lessThan
diff --git a/joern-cli/src/main/scala/io/joern/console/AmmoniteBridge.scala b/joern-cli/src/main/scala/io/joern/console/AmmoniteBridge.scala
index 667471531..48df71e52 100644
--- a/joern-cli/src/main/scala/io/joern/console/AmmoniteBridge.scala
+++ b/joern-cli/src/main/scala/io/joern/console/AmmoniteBridge.scala
@@ -1,7 +1,5 @@
 package io.joern.console
 
-import io.joern.console.{BridgeBase, JoernProduct}
-
 object AmmoniteBridge extends App with BridgeBase {
 
   runAmmonite(parseConfig(args), JoernProduct)
diff --git a/joern-cli/src/main/scala/io/joern/console/Predefined.scala b/joern-cli/src/main/scala/io/joern/console/Predefined.scala
index bc690d995..7be181ccc 100644
--- a/joern-cli/src/main/scala/io/joern/console/Predefined.scala
+++ b/joern-cli/src/main/scala/io/joern/console/Predefined.scala
@@ -1,7 +1,5 @@
 package io.joern.console
 
-import io.joern.console.{Help, Run}
-
 object Predefined {
 
   /* ammonite tab completion is partly broken for scala > 2.12.8


Test patch:
diff --git a/joern-cli/src/test/resources/testcode/const-ish/const-ish.c b/joern-cli/src/test/resources/testcode/const-ish/const-ish.cpp
similarity index 100%
rename from joern-cli/src/test/resources/testcode/const-ish/const-ish.c
rename to joern-cli/src/test/resources/testcode/const-ish/const-ish.cpp
diff --git a/joern-cli/src/test/scala/io/shiftleft/joern/AbstractJoernCliTest.scala b/joern-cli/src/test/scala/io/shiftleft/joern/AbstractJoernCliTest.scala
index 8412cc7c2..fd9f50442 100644
--- a/joern-cli/src/test/scala/io/shiftleft/joern/AbstractJoernCliTest.scala
+++ b/joern-cli/src/test/scala/io/shiftleft/joern/AbstractJoernCliTest.scala
@@ -1,8 +1,8 @@
 package io.joern
 
 import better.files.File
+import io.joern.c2cpg.C2Cpg
 import io.shiftleft.codepropertygraph.Cpg
-import io.joern.fuzzyc2cpg.FuzzyC2Cpg
 
 trait AbstractJoernCliTest {
 
@@ -13,15 +13,16 @@ trait AbstractJoernCliTest {
   private def loadTestCpg(file: File): (Cpg, String) = {
     val inputFilenames = Set(file.pathAsString)
     val tmpFile = File.newTemporaryFile("cpg", "bin")
-    val fuzzycOutFilename = tmpFile.pathAsString
+    val c2cpgOutFilename = tmpFile.pathAsString
     tmpFile.delete()
 
-    // Create a CPG using the C/C++ fuzzy parser
-    val fuzzyc2Cpg = new FuzzyC2Cpg()
-    fuzzyc2Cpg.runAndOutput(inputFilenames, Set(".c"), Some(fuzzycOutFilename)).close()
+    // Create a CPG using the C/C++ parser
+    val c2cpg = new C2Cpg()
+    val config = C2Cpg.Config(inputPaths = inputFilenames, outputPath = c2cpgOutFilename)
+    c2cpg.runAndOutput(config).close()
     // Link CPG fragments and enhance to create semantic CPG
-    val cpg = Cpg2Scpg.run(fuzzycOutFilename, dataFlow = true)
-    (cpg, fuzzycOutFilename)
+    val cpg = Cpg2Scpg.run(c2cpgOutFilename, dataFlow = true)
+    (cpg, c2cpgOutFilename)
   }
 
 }