From b78d6f623a7002d68d592e2ab06481223267622c Mon Sep 17 00:00:00 2001 From: Andrzej Kotulski Date: Mon, 5 Oct 2015 08:50:16 -0700 Subject: [PATCH] Split methods.cpp test into multiple ones MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: @​public 1. Factor out some of the common code for comparing C++ dot files 2. Create new directory with smaller .cpp files to translate Reviewed By: @dulmarod Differential Revision: D2507757 --- .../frontend/methods/default_parameters.cpp | 21 ++++ .../methods/default_parameters.cpp.dot | 32 +++++ .../cpp/frontend/methods/inline_method.cpp | 23 ++++ .../frontend/methods/inline_method.cpp.dot | 43 +++++++ .../cpp/frontend/methods/overloading.cpp | 28 +++++ .../cpp/frontend/methods/overloading.cpp.dot | 39 +++++++ .../cpp/frontend/types/methods.cpp | 69 ----------- .../cpp/frontend/types/methods.dot | 109 ------------------ infer/tests/frontend/cpp/MethodsTest.java | 46 ++++---- infer/tests/utils/ClangFrontendUtils.java | 41 +++++++ 10 files changed, 250 insertions(+), 201 deletions(-) create mode 100644 infer/tests/codetoanalyze/cpp/frontend/methods/default_parameters.cpp create mode 100644 infer/tests/codetoanalyze/cpp/frontend/methods/default_parameters.cpp.dot create mode 100644 infer/tests/codetoanalyze/cpp/frontend/methods/inline_method.cpp create mode 100644 infer/tests/codetoanalyze/cpp/frontend/methods/inline_method.cpp.dot create mode 100644 infer/tests/codetoanalyze/cpp/frontend/methods/overloading.cpp create mode 100644 infer/tests/codetoanalyze/cpp/frontend/methods/overloading.cpp.dot delete mode 100644 infer/tests/codetoanalyze/cpp/frontend/types/methods.cpp delete mode 100644 infer/tests/codetoanalyze/cpp/frontend/types/methods.dot create mode 100644 infer/tests/utils/ClangFrontendUtils.java diff --git a/infer/tests/codetoanalyze/cpp/frontend/methods/default_parameters.cpp b/infer/tests/codetoanalyze/cpp/frontend/methods/default_parameters.cpp new file mode 100644 index 000000000..d82ab96be --- /dev/null +++ b/infer/tests/codetoanalyze/cpp/frontend/methods/default_parameters.cpp @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2015 - present Facebook, Inc. +* All rights reserved. +* +* This source code is licensed under the BSD style license found in the +* LICENSE file in the root directory of this source tree. An additional grant +* of patent rights can be found in the PATENTS file in the same directory. +*/ + +class A { + public: + // default parameters + int fun_default(int a, int b = 10, int c = 20) {return a+b+c;} +}; + +void call_method_with_default_parameters() { + A *a_ptr; + a_ptr->fun_default(1,2,3); + a_ptr->fun_default(1,2); + a_ptr->fun_default(1); +} diff --git a/infer/tests/codetoanalyze/cpp/frontend/methods/default_parameters.cpp.dot b/infer/tests/codetoanalyze/cpp/frontend/methods/default_parameters.cpp.dot new file mode 100644 index 000000000..c44c8a155 --- /dev/null +++ b/infer/tests/codetoanalyze/cpp/frontend/methods/default_parameters.cpp.dot @@ -0,0 +1,32 @@ +digraph iCFG { +8 [label="8: Call _fun_A_fun_default \n n$4=*&a_ptr:class A * [line 18]\n n$5=_fun_A_fun_default(n$4:class A ,1:int ,2:int ,3:int ) [line 18]\n REMOVE_TEMPS(n$4,n$5); [line 18]\n " shape="box"] + + + 8 -> 7 ; +7 [label="7: Call _fun_A_fun_default \n n$2=*&a_ptr:class A * [line 19]\n n$3=_fun_A_fun_default(n$2:class A ,1:int ,2:int ,20:int ) [line 19]\n REMOVE_TEMPS(n$2,n$3); [line 19]\n " shape="box"] + + + 7 -> 6 ; +6 [label="6: Call _fun_A_fun_default \n n$0=*&a_ptr:class A * [line 20]\n n$1=_fun_A_fun_default(n$0:class A ,1:int ,10:int ,20:int ) [line 20]\n REMOVE_TEMPS(n$0,n$1); [line 20]\n NULLIFY(&a_ptr,false); [line 20]\n APPLY_ABSTRACTION; [line 20]\n " shape="box"] + + + 6 -> 5 ; +5 [label="5: Exit call_method_with_default_parameters \n " color=yellow style=filled] + + +4 [label="4: Start call_method_with_default_parameters\nFormals: \nLocals: a_ptr:class A * \n DECLARE_LOCALS(&return,&a_ptr); [line 16]\n " color=yellow style=filled] + + + 4 -> 8 ; +3 [label="3: Return Stmt \n n$0=*&a:int [line 13]\n n$1=*&b:int [line 13]\n n$2=*&c:int [line 13]\n *&return:int =((n$0 + n$1) + n$2) [line 13]\n REMOVE_TEMPS(n$0,n$1,n$2); [line 13]\n NULLIFY(&a,false); [line 13]\n NULLIFY(&b,false); [line 13]\n NULLIFY(&c,false); [line 13]\n APPLY_ABSTRACTION; [line 13]\n " shape="box"] + + + 3 -> 2 ; +2 [label="2: Exit A_fun_default \n " color=yellow style=filled] + + +1 [label="1: Start A_fun_default\nFormals: this:class A a:int b:int c:int \nLocals: \n DECLARE_LOCALS(&return); [line 13]\n NULLIFY(&this,false); [line 13]\n " color=yellow style=filled] + + + 1 -> 3 ; +} diff --git a/infer/tests/codetoanalyze/cpp/frontend/methods/inline_method.cpp b/infer/tests/codetoanalyze/cpp/frontend/methods/inline_method.cpp new file mode 100644 index 000000000..98e5e5f81 --- /dev/null +++ b/infer/tests/codetoanalyze/cpp/frontend/methods/inline_method.cpp @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2015 - present Facebook, Inc. +* All rights reserved. +* +* This source code is licensed under the BSD style license found in the +* LICENSE file in the root directory of this source tree. An additional grant +* of patent rights can be found in the PATENTS file in the same directory. +*/ + +class A { + struct AIn { + int fun() { return 1;} + }; + AIn *in; + // inline definition + int fun() { int c = 10; return c+1;} +}; + +void test_call() { + A *a_ptr; + a_ptr->fun(); + a_ptr->in->fun(); +} diff --git a/infer/tests/codetoanalyze/cpp/frontend/methods/inline_method.cpp.dot b/infer/tests/codetoanalyze/cpp/frontend/methods/inline_method.cpp.dot new file mode 100644 index 000000000..bb919a8fd --- /dev/null +++ b/infer/tests/codetoanalyze/cpp/frontend/methods/inline_method.cpp.dot @@ -0,0 +1,43 @@ +digraph iCFG { +11 [label="11: Call _fun_A_fun \n n$3=*&a_ptr:class A * [line 21]\n n$4=_fun_A_fun(n$3:class A ) [line 21]\n REMOVE_TEMPS(n$3,n$4); [line 21]\n " shape="box"] + + + 11 -> 10 ; +10 [label="10: Call _fun_A::AIn_fun \n n$0=*&a_ptr:class A * [line 22]\n n$1=*n$0.in:class A::AIn * [line 22]\n n$2=_fun_A::AIn_fun(n$1:class A::AIn ) [line 22]\n REMOVE_TEMPS(n$0,n$1,n$2); [line 22]\n NULLIFY(&a_ptr,false); [line 22]\n APPLY_ABSTRACTION; [line 22]\n " shape="box"] + + + 10 -> 9 ; +9 [label="9: Exit test_call \n " color=yellow style=filled] + + +8 [label="8: Start test_call\nFormals: \nLocals: a_ptr:class A * \n DECLARE_LOCALS(&return,&a_ptr); [line 19]\n " color=yellow style=filled] + + + 8 -> 11 ; +7 [label="7: DeclStmt \n *&c:int =10 [line 16]\n " shape="box"] + + + 7 -> 6 ; +6 [label="6: Return Stmt \n n$0=*&c:int [line 16]\n *&return:int =(n$0 + 1) [line 16]\n REMOVE_TEMPS(n$0); [line 16]\n NULLIFY(&c,false); [line 16]\n APPLY_ABSTRACTION; [line 16]\n " shape="box"] + + + 6 -> 5 ; +5 [label="5: Exit A_fun \n " color=yellow style=filled] + + +4 [label="4: Start A_fun\nFormals: this:class A \nLocals: c:int \n DECLARE_LOCALS(&return,&c); [line 16]\n NULLIFY(&c,false); [line 16]\n NULLIFY(&this,false); [line 16]\n " color=yellow style=filled] + + + 4 -> 7 ; +3 [label="3: Return Stmt \n *&return:int =1 [line 12]\n APPLY_ABSTRACTION; [line 12]\n " shape="box"] + + + 3 -> 2 ; +2 [label="2: Exit A::AIn_fun \n " color=yellow style=filled] + + +1 [label="1: Start A::AIn_fun\nFormals: this:class A::AIn \nLocals: \n DECLARE_LOCALS(&return); [line 12]\n NULLIFY(&this,false); [line 12]\n " color=yellow style=filled] + + + 1 -> 3 ; +} diff --git a/infer/tests/codetoanalyze/cpp/frontend/methods/overloading.cpp b/infer/tests/codetoanalyze/cpp/frontend/methods/overloading.cpp new file mode 100644 index 000000000..8851fa5eb --- /dev/null +++ b/infer/tests/codetoanalyze/cpp/frontend/methods/overloading.cpp @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2015 - present Facebook, Inc. +* All rights reserved. +* +* This source code is licensed under the BSD style license found in the +* LICENSE file in the root directory of this source tree. An additional grant +* of patent rights can be found in the PATENTS file in the same directory. +*/ + +class A { + int fun(int a, int b); + int fun(int a, int b, int c); +}; + +int A::fun(int a, int b, int c) { + return a + b + c; +} + +int A::fun(int a, int b) { + return a - b; +} + +void test() { + A *a_ptr; + // calling methods + a_ptr->fun(1,2); + a_ptr->fun(1,2,3); +} diff --git a/infer/tests/codetoanalyze/cpp/frontend/methods/overloading.cpp.dot b/infer/tests/codetoanalyze/cpp/frontend/methods/overloading.cpp.dot new file mode 100644 index 000000000..05bc80340 --- /dev/null +++ b/infer/tests/codetoanalyze/cpp/frontend/methods/overloading.cpp.dot @@ -0,0 +1,39 @@ +digraph iCFG { +10 [label="10: Call _fun_A_fun \n n$2=*&a_ptr:class A * [line 26]\n n$3=_fun_A_fun(n$2:class A ,1:int ,2:int ) [line 26]\n REMOVE_TEMPS(n$2,n$3); [line 26]\n " shape="box"] + + + 10 -> 9 ; +9 [label="9: Call _fun_A_fun \n n$0=*&a_ptr:class A * [line 27]\n n$1=_fun_A_fun(n$0:class A ,1:int ,2:int ,3:int ) [line 27]\n REMOVE_TEMPS(n$0,n$1); [line 27]\n NULLIFY(&a_ptr,false); [line 27]\n APPLY_ABSTRACTION; [line 27]\n " shape="box"] + + + 9 -> 8 ; +8 [label="8: Exit test \n " color=yellow style=filled] + + +7 [label="7: Start test\nFormals: \nLocals: a_ptr:class A * \n DECLARE_LOCALS(&return,&a_ptr); [line 23]\n " color=yellow style=filled] + + + 7 -> 10 ; +6 [label="6: Return Stmt \n n$0=*&a:int [line 20]\n n$1=*&b:int [line 20]\n *&return:int =(n$0 - n$1) [line 20]\n REMOVE_TEMPS(n$0,n$1); [line 20]\n NULLIFY(&a,false); [line 20]\n NULLIFY(&b,false); [line 20]\n APPLY_ABSTRACTION; [line 20]\n " shape="box"] + + + 6 -> 5 ; +5 [label="5: Exit A_fun \n " color=yellow style=filled] + + +4 [label="4: Start A_fun\nFormals: this:class A a:int b:int \nLocals: \n DECLARE_LOCALS(&return); [line 19]\n NULLIFY(&this,false); [line 19]\n " color=yellow style=filled] + + + 4 -> 6 ; +3 [label="3: Return Stmt \n n$0=*&a:int [line 16]\n n$1=*&b:int [line 16]\n n$2=*&c:int [line 16]\n *&return:int =((n$0 + n$1) + n$2) [line 16]\n REMOVE_TEMPS(n$0,n$1,n$2); [line 16]\n NULLIFY(&a,false); [line 16]\n NULLIFY(&b,false); [line 16]\n NULLIFY(&c,false); [line 16]\n APPLY_ABSTRACTION; [line 16]\n " shape="box"] + + + 3 -> 2 ; +2 [label="2: Exit A_fun \n " color=yellow style=filled] + + +1 [label="1: Start A_fun\nFormals: this:class A a:int b:int c:int \nLocals: \n DECLARE_LOCALS(&return); [line 15]\n NULLIFY(&this,false); [line 15]\n " color=yellow style=filled] + + + 1 -> 3 ; +} diff --git a/infer/tests/codetoanalyze/cpp/frontend/types/methods.cpp b/infer/tests/codetoanalyze/cpp/frontend/types/methods.cpp deleted file mode 100644 index 6045f7d8c..000000000 --- a/infer/tests/codetoanalyze/cpp/frontend/types/methods.cpp +++ /dev/null @@ -1,69 +0,0 @@ -// commented out parts are not done yet -struct A { - public: - int member1; - float member2; - public: - int fun(int a, int b); - // overloading - int fun(int a, int b, int c); - int add(const A& other); - - struct AIn { - int fun1() { return 1;} - int fun(int a, int b); - }; - // inline definition - int def_in() { int c = 10; return c+1;} - - // default parameters - int fun_default(int a, int b = 10, int c = 20) {return a+b+c;} - //static function - //static int get_fun() {return 1;} -}; - -int A::fun(int a, int b, int c) { - //using class members - //fun(a,b); -} - -int A::fun(int a, int b) { - int c = a + b + 1; - //using class members - //member1 = c; - return c*c; -} - -int A::AIn::fun(int a, int b) { - return a+b; -} - -int A::add(const A& other) { - //member1 += other.member1; - //return member1; -} - -void call_method() { - // constructing objects - //A a; - //a.fun(1,2); - - A *a_ptr; - // calling methods - a_ptr->fun(10,20); - a_ptr->fun_default(1,2,3); -} - -void call_method_with_default_parameters() { - A *a_ptr; - a_ptr->fun_default(1,2); - a_ptr->fun_default(1); -} - -/* -void call_static_method { - A *a_ptr; - A::get_fun(); - a_ptr->get_fun(); -} -*/ diff --git a/infer/tests/codetoanalyze/cpp/frontend/types/methods.dot b/infer/tests/codetoanalyze/cpp/frontend/types/methods.dot deleted file mode 100644 index d94032fc3..000000000 --- a/infer/tests/codetoanalyze/cpp/frontend/types/methods.dot +++ /dev/null @@ -1,109 +0,0 @@ -digraph iCFG { -29 [label="29: Call _fun_A_fun_default \n n$2=*&a_ptr:class A * [line 59]\n n$3=_fun_A_fun_default(n$2:class A ,1:int ,2:int ,20:int ) [line 59]\n REMOVE_TEMPS(n$2,n$3); [line 59]\n " shape="box"] - - - 29 -> 28 ; -28 [label="28: Call _fun_A_fun_default \n n$0=*&a_ptr:class A * [line 60]\n n$1=_fun_A_fun_default(n$0:class A ,1:int ,10:int ,20:int ) [line 60]\n REMOVE_TEMPS(n$0,n$1); [line 60]\n NULLIFY(&a_ptr,false); [line 60]\n APPLY_ABSTRACTION; [line 60]\n " shape="box"] - - - 28 -> 27 ; -27 [label="27: Exit call_method_with_default_parameters \n " color=yellow style=filled] - - -26 [label="26: Start call_method_with_default_parameters\nFormals: \nLocals: a_ptr:class A * \n DECLARE_LOCALS(&return,&a_ptr); [line 57]\n " color=yellow style=filled] - - - 26 -> 29 ; -25 [label="25: Call _fun_A_fun \n n$2=*&a_ptr:class A * [line 53]\n n$3=_fun_A_fun(n$2:class A ,10:int ,20:int ) [line 53]\n REMOVE_TEMPS(n$2,n$3); [line 53]\n " shape="box"] - - - 25 -> 24 ; -24 [label="24: Call _fun_A_fun_default \n n$0=*&a_ptr:class A * [line 54]\n n$1=_fun_A_fun_default(n$0:class A ,1:int ,2:int ,3:int ) [line 54]\n REMOVE_TEMPS(n$0,n$1); [line 54]\n NULLIFY(&a_ptr,false); [line 54]\n APPLY_ABSTRACTION; [line 54]\n " shape="box"] - - - 24 -> 23 ; -23 [label="23: Exit call_method \n " color=yellow style=filled] - - -22 [label="22: Start call_method\nFormals: \nLocals: a_ptr:class A * \n DECLARE_LOCALS(&return,&a_ptr); [line 46]\n " color=yellow style=filled] - - - 22 -> 25 ; -21 [label="21: Exit A_add \n " color=yellow style=filled] - - -20 [label="20: Start A_add\nFormals: this:class A other:class A &\nLocals: \n DECLARE_LOCALS(&return); [line 41]\n NULLIFY(&other,false); [line 41]\n NULLIFY(&this,false); [line 41]\n " color=yellow style=filled] - - - 20 -> 21 ; -19 [label="19: Return Stmt \n n$0=*&a:int [line 38]\n n$1=*&b:int [line 38]\n *&return:int =(n$0 + n$1) [line 38]\n REMOVE_TEMPS(n$0,n$1); [line 38]\n NULLIFY(&a,false); [line 38]\n NULLIFY(&b,false); [line 38]\n APPLY_ABSTRACTION; [line 38]\n " shape="box"] - - - 19 -> 18 ; -18 [label="18: Exit A::AIn_fun \n " color=yellow style=filled] - - -17 [label="17: Start A::AIn_fun\nFormals: this:class A::AIn a:int b:int \nLocals: \n DECLARE_LOCALS(&return); [line 37]\n NULLIFY(&this,false); [line 37]\n " color=yellow style=filled] - - - 17 -> 19 ; -16 [label="16: DeclStmt \n n$2=*&a:int [line 31]\n n$3=*&b:int [line 31]\n *&c:int =((n$2 + n$3) + 1) [line 31]\n REMOVE_TEMPS(n$2,n$3); [line 31]\n NULLIFY(&a,false); [line 31]\n NULLIFY(&b,false); [line 31]\n " shape="box"] - - - 16 -> 15 ; -15 [label="15: Return Stmt \n n$0=*&c:int [line 34]\n n$1=*&c:int [line 34]\n *&return:int =(n$0 * n$1) [line 34]\n REMOVE_TEMPS(n$0,n$1); [line 34]\n NULLIFY(&c,false); [line 34]\n APPLY_ABSTRACTION; [line 34]\n " shape="box"] - - - 15 -> 14 ; -14 [label="14: Exit A_fun \n " color=yellow style=filled] - - -13 [label="13: Start A_fun\nFormals: this:class A a:int b:int \nLocals: c:int \n DECLARE_LOCALS(&return,&c); [line 30]\n NULLIFY(&c,false); [line 30]\n NULLIFY(&this,false); [line 30]\n " color=yellow style=filled] - - - 13 -> 16 ; -12 [label="12: Exit A_fun \n " color=yellow style=filled] - - -11 [label="11: Start A_fun\nFormals: this:class A a:int b:int c:int \nLocals: \n DECLARE_LOCALS(&return); [line 25]\n NULLIFY(&a,false); [line 25]\n NULLIFY(&b,false); [line 25]\n NULLIFY(&c,false); [line 25]\n NULLIFY(&this,false); [line 25]\n " color=yellow style=filled] - - - 11 -> 12 ; -10 [label="10: Return Stmt \n n$0=*&a:int [line 20]\n n$1=*&b:int [line 20]\n n$2=*&c:int [line 20]\n *&return:int =((n$0 + n$1) + n$2) [line 20]\n REMOVE_TEMPS(n$0,n$1,n$2); [line 20]\n NULLIFY(&a,false); [line 20]\n NULLIFY(&b,false); [line 20]\n NULLIFY(&c,false); [line 20]\n APPLY_ABSTRACTION; [line 20]\n " shape="box"] - - - 10 -> 9 ; -9 [label="9: Exit A_fun_default \n " color=yellow style=filled] - - -8 [label="8: Start A_fun_default\nFormals: this:class A a:int b:int c:int \nLocals: \n DECLARE_LOCALS(&return); [line 20]\n NULLIFY(&this,false); [line 20]\n " color=yellow style=filled] - - - 8 -> 10 ; -7 [label="7: DeclStmt \n *&c:int =10 [line 17]\n " shape="box"] - - - 7 -> 6 ; -6 [label="6: Return Stmt \n n$0=*&c:int [line 17]\n *&return:int =(n$0 + 1) [line 17]\n REMOVE_TEMPS(n$0); [line 17]\n NULLIFY(&c,false); [line 17]\n APPLY_ABSTRACTION; [line 17]\n " shape="box"] - - - 6 -> 5 ; -5 [label="5: Exit A_def_in \n " color=yellow style=filled] - - -4 [label="4: Start A_def_in\nFormals: this:class A \nLocals: c:int \n DECLARE_LOCALS(&return,&c); [line 17]\n NULLIFY(&c,false); [line 17]\n NULLIFY(&this,false); [line 17]\n " color=yellow style=filled] - - - 4 -> 7 ; -3 [label="3: Return Stmt \n *&return:int =1 [line 13]\n APPLY_ABSTRACTION; [line 13]\n " shape="box"] - - - 3 -> 2 ; -2 [label="2: Exit A::AIn_fun1 \n " color=yellow style=filled] - - -1 [label="1: Start A::AIn_fun1\nFormals: this:class A::AIn \nLocals: \n DECLARE_LOCALS(&return); [line 13]\n NULLIFY(&this,false); [line 13]\n " color=yellow style=filled] - - - 1 -> 3 ; -} diff --git a/infer/tests/frontend/cpp/MethodsTest.java b/infer/tests/frontend/cpp/MethodsTest.java index 9f955c5a1..eab82b7ae 100644 --- a/infer/tests/frontend/cpp/MethodsTest.java +++ b/infer/tests/frontend/cpp/MethodsTest.java @@ -9,43 +9,43 @@ package frontend.cpp; -import static org.hamcrest.MatcherAssert.assertThat; -import static utils.matchers.DotFilesEqual.dotFileEqualTo; - -import com.google.common.collect.ImmutableList; - import org.junit.Rule; import org.junit.Test; -import java.io.File; import java.io.IOException; import utils.DebuggableTemporaryFolder; import utils.InferException; -import utils.InferRunner; +import utils.ClangFrontendUtils; public class MethodsTest { + String methodBasePath = "infer/tests/codetoanalyze/cpp/frontend/methods/"; + @Rule public DebuggableTemporaryFolder folder = new DebuggableTemporaryFolder(); + void frontendTest(String fileRelative) throws InterruptedException, IOException, InferException { + ClangFrontendUtils.createAndCompareCppDotFiles(folder, methodBasePath + fileRelative); + } + @Test - public void whenCaptureRunCommaThenDotFilesAreTheSame() + public void testInlineMethodDotFilesMatch() throws InterruptedException, IOException, InferException { - String literal_src = - "infer/tests/codetoanalyze/cpp/frontend/types/methods.cpp"; - - String literal_dotty = - "infer/tests/codetoanalyze/cpp/frontend/types/methods.dot"; - - ImmutableList inferCmd = - InferRunner.createCPPInferCommandFrontend( - folder, - literal_src); - File newDotFile = InferRunner.runInferFrontend(inferCmd); - assertThat( - "In the capture of " + literal_src + - " the dotty files should be the same.", - newDotFile, dotFileEqualTo(literal_dotty)); + frontendTest("inline_method.cpp"); } + + @Test + public void testDefaultParametersDotFilesMatch() + throws InterruptedException, IOException, InferException { + frontendTest("default_parameters.cpp"); + } + + @Test + public void testOverloadingDotFilesMatch() + throws InterruptedException, IOException, InferException { + frontendTest("overloading.cpp"); + } + + } diff --git a/infer/tests/utils/ClangFrontendUtils.java b/infer/tests/utils/ClangFrontendUtils.java new file mode 100644 index 000000000..74ce3ca81 --- /dev/null +++ b/infer/tests/utils/ClangFrontendUtils.java @@ -0,0 +1,41 @@ +/* +* Copyright (c) 2015 - present Facebook, Inc. +* All rights reserved. +* +* This source code is licensed under the BSD style license found in the +* LICENSE file in the root directory of this source tree. An additional grant +* of patent rights can be found in the PATENTS file in the same directory. +*/ + +package utils; + +import static org.hamcrest.MatcherAssert.assertThat; +import static utils.matchers.DotFilesEqual.dotFileEqualTo; + +import com.google.common.collect.ImmutableList; + +import java.io.File; +import java.io.IOException; + +import utils.DebuggableTemporaryFolder; +import utils.InferException; +import utils.InferRunner; + +public class ClangFrontendUtils { + public static void createAndCompareCppDotFiles(DebuggableTemporaryFolder folder, String pathToSrcFile) + throws InterruptedException, IOException, InferException { + + String test_src = pathToSrcFile; + String test_dotty = pathToSrcFile + ".dot"; + ImmutableList inferCmd = + InferRunner.createCPPInferCommandFrontend( + folder, + test_src); + File newDotFile = InferRunner.runInferFrontend(inferCmd); + assertThat( + "In the capture of " + test_src + + " the dotty files should be the same.", + newDotFile, dotFileEqualTo(test_dotty)); + } + +}