From a2ccebe27554d196fbcadf4fd230fb1b4b14090a Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Thu, 30 Apr 2020 19:32:01 +0430 Subject: working on the test script --- cgrep.cpp | 24 ++------------------- compile_commands.json | 8 +++---- makefile | 13 +++++++----- testscript/main.py | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 71 insertions(+), 32 deletions(-) diff --git a/cgrep.cpp b/cgrep.cpp index 0a0888c..15ee524 100644 --- a/cgrep.cpp +++ b/cgrep.cpp @@ -7,27 +7,7 @@ * */ /***********************************************************************************************/ /*included modules*/ -#include "./cfe-extra/cfe_extra.h" -#include "clang/AST/AST.h" -#include "clang/AST/ASTConsumer.h" -#include "clang/ASTMatchers/ASTMatchFinder.h" -#include "clang/ASTMatchers/ASTMatchers.h" -#include "clang/Basic/LLVM.h" -#include "clang/Frontend/CompilerInstance.h" -#include "clang/Frontend/FrontendActions.h" -#include "clang/Lex/Lexer.h" -#include "clang/Rewrite/Core/Rewriter.h" -#include "clang/Tooling/CommonOptionsParser.h" -#include "clang/Tooling/Tooling.h" -#include "llvm/Support/raw_ostream.h" -#include -#include -#include -#include -#include -#include -#include -#include +#include "pch.hpp" /***********************************************************************************************/ /*used namespaces*/ using namespace llvm; @@ -209,7 +189,7 @@ static std::string get_line_from_file(SourceManager &SM, */ std::string regex_preprocessor(const std::string &rx_str) { std::string ret_rx_str; - return ret_rx_str; + return rx_str; } bool regex_handler(std::string rx_str, std::string identifier_name) { diff --git a/compile_commands.json b/compile_commands.json index 598f647..86af499 100644 --- a/compile_commands.json +++ b/compile_commands.json @@ -1,12 +1,12 @@ [ { - "command": "c++ -c -fpic -I/home/bloodstalker/extra/llvm-clang-4/llvm/include -I/home/bloodstalker/extra/llvm-clang-4/build/include -std=c++14 -fno-exceptions -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/bloodstalker/extra/llvm-clang-4/llvm/tools/clang/include -I/home/bloodstalker/extra/llvm-clang-4/build/tools/clang/include -std=c++17 -fexceptions -o cgrep.o cgrep.cpp", + "command": "c++ -c -fpic -I/home/bloodstalker/extra/llvm-clang-4/llvm/include -I/home/bloodstalker/extra/llvm-clang-4/build/include -std=c++14 -fno-exceptions -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/bloodstalker/extra/llvm-clang-4/llvm/tools/clang/include -I/home/bloodstalker/extra/llvm-clang-4/build/tools/clang/include -std=c++17 -fexceptions -o cfe-extra/cfe_extra.o cfe-extra/cfe_extra.cpp", "directory": "/home/bloodstalker/extra/cgrep", - "file": "/home/bloodstalker/extra/cgrep/cgrep.cpp" + "file": "/home/bloodstalker/extra/cgrep/cfe-extra/cfe_extra.cpp" }, { - "command": "c++ -c -fpic -I/home/bloodstalker/extra/llvm-clang-4/llvm/include -I/home/bloodstalker/extra/llvm-clang-4/build/include -std=c++14 -fno-exceptions -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/bloodstalker/extra/llvm-clang-4/llvm/tools/clang/include -I/home/bloodstalker/extra/llvm-clang-4/build/tools/clang/include -std=c++17 -fexceptions -o cfe-extra/cfe_extra.o cfe-extra/cfe_extra.cpp", + "command": "c++ -c -include-pch pch.hpp.gch -fpic -I/home/bloodstalker/extra/llvm-clang-4/llvm/include -I/home/bloodstalker/extra/llvm-clang-4/build/include -std=c++14 -fno-exceptions -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/bloodstalker/extra/llvm-clang-4/llvm/tools/clang/include -I/home/bloodstalker/extra/llvm-clang-4/build/tools/clang/include -std=c++17 -fexceptions -o cgrep.o cgrep.cpp", "directory": "/home/bloodstalker/extra/cgrep", - "file": "/home/bloodstalker/extra/cgrep/cfe-extra/cfe_extra.cpp" + "file": "/home/bloodstalker/extra/cgrep/cgrep.cpp" } ] \ No newline at end of file diff --git a/makefile b/makefile index 94fd556..e5f241a 100644 --- a/makefile +++ b/makefile @@ -18,7 +18,7 @@ endif CXX_EXTRA?= CTAGS_I_PATH?=./ #LD_FLAGS= -lstdc++fs -LD_FLAGS= +LD_FLAGS= -lboost_system -lboost_filesystem EXTRA_LD_FLAGS?= ADD_SANITIZERS_CC= -g -fsanitize=address -fno-omit-frame-pointer ADD_SANITIZERS_LD= -g -fsanitize=address @@ -84,7 +84,7 @@ LD_FLAGS+=$(EXTRA_LD_FLAGS) .PHONY:all clean help ASM SO TAGS -all: $(TARGET) +all: pch.hpp.gch $(TARGET) everything:$(TARGET) A ASM SO $(TARGET)-dbg TAGS $(TARGET)-cov @@ -98,15 +98,18 @@ depend:.depend -include ./.depend -%.o:%.cpp - $(CXX) $(CXX_FLAGS) -c $< -o $@ +%.o:%.cpp pch.hpp.gch + $(CXX) -include-pch pch.hpp.gch $(CXX_FLAGS) -c $< -o $@ %.odbg:%.cpp $(CXX) $(CXX_FLAGS) -g -c $< -o $@ -%.ocov:%.cpp +%.ocov:%.cpp pch.hpp.gch $(CXX) $(CXX_FLAGS) $(COV_CXX) -c $< -o $@ +pch.hpp.gch: pch.hpp + $(CXX) $(CXX_FLAGS) -c $< -o $@ + ./cfe-extra/cfe_extra.o:./cfe-extra/cfe_extra.cpp $(CXX) $(CXX_FLAGS) -c $< -o $@ diff --git a/testscript/main.py b/testscript/main.py index 013ab99..fddc3a3 100755 --- a/testscript/main.py +++ b/testscript/main.py @@ -1,4 +1,4 @@ -#!/usr/bin/python3 +#!/usr/bin/env python3 # _*_ coding=utf-8 _*_ import argparse @@ -6,6 +6,24 @@ import subprocess import os import sys +test_files = ["/home/bloodstalker/extra/cgrep/cgrep.cpp"] + +cgrep_test_args = [ + "-A 1 -B 1 --func --var --regex n[aA]m", + "-A 1 -B 1 --func --var --awk --regex n[aA]m", + "-A 1 -B 1 --func --declrefexpr --regex n[aA]m --nocolor", + "-A 1 -B 1 --func --declrefexpr --memfunc --call --cxxcall --var --regex run", + "-A 1 -B 1 --macro --header --regex n[aA]m", + "-A 1 -B 1 --class --regex and", + "-A 1 -B 1 --struct --union --regex n[aA]m", + "-A 1 -B 1 --nameddecl --regex n[aA]m", + "-A 1 -B 1 --cxxcall --call --regex add", + "-A 1 -B 1 --cfield --regex ite", + "--union --regex [Uu]nion ./test/main.cpp", + "--struct --regex [sS]truct ./test/main.cpp", + "--dir ./ --regex run --func",] + + class Argparser(object): def __init__(self): parser = argparse.ArgumentParser() @@ -13,8 +31,46 @@ class Argparser(object): parser.add_argument("--bool", action="store_true", help="bool", default=False) self.args = parser.parse_args() + +def call_from_shell(command, *command_args): + command_list = [arg for arg in command_args] + command_list.insert(0, command) + if sys.version_info < (3, 7): + return subprocess.run(command_list, stdout=subprocess.PIPE) + else: + return subprocess.run(command_list, capture_output=True) + + +def call_from_shell_list(command_list): + if sys.version_info < (3, 7): + return subprocess.run(command_list, stdout=subprocess.PIPE) + else: + return subprocess.run(command_list, capture_output=True) + + +def call_from_shell_pprint(command, *command_args): + print(call_from_shell(command, *command_args).stdout.decode("utf-8")) + + +def call_from_shell_list_pprint(command_list): + print(call_from_list_shell(command_list).stdout.decode("utf-8")) + + def main(): argparser = Argparser() + cgrep_exe = "cgrep" + os.chdir("../") + print(os.getcwd()) + for cgrep_test_arg in cgrep_test_args: + arg_list = cgrep_test_arg.split() + arg_list.insert(0, cgrep_exe) + arg_list.append(test_files[0]) + print(arg_list) + ret = call_from_shell_list(arg_list) + #print("ret:", ret.returncode) + print("ret:", ret.stdout.decode("utf-8"), end="") + print("ret:", ret.stderr.decode("utf-8"), end="") + if __name__ == "__main__": main() -- cgit v1.2.3