Directory: | ./ |
---|---|
File: | TESTS/TEST_OPTION_COMPLETION/main.cpp |
Date: | 2024-07-27 10:53:27 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 17 | 17 | 100.0% |
Branches: | 70 | 70 | 100.0% |
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 <iostream> | ||
9 | #include "phoenix_assert.h" | ||
10 | #include "phoenix_check.h" | ||
11 | #include "string_system.h" | ||
12 | |||
13 | ///Check the option completion of a program | ||
14 | /** @param program : program to be tested | ||
15 | * @param partialOption : partial typed option | ||
16 | * @param cursorOption : option of the cursor | ||
17 | * @param prevCursorOption : previous cursor option | ||
18 | * @param expectedResult : expected completion result | ||
19 | * @return true on success, false otherwise | ||
20 | */ | ||
21 | 6 | bool checkOptionCompletion(const std::string & program, const std::string & partialOption, const std::string & prevCursorOption, | |
22 | const std::string & cursorOption, const std::string & expectedResult) | ||
23 | { | ||
24 |
6/6✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
✓ Branch 10 taken 6 times.
✓ Branch 13 taken 6 times.
✓ Branch 16 taken 6 times.
|
12 | std::string command(program + " __bashcompletionmode=\""+cursorOption+"\" __bashcompletionmodeprev=\""+prevCursorOption+"\" prgName " + partialOption); |
25 |
1/1✓ Branch 1 taken 6 times.
|
6 | std::string resultCmd(phoenix_popen(command)); |
26 | |||
27 |
3/3✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
|
6 | bool b(phoenix_check("checkOptionCompletion cmd("+command+")", resultCmd, expectedResult)); |
28 | 6 | return b; | |
29 | 6 | } | |
30 | |||
31 | ///Test the completion of the option | ||
32 | 1 | void testCompletion(){ | |
33 |
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_INT, "", "", "", "--value -n --help -h --version -v \n")); |
34 |
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_INT, "-", "", "-", "--value -n --help -h --version -v \n")); |
35 | //Here we expect mostly '--value --help --version' | ||
36 |
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_INT, "--", "", "--", "--value --help --version \n")); |
37 | //Here we expect mostly '--value --version' | ||
38 |
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_INT, "--v", "", "--v", "--value --version \n")); |
39 |
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_INT, "--value", "--value", "", "INT\n")); |
40 |
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_INT, "--value=42", "", "", "--help -h --version -v \n")); |
41 | 1 | } | |
42 | |||
43 | 1 | int main(int argc, char** argv){ | |
44 | 1 | testCompletion(); | |
45 | 1 | return 0; | |
46 | } | ||
47 | |||
48 | |||
49 |