diff options
Diffstat (limited to 'test/testprog.cc')
| -rw-r--r-- | test/testprog.cc | 55 | 
1 files changed, 55 insertions, 0 deletions
diff --git a/test/testprog.cc b/test/testprog.cc new file mode 100644 index 0000000..93edc3f --- /dev/null +++ b/test/testprog.cc @@ -0,0 +1,55 @@ +#include <iostream> +#include <fstream> +#include <string> +#include <csignal> + +extern char **environ; + +int main(int argc, const char* argv[]) +{ +	if(argc < 2) +	{ +		return 0; +	} + +	std::string cmd = argv[1]; + +	if(cmd == "envdump") +	{ +		if(argc < 3) +		{ +			return 0; +		} +		std::ofstream ostrm(argv[2], std::ios::binary); +		for(auto current = environ; *current; ++current) +		{ +			ostrm << (*current) << "\n"; +		} +	} + +	if(cmd == "retval") +	{ +		if(argc < 3) +		{ +			return 0; +		} +		return std::stoi(argv[2]); +	} + +	if(cmd == "abort") +	{ +		abort(); +	} + +	if(cmd == "segfault") +	{ +		raise(SIGSEGV); +	} + +	if(cmd == "throw") +	{ +		throw "ouch"; +	} + +	return 0; +}  | 
