Arkanjo 0.1
A tool for find code duplicated functions in codebases
Loading...
Searching...
No Matches
test.cpp
Go to the documentation of this file.
1#include <iostream>
2#include <string>
3#include <vector>
4#include <algorithm>
5#include <filesystem>
9
10using namespace std;
11
12const string EXPECTED_DIR = "tests/e2e/expected";
13const string CURRENT_DIR = "tests/e2e/current";
14const string CODEBASE_DIR = "tests/e2e/codebase";
15
16vector<string> skip_check_list = {"/tmp/config.txt","/tmp/output_tool.txt","/tmp/output_parsed.txt"};
17
18bool should_skip(string s){
19 for(auto x : skip_check_list){
20 if(x == s){
21 return true;
22 }
23 }
24 return false;
25}
26
27bool areEqualFile(string file1, string file2){
28 vector<string> left = Utils::read_file_generic(file1);
29 vector<string> right = Utils::read_file_generic(file2);
30
31 if(left.size() != right.size()){
32 return false;
33 }
34
35 int sz = left.size();
36
37 for(int i = 0; i < sz; i++){
38 if(left[i] != right[i]){
39 return false;
40 }
41 }
42
43 return true;
44}
45
46string remove_prefix(string a, int rem){
47 reverse(a.begin(),a.end());
48 int cnt = rem;
49
50 while(cnt > 0 && !a.empty()){
51 a.pop_back();
52 cnt--;
53 }
54 reverse(a.begin(),a.end());
55 return a;
56}
57
58void Test(){
59 vector<string> expected_files;
60 vector<string> current_files;
61
62 for(const auto &dirEntry: std::filesystem::recursive_directory_iterator(EXPECTED_DIR)){
63 string file_path = dirEntry.path().string();
64 expected_files.push_back(file_path);
65 }
66 for(const auto &dirEntry: std::filesystem::recursive_directory_iterator(CURRENT_DIR)){
67 string file_path = dirEntry.path().string();
68 current_files.push_back(file_path);
69 }
70
71 sort(expected_files.begin(),expected_files.end());
72 sort(current_files.begin(),current_files.end());
73
74 int ite = min((int)expected_files.size(),(int)current_files.size());
75
76 for(int i = 0; i < ite; i++){
77 string expected_file = expected_files[i];
78 string current_file = current_files[i];
79
80 string expected_without_prefix = remove_prefix(expected_file,EXPECTED_DIR.size());
81 string current_without_prefix = remove_prefix(current_file,CURRENT_DIR.size());
82
83 if(expected_without_prefix != current_without_prefix){
84 if(expected_without_prefix < current_without_prefix){
85 cout << "TEST FAILED" << '\n';
86 cout << "Expected file with name " <<expected_file <<" but does not exist" << '\n';
87 return;
88 }else{
89 cout << "TEST FAILED" << '\n';
90 cout << "Unexpected file with name " << current_file << " found" << '\n';
91 return;
92 }
93 }
94 if(should_skip(current_without_prefix)) continue;
95 if(!areEqualFile(expected_file,current_file)){
96 cout << "TEST FAILED" << '\n';
97 cout << "File " << expected_file << " does not have the expected content" << '\n';
98 return;
99 }
100 }
101 cout << "TEST PASSED" << '\n';
102}
103
104
105int main( int argc, char *argv[] ){
108 Test();
109
110}
111
static Config * config()
Gets the singleton configuration instance.
Definition config.cpp:18
void setTestConfig()
Sets test configuration paths.
Definition config.cpp:8
Codebase preprocessing orchestrator.
Configuration management interface.
vector< string > read_file_generic(string string_path)
Reads a file line by line into a vector of strings.
Definition utils.cpp:19
Definition json.hpp:5678
Codebase preprocessing interface.
vector< string > skip_check_list
Definition test.cpp:16
int main(int argc, char *argv[])
Definition test.cpp:105
string remove_prefix(string a, int rem)
Definition test.cpp:46
bool should_skip(string s)
Definition test.cpp:18
const string EXPECTED_DIR
Definition test.cpp:12
const string CODEBASE_DIR
Definition test.cpp:14
bool areEqualFile(string file1, string file2)
Definition test.cpp:27
const string CURRENT_DIR
Definition test.cpp:13
void Test()
Definition test.cpp:58
Defines utility functions used across all files.