@Test public void testRequireNodeModules() throws Exception { URL fileUrl = getClass().getClassLoader().getResource("NodejsRequireTargetSelectorResolve/requireNodeModules/index.js"); File file = new File(fileUrl.toURI()); PropagationCallGraphBuilder builder = NodejsCallGraphBuilderUtil.makeCGBuilder(file); CallGraph CG = builder.makeCallGraph(builder.getOptions()); String cgString = CG.toString(); assertTrue(cgString.contains("Lnode_modules_lib_node_modules_sublib_sublib/nodejsModule/moduleSource")); assertTrue(!cgString.contains("?")); }
@Test public void testRequireStaticCircular() throws Exception { URL fileUrl = getClass().getClassLoader().getResource("NodejsRequireTargetSelectorResolve/requireStaticCircular/index.js"); File file = new File(fileUrl.toURI()); PropagationCallGraphBuilder builder = NodejsCallGraphBuilderUtil.makeCGBuilder(file); CallGraph CG = builder.makeCallGraph(builder.getOptions()); String cgString = CG.toString(); assertTrue(cgString.contains("Llib1/nodejsModule/moduleSource/lib1>")); assertTrue(cgString.contains("Llib2/nodejsModule/moduleSource/lib2>")); assertTrue(!cgString.contains("?")); }
@Test public void testRequireDynamic() throws Exception { URL fileUrl = getClass().getClassLoader().getResource("NodejsRequireTargetSelectorResolve/requireDynamic/index.js"); File file = new File(fileUrl.toURI()); PropagationCallGraphBuilder builder = NodejsCallGraphBuilderUtil.makeCGBuilder(file); CallGraph CG = builder.makeCallGraph(builder.getOptions()); String cgString = CG.toString(); assertTrue(cgString.contains("Llib1/nodejsModule/moduleSource/lib1>")); assertTrue(cgString.contains("Llib2/nodejsModule/moduleSource/lib2>")); assertTrue(!cgString.contains("?")); }
@Test public void testRequireSimple() throws Exception { URL fileUrl = getClass().getClassLoader().getResource("NodejsRequireTargetSelectorResolve/requireSimple/index.js"); File file = new File(fileUrl.toURI()); PropagationCallGraphBuilder builder = NodejsCallGraphBuilderUtil.makeCGBuilder(file); CallGraph CG = builder.makeCallGraph(builder.getOptions()); String cgString = CG.toString(); assertTrue(cgString.contains("Lmod/nodejsModule/moduleSource/exec>")); assertTrue(cgString.contains("Lmod/nodejsModule/moduleSource/SomeClass/hello>")); assertTrue(!cgString.contains("?")); }
@Test public void testRequireCoreModules() throws Exception { URL fileUrl = getClass().getClassLoader().getResource("NodejsRequireTargetSelectorResolve/requireCoreModules.js"); File file = new File(fileUrl.toURI()); PropagationCallGraphBuilder builder = NodejsCallGraphBuilderUtil.makeCGBuilder(file); CallGraph CG = builder.makeCallGraph(builder.getOptions()); String cgString = CG.toString(); assertTrue(cgString.contains("Lutil/nodejsModule/moduleSource/util")); assertTrue(cgString.contains("Lhttps/nodejsModule/moduleSource/https")); assertTrue(cgString.contains("Lhttp/nodejsModule/moduleSource/http")); }
public static CallGraph makeHTMLCG(URL url, CGBuilderType builderType, Supplier<JSSourceExtractor> fExtractor) throws IllegalArgumentException, CancelException, WalaException { PropagationCallGraphBuilder b = makeHTMLCGBuilder(url, builderType, fExtractor); CallGraph CG = b.makeCallGraph(b.getOptions()); return CG; }
public static CallGraph makeScriptCG(String dir, String name, CGBuilderType builderType, ClassLoader loader) throws IOException, IllegalArgumentException, CancelException, WalaException { PropagationCallGraphBuilder b = makeScriptCGBuilder(dir, name, builderType, loader); CallGraph CG = b.makeCallGraph(b.getOptions()); // dumpCG(b.getPointerAnalysis(), CG); return CG; }
@Test public void test() throws Exception { URL fileUrl = getClass().getClassLoader().getResource("NodejsRequireJsonTest/index.js"); File file = new File(fileUrl.toURI()); PropagationCallGraphBuilder builder = NodejsCallGraphBuilderUtil.makeCGBuilder(file); CallGraph CG = builder.makeCallGraph(builder.getOptions()); String cgString = CG.toString(); assertTrue(cgString.contains("Lempty/jsonModule>")); assertTrue(cgString.contains("Lnested/jsonModule>")); assertTrue(cgString.contains("Lpackage/jsonModule>")); assertTrue(!cgString.contains("?")); } }
public static CallGraph makeScriptCG(SourceModule[] scripts, CGBuilderType builderType, IRFactory<IMethod> irFactory) throws IllegalArgumentException, CancelException, WalaException { CAstRewriterFactory<?, ?> preprocessor = builderType.extractCorrelatedPairs ? new CorrelatedPairExtractorFactory(translatorFactory, scripts) : null; PropagationCallGraphBuilder b = makeCGBuilder(makeLoaders(preprocessor), scripts, builderType, irFactory); CallGraph CG = b.makeCallGraph(b.getOptions()); // dumpCG(b.getPointerAnalysis(), CG); return CG; }
@Test public void testNested() throws IOException, IllegalArgumentException, CancelException, WalaException { PropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "nested.js"); CallGraph CG = B.makeCallGraph(B.getOptions()); verifyGraphAssertions(CG, assertionsForNested); }
@Test public void testDateAsProperty() throws IllegalArgumentException, IOException, CancelException, WalaException { PropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "date-property.js"); CallGraph CG = B.makeCallGraph(B.getOptions()); //JSCallGraphUtil.AVOID_DUMP = false; //JSCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG); verifyGraphAssertions(CG, assertionsForDateProperty); } private static final Object[][] assertionsForDeadCode = new Object[][] {
@Test public void testDispatchSameTarget() throws IOException, IllegalArgumentException, CancelException, WalaException { PropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "dispatch_same_target.js"); CallGraph CG = B.makeCallGraph(B.getOptions()); // JSCallGraphUtil.AVOID_DUMP = false; // JSCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG); verifyGraphAssertions(CG, assertionsForDispatchSameTarget); }
@Test public void testTry() throws IOException, IllegalArgumentException, CancelException, WalaException { PropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "try.js"); CallGraph CG = B.makeCallGraph(B.getOptions()); /* boolean x = CAstCallGraphUtil.AVOID_DUMP; CAstCallGraphUtil.AVOID_DUMP = false; CAstCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG); CAstCallGraphUtil.AVOID_DUMP = x; */ verifyGraphAssertions(CG, assertionsForTry); }
@Test public void testDeadCode() throws IllegalArgumentException, IOException, CancelException, WalaException { PropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "dead.js"); CallGraph CG = B.makeCallGraph(B.getOptions()); //JSCallGraphUtil.AVOID_DUMP = false; //JSCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG); verifyGraphAssertions(CG, assertionsForDeadCode); }
@Test public void testRenaming() throws IOException, WalaException, IllegalArgumentException, CancelException { PropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "rename-example.js"); CallGraph CG = B.makeCallGraph(B.getOptions()); verifyNameAssertions(CG, renamingAssertions); }
@Test public void testInstanceof() throws IOException, IllegalArgumentException, CancelException, WalaException { PropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "instanceof.js"); CallGraph CG = B.makeCallGraph(B.getOptions()); verifyGraphAssertions(CG, assertionsForInstanceof); }
@Test public void testArrayIndexConv() throws IllegalArgumentException, IOException, CancelException, WalaException { PropagationCallGraphBuilder b = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "array_index_conv.js"); CallGraph cg = b.makeCallGraph(b.getOptions()); verifyGraphAssertions(cg, assertionsForArrayIndexConv); }
@Test(expected = WalaException.class) public void testParseError() throws IllegalArgumentException, IOException, CancelException, WalaException { PropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "portal-example-simple.html"); B.makeCallGraph(B.getOptions()); com.ibm.wala.cast.util.Util.checkForFrontEndErrors(B.getClassHierarchy()); }
@Test public void testStringOp() throws IOException, IllegalArgumentException, CancelException, WalaException { PropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "string-op.js"); B.getOptions().setTraceStringConstants(true); CallGraph CG = B.makeCallGraph(B.getOptions()); verifyGraphAssertions(CG, assertionsForStringOp); }
@Test public void testArrayIndexConv2() throws IllegalArgumentException, IOException, CancelException, WalaException { PropagationCallGraphBuilder b = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "array_index_conv2.js"); b.setContextSelector(new PropertyNameContextSelector(b.getAnalysisCache(), b.getContextSelector())); CallGraph cg = b.makeCallGraph(b.getOptions()); //JSCallGraphUtil.AVOID_DUMP = false; //JSCallGraphUtil.dumpCG(b.getPointerAnalysis(), cg); verifyGraphAssertions(cg, assertionsForArrayIndexConv2); }