Directory: | ./ |
---|---|
File: | TESTS/TEST_OPTION_COMPLETION_MODE/main.cpp |
Date: | 2024-07-27 10:53:27 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 44 | 46 | 95.7% |
Branches: | 178 | 181 | 98.3% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | |||
2 | /*************************************** | ||
3 | Auteur : Pierre Aubert | ||
4 | Mail : pierre.aubert@lapp.in2p3.fr | ||
5 | Licence : CeCILL-C | ||
6 | ****************************************/ | ||
7 | |||
8 | #include <map> | ||
9 | #include <iostream> | ||
10 | #include "phoenix_assert.h" | ||
11 | #include "phoenix_check.h" | ||
12 | |||
13 | #include "string_utils.h" | ||
14 | #include "string_system.h" | ||
15 | |||
16 | ///Create a map with a string | ||
17 | /** @param mapStr : map of string to be created | ||
18 | * @param listStr : list of string to be used | ||
19 | */ | ||
20 | 16 | void fillMapString(std::map<std::string, bool> & mapStr, const std::list<std::string> & listStr){ | |
21 |
2/2✓ Branch 3 taken 66 times.
✓ Branch 4 taken 16 times.
|
82 | for(std::list<std::string>::const_iterator it(listStr.begin()); it != listStr.end(); ++it){ |
22 |
1/1✓ Branch 2 taken 66 times.
|
66 | mapStr[*it] = true; |
23 | } | ||
24 | 16 | } | |
25 | |||
26 | ///Check the restut | ||
27 | /** @param resultCmd : result | ||
28 | * @param expectedResult : expected result | ||
29 | * @param separator : separator to be used to split the results | ||
30 | * @return true if the results matches the expected result, false otherwise | ||
31 | */ | ||
32 | 16 | bool checkResultSeparator(const std::string & resultCmd, const std::string & expectedResult, char separator){ | |
33 |
1/1✓ Branch 1 taken 16 times.
|
16 | std::list<std::string> listRes = cutStringList(resultCmd, separator); |
34 |
1/1✓ Branch 1 taken 16 times.
|
16 | std::list<std::string> listExpectedRes = cutStringList(expectedResult, separator); |
35 | |||
36 | 16 | std::map<std::string, bool> mapExpectedRes; | |
37 |
1/1✓ Branch 1 taken 16 times.
|
16 | fillMapString(mapExpectedRes, listExpectedRes); |
38 | |||
39 | 16 | bool b(true); | |
40 |
2/2✓ Branch 5 taken 66 times.
✓ Branch 6 taken 16 times.
|
82 | for(std::list<std::string>::const_iterator it(listRes.begin()); it != listRes.end(); ++it){ |
41 |
1/1✓ Branch 3 taken 66 times.
|
66 | b &= mapExpectedRes.find(*it) != mapExpectedRes.end(); |
42 | } | ||
43 | |||
44 | 16 | return b; | |
45 | 16 | } | |
46 | |||
47 | ///Check the restut | ||
48 | /** @param resultCmd : result | ||
49 | * @param expectedResult : expected result | ||
50 | * @return true if the results matches the expected result, false otherwise | ||
51 | */ | ||
52 | 16 | bool checkResult(const std::string & resultCmd, const std::string & expectedResult){ | |
53 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
|
16 | if(!checkResultSeparator(resultCmd, expectedResult, ' ')){ |
54 | ✗ | if(!checkResultSeparator(resultCmd, expectedResult, '\n')){ | |
55 | ✗ | return false; | |
56 | } | ||
57 | } | ||
58 | 16 | return true; | |
59 | } | ||
60 | |||
61 | ///Check the option completion of a program | ||
62 | /** @param program : program to be tested | ||
63 | * @param partialOption : partial typed option | ||
64 | * @param prevCursorOption : previous cursor option | ||
65 | * @param cursorOption : option of the cursor | ||
66 | * @param expectedResult : expected completion result | ||
67 | * @return true on success, false otherwise | ||
68 | */ | ||
69 | 16 | bool checkOptionCompletion(const std::string & program, const std::string & partialOption, | |
70 | const std::string & prevCursorOption, const std::string & cursorOption, const std::string & expectedResult) | ||
71 | { | ||
72 |
6/6✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
✓ Branch 7 taken 16 times.
✓ Branch 10 taken 16 times.
✓ Branch 13 taken 16 times.
✓ Branch 16 taken 16 times.
|
32 | std::string command(program + " __bashcompletionmode=\""+cursorOption+"\" __bashcompletionmodeprev=\""+prevCursorOption+"\" prgName " + partialOption); |
73 |
1/1✓ Branch 1 taken 16 times.
|
16 | std::string resultCmd(phoenix_popen(command)); |
74 | // std::cout << "checkOptionCompletion : command '"<<command<<"':\n\tresult = '"<<resultCmd<<"', expectedResult = '"<<expectedResult<<"'" << std::endl; | ||
75 | |||
76 |
1/1✓ Branch 1 taken 16 times.
|
16 | bool b(checkResult(resultCmd, expectedResult)); |
77 | 16 | return b; | |
78 | 16 | } | |
79 | |||
80 | ///Test the completion of the option | ||
81 | 1 | void testCompletion(){ | |
82 |
10/10✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 18 taken 1 times.
✓ Branch 22 taken 1 times.
✓ Branch 26 taken 1 times.
✓ Branch 30 taken 1 times.
✓ Branch 33 taken 1 times.
✓ Branch 36 taken 1 times.
|
1 | phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "", "", "", "class source --help -h --version -v \n")); |
83 |
10/10✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 18 taken 1 times.
✓ Branch 22 taken 1 times.
✓ Branch 26 taken 1 times.
✓ Branch 30 taken 1 times.
✓ Branch 33 taken 1 times.
✓ Branch 36 taken 1 times.
|
1 | phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "class", "class", "", "--name -n --template -t --config -c --help -h --version -v \n")); |
84 |
10/10✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 18 taken 1 times.
✓ Branch 22 taken 1 times.
✓ Branch 26 taken 1 times.
✓ Branch 30 taken 1 times.
✓ Branch 33 taken 1 times.
✓ Branch 36 taken 1 times.
|
1 | phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "class", "class", "-", "--name -n --template -t --config -c --help -h --version -v \n")); |
85 |
10/10✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 18 taken 1 times.
✓ Branch 22 taken 1 times.
✓ Branch 26 taken 1 times.
✓ Branch 30 taken 1 times.
✓ Branch 33 taken 1 times.
✓ Branch 36 taken 1 times.
|
1 | phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "class", "class", "--", "--name --template --config --help --version \n")); |
86 |
10/10✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 18 taken 1 times.
✓ Branch 22 taken 1 times.
✓ Branch 26 taken 1 times.
✓ Branch 30 taken 1 times.
✓ Branch 33 taken 1 times.
✓ Branch 36 taken 1 times.
|
1 | phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "class", "class", "--n", "--name \n")); |
87 |
10/10✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 18 taken 1 times.
✓ Branch 22 taken 1 times.
✓ Branch 26 taken 1 times.
✓ Branch 30 taken 1 times.
✓ Branch 33 taken 1 times.
✓ Branch 36 taken 1 times.
|
1 | phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "class --name=test --", "--name=test", "--", "--template --config --help --version \n")); |
88 |
10/10✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 18 taken 1 times.
✓ Branch 22 taken 1 times.
✓ Branch 26 taken 1 times.
✓ Branch 30 taken 1 times.
✓ Branch 33 taken 1 times.
✓ Branch 36 taken 1 times.
|
1 | phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "class --name=\"test\" --", "--name=\"test\"", "--", "--template --config --help --version \n")); |
89 |
10/10✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 18 taken 1 times.
✓ Branch 22 taken 1 times.
✓ Branch 26 taken 1 times.
✓ Branch 30 taken 1 times.
✓ Branch 33 taken 1 times.
✓ Branch 36 taken 1 times.
|
1 | phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "class -n \"test\" --", "\"test\"", "--", "--template --config --help --version \n")); |
90 |
10/10✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 18 taken 1 times.
✓ Branch 22 taken 1 times.
✓ Branch 26 taken 1 times.
✓ Branch 30 taken 1 times.
✓ Branch 33 taken 1 times.
✓ Branch 36 taken 1 times.
|
1 | phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "source", "source", "", "--name -n --help -h --version -v \n")); |
91 |
10/10✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 18 taken 1 times.
✓ Branch 22 taken 1 times.
✓ Branch 26 taken 1 times.
✓ Branch 30 taken 1 times.
✓ Branch 33 taken 1 times.
✓ Branch 36 taken 1 times.
|
1 | phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "class --config ", "--config", "", "./\n")); |
92 |
10/10✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 18 taken 1 times.
✓ Branch 22 taken 1 times.
✓ Branch 26 taken 1 times.
✓ Branch 30 taken 1 times.
✓ Branch 33 taken 1 times.
✓ Branch 36 taken 1 times.
|
1 | phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "class --config " DIR_COMPLETION, "--config", DIR_COMPLETION, DIR_COMPLETION "/0-someDir\n" DIR_COMPLETION "/1-someFile.txt\n\n")); |
93 |
10/10✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 18 taken 1 times.
✓ Branch 22 taken 1 times.
✓ Branch 26 taken 1 times.
✓ Branch 30 taken 1 times.
✓ Branch 33 taken 1 times.
✓ Branch 36 taken 1 times.
|
1 | phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "class --config " DIR_COMPLETION "/0-someDir", "--config", DIR_COMPLETION "/0-someDir", DIR_COMPLETION "/0-someDir/someFile.txt\n\n")); |
94 |
10/10✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 18 taken 1 times.
✓ Branch 22 taken 1 times.
✓ Branch 26 taken 1 times.
✓ Branch 30 taken 1 times.
✓ Branch 33 taken 1 times.
✓ Branch 36 taken 1 times.
|
1 | phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "class --config " DIR_COMPLETION "/0-someDir/someFile.txt", "--config", DIR_COMPLETION "/0-someDir/someFile.txt", "\n")); |
95 |
10/10✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 18 taken 1 times.
✓ Branch 22 taken 1 times.
✓ Branch 26 taken 1 times.
✓ Branch 30 taken 1 times.
✓ Branch 33 taken 1 times.
✓ Branch 36 taken 1 times.
|
1 | phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE, "class --config " DIR_COMPLETION "/0-someDir/some", "--config", DIR_COMPLETION "/0-someDir/some", DIR_COMPLETION "/0-someDir/someFile.txt\n\n")); |
96 |
10/10✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 18 taken 1 times.
✓ Branch 22 taken 1 times.
✓ Branch 26 taken 1 times.
✓ Branch 30 taken 1 times.
✓ Branch 33 taken 1 times.
✓ Branch 36 taken 1 times.
|
1 | phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE_DIR, "class --dir " DIR_COMPLETION "/0-some", "--dir", DIR_COMPLETION "/0-some", DIR_COMPLETION "/0-someDir\n\n")); |
97 |
10/10✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 18 taken 1 times.
✓ Branch 22 taken 1 times.
✓ Branch 26 taken 1 times.
✓ Branch 30 taken 1 times.
✓ Branch 33 taken 1 times.
✓ Branch 36 taken 1 times.
|
1 | phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_MODE_DIR, "class --dir " DIR_COMPLETION, "--dir", DIR_COMPLETION, DIR_COMPLETION "/0-someDir\n\n")); |
98 | 1 | } | |
99 | |||
100 | 1 | int main(int argc, char** argv){ | |
101 | 1 | testCompletion(); | |
102 | 1 | return 0; | |
103 | } | ||
104 | |||
105 | |||
106 |