GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: tmp_project/OptionParser/TESTS/TEST_OPTION_COMPLETION/main.cpp Lines: 16 16 100.0 %
Date: 2024-12-09 15:30:52 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

18
	std::string command(program + " __bashcompletionmode=\""+cursorOption+"\" __bashcompletionmodeprev=\""+prevCursorOption+"\" prgName " + partialOption);
25
6
	std::string resultCmd(phoenix_popen(command));
26
27
6
	bool b(phoenix_check("checkOptionCompletion cmd("+command+")", resultCmd, expectedResult));
28
12
	return b;
29
}
30
31
///Test the completion of the option
32
1
void testCompletion(){
33


1
	phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_INT, "", "", "", "--value -n --help -h --version -v \n"));
34


1
	phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_INT, "-", "", "-", "--value -n --help -h --version -v \n"));
35
	//Here we expect mostly '--value --help --version'
36


1
	phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_INT, "--", "", "--", "--value --help --version \n"));
37
	//Here we expect mostly '--value --version'
38


1
	phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_INT, "--v", "", "--v", "--value --version \n"));
39


1
	phoenix_assert(checkOptionCompletion(PROGRAM_OPTION_COMPLETION_INT, "--value", "--value", "", "INT\n"));
40


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