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 <bits/stdc++.h>
5
6using namespace std;
7
8const string EXPECTED_DIR = "tests/e2e/expected";
9const string CURRENT_DIR = "tests/e2e/current";
10const string CODEBASE_DIR = "tests/e2e/codebase";
11
12vector<string> skip_check_list = {"/tmp/config.txt","/tmp/output_tool.txt","/tmp/output_parsed.txt"};
13
14bool should_skip(string s){
15 for(auto x : skip_check_list){
16 if(x == s){
17 return true;
18 }
19 }
20 return false;
21}
22
23bool areEqualFile(string file1, string file2){
24 vector<string> left = Utils::read_file_generic(file1);
25 vector<string> right = Utils::read_file_generic(file2);
26
27 if(left.size() != right.size()){
28 return false;
29 }
30
31 int sz = left.size();
32
33 for(int i = 0; i < sz; i++){
34 if(left[i] != right[i]){
35 return false;
36 }
37 }
38
39 return true;
40}
41
42string remove_prefix(string a, int rem){
43 reverse(a.begin(),a.end());
44 int cnt = rem;
45
46 while(cnt > 0 && !a.empty()){
47 a.pop_back();
48 cnt--;
49 }
50 reverse(a.begin(),a.end());
51 return a;
52}
53
54void Test(){
55 vector<string> expected_files;
56 vector<string> current_files;
57
58 for(const auto &dirEntry: std::filesystem::recursive_directory_iterator(EXPECTED_DIR)){
59 string file_path = dirEntry.path().string();
60 expected_files.push_back(file_path);
61 }
62 for(const auto &dirEntry: std::filesystem::recursive_directory_iterator(CURRENT_DIR)){
63 string file_path = dirEntry.path().string();
64 current_files.push_back(file_path);
65 }
66
67 sort(expected_files.begin(),expected_files.end());
68 sort(current_files.begin(),current_files.end());
69
70 int ite = min((int)expected_files.size(),(int)current_files.size());
71
72 for(int i = 0; i < ite; i++){
73 string expected_file = expected_files[i];
74 string current_file = current_files[i];
75
76 string expected_without_prefix = remove_prefix(expected_file,EXPECTED_DIR.size());
77 string current_without_prefix = remove_prefix(current_file,CURRENT_DIR.size());
78
79 if(expected_without_prefix != current_without_prefix){
80 if(expected_without_prefix < current_without_prefix){
81 cout << "TEST FAILED" << '\n';
82 cout << "Expected file with name " <<expected_file <<" but does not exist" << '\n';
83 return;
84 }else{
85 cout << "TEST FAILED" << '\n';
86 cout << "Unexpected file with name " << current_file << " found" << '\n';
87 return;
88 }
89 }
90 if(should_skip(current_without_prefix)) continue;
91 if(!areEqualFile(expected_file,current_file)){
92 cout << "TEST FAILED" << '\n';
93 cout << "File " << expected_file << " does not have the expected content" << '\n';
94 return;
95 }
96 }
97 cout << "TEST PASSED" << '\n';
98}
99
100
101int main( int argc, char *argv[] ){
104 Test();
105
106}
107
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
Codebase preprocessing interface.
vector< string > skip_check_list
Definition test.cpp:12
int main(int argc, char *argv[])
Definition test.cpp:101
string remove_prefix(string a, int rem)
Definition test.cpp:42
bool should_skip(string s)
Definition test.cpp:14
const string EXPECTED_DIR
Definition test.cpp:8
const string CODEBASE_DIR
Definition test.cpp:10
bool areEqualFile(string file1, string file2)
Definition test.cpp:23
const string CURRENT_DIR
Definition test.cpp:9
void Test()
Definition test.cpp:54
Defines utility functions used across all files.