diff options
| author | Bent Bisballe Nyeng <deva@aasimon.org> | 2025-04-02 21:54:55 +0200 | 
|---|---|---|
| committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2025-04-20 11:02:55 +0200 | 
| commit | bae7399c0beadc36ed5afaebf4690439a416416f (patch) | |
| tree | 4aa99644e403397112cf313da55a84e225ef4ab3 /test | |
| parent | cd6c3ea1c3ca853fc38da4fa5fd62545c31aa92d (diff) | |
Diffstat (limited to 'test')
| -rw-r--r-- | test/ctor.cc | 13 | ||||
| -rw-r--r-- | test/execute_test.cc | 24 | ||||
| -rw-r--r-- | test/source_type_test.cc | 8 | ||||
| -rwxr-xr-x | test/suite/test.sh | 2 | ||||
| -rw-r--r-- | test/testprog.cc | 38 | ||||
| -rw-r--r-- | test/tmpfile.h | 5 | ||||
| -rw-r--r-- | test/tools_test.cc | 3 | 
7 files changed, 88 insertions, 5 deletions
diff --git a/test/ctor.cc b/test/ctor.cc index 0d77a3e..768708c 100644 --- a/test/ctor.cc +++ b/test/ctor.cc @@ -22,6 +22,7 @@ ctor::build_configurations ctorTestConfigs(const ctor::settings& settings)  					"-std=c++20", "-O3", "-Wall", "-Werror",  					"-I../src", "-Iuunit",  					"-DOUTPUT=\"argparser\"", +					"-fexceptions",  				},  			},  		}, @@ -39,6 +40,7 @@ ctor::build_configurations ctorTestConfigs(const ctor::settings& settings)  					"-std=c++20", "-O3", "-Wall", "-Werror",  					"-I../src", "-Iuunit",  					"-DOUTPUT=\"argsplit\"", +					"-fexceptions",  				},  			},  		}, @@ -56,6 +58,7 @@ ctor::build_configurations ctorTestConfigs(const ctor::settings& settings)  					"-std=c++20", "-O3", "-Wall", "-Werror",  					"-I../src", "-Iuunit",  					"-DOUTPUT=\"pointerlist\"", +					"-fexceptions",  				},  			},  		}, @@ -74,7 +77,9 @@ ctor::build_configurations ctorTestConfigs(const ctor::settings& settings)  				.cxxflags = {  					"-std=c++20", "-O3", "-Wall", "-Werror",  					"-I../src", "-Iuunit", +					"-I../json/include",  					"-DOUTPUT=\"deps\"", +					"-fexceptions",  				},  			},  		}, @@ -88,6 +93,7 @@ ctor::build_configurations ctorTestConfigs(const ctor::settings& settings)  			.flags = {  				.cxxflags = {  					"-std=c++20", "-O3", "-Wall", "-Werror", +					"-fexceptions",  				},  			},  		}, @@ -108,6 +114,7 @@ ctor::build_configurations ctorTestConfigs(const ctor::settings& settings)  					"-std=c++20", "-O3", "-Wall", "-Werror",  					"-I../src", "-Iuunit",  					"-DOUTPUT=\"execute\"", +					"-fexceptions",  				},  				.ldflags = { "-pthread" },  			}, @@ -126,6 +133,7 @@ ctor::build_configurations ctorTestConfigs(const ctor::settings& settings)  					"-std=c++20", "-O3", "-Wall", "-Werror",  					"-I../src", "-Iuunit",  					"-DOUTPUT=\"tasks\"", +					"-fexceptions",  				},  				.ldflags = { "-pthread" },  			}, @@ -144,6 +152,7 @@ ctor::build_configurations ctorTestConfigs(const ctor::settings& settings)  					"-std=c++20", "-O3", "-Wall", "-Werror",  					"-I../src", "-Iuunit",  					"-DOUTPUT=\"cycle\"", +					"-fexceptions",  				},  				.ldflags = { "-pthread" },  			}, @@ -162,6 +171,7 @@ ctor::build_configurations ctorTestConfigs(const ctor::settings& settings)  					"-std=c++20", "-O3", "-Wall", "-Werror",  					"-I../src", "-Iuunit",  					"-DOUTPUT=\"source_type\"", +					"-fexceptions",  				},  				.ldflags = { "-pthread" },  			}, @@ -182,6 +192,7 @@ ctor::build_configurations ctorTestConfigs(const ctor::settings& settings)  					"-std=c++20", "-O3", "-Wall", "-Werror",  					"-I../src", "-Iuunit",  					"-DOUTPUT=\"tools\"", +					"-fexceptions",  				},  			},  		}, @@ -211,6 +222,8 @@ ctor::build_configurations ctorTestConfigs(const ctor::settings& settings)  				.cxxflags = {  					"-std=c++20", "-O3", "-Wall", "-Werror",  					"-I../src", +					"-I../json/include", +					"-fexceptions",  				},  				.ldflags = { "-pthread" },  			}, diff --git a/test/execute_test.cc b/test/execute_test.cc index 11b067f..3cdb309 100644 --- a/test/execute_test.cc +++ b/test/execute_test.cc @@ -23,6 +23,13 @@ public:  	void return_value()  	{ +#if defined(_WIN32) +		constexpr int segfault_return_value = 3; +		constexpr int exception_return_value = 0xC0000409; +#else +		constexpr int segfault_return_value = 11; +		constexpr int exception_return_value = 6; +#endif  		ctor::settings s;  		auto cur_path = std::filesystem::path(paths::argv_0).parent_path();  		std::vector<std::string> paths{{cur_path.string()}}; @@ -31,16 +38,21 @@ public:  		auto value = execute(s, cmd, {"retval", "0"}, {}, false);  		uASSERT_EQUAL(0, value); +  		value = execute(s, cmd, {"retval", "1"}, {}, false);  		uASSERT_EQUAL(1, value); +  		value = execute(s, "no-such-binary", {}, {}, false);  		uASSERT_EQUAL(1, value); +  		value = execute(s, cmd, {"segfault"}, {}, false); -		uASSERT_EQUAL(11, value); +		uASSERT_EQUAL(segfault_return_value, value); +  		value = execute(s, cmd, {"throw"}, {}, false); -		uASSERT_EQUAL(6, value); +		uASSERT_EQUAL(exception_return_value, value); +  		value = execute(s, cmd, {"abort"}, {}, false); -		uASSERT_EQUAL(6, value); +		uASSERT_EQUAL(exception_return_value, value);  	}  	void env() @@ -83,11 +95,13 @@ public:  		chk = std::find(vars.begin(), vars.end(), "bar=42"s);  		uASSERT(chk != vars.end()); -		// Check the one that should have overwritten the existing one (probably LANG=en_US.UTF-8 or something) +		// Check the one that should have overwritten the existing one (probably +		// LANG=en_US.UTF-8 or something)  		chk = std::find(vars.begin(), vars.end(), "LANG=foo"s);  		uASSERT(chk != vars.end()); -		// Check that other vars are also there (ie. the env wasn't cleared on entry) +		// Check that other vars are also there (ie. the env wasn't cleared on +		// entry)  		uASSERT(vars.size() > 3);  	}  }; diff --git a/test/source_type_test.cc b/test/source_type_test.cc index 288f1e5..657260e 100644 --- a/test/source_type_test.cc +++ b/test/source_type_test.cc @@ -26,6 +26,14 @@ std::ostream& operator<<(std::ostream& stream, const ctor::language& lang)  	return stream;  } +const ctor::configuration& ctor::get_configuration() +{ +	static ctor::configuration cfg{}; +	cfg.build_toolchain = ctor::toolchain::gcc; +	cfg.build_arch = ctor::arch::unix; +	return cfg; +} +  class TestableTaskCC  	: public TaskCC  { diff --git a/test/suite/test.sh b/test/suite/test.sh index c54137a..ec603f5 100755 --- a/test/suite/test.sh +++ b/test/suite/test.sh @@ -1,4 +1,6 @@  #!/bin/bash +#set -x +  : ${CXX:=g++}  : ${CTORDIR:=../../build}  : ${BUILDDIR:=build} diff --git a/test/testprog.cc b/test/testprog.cc index 93edc3f..18c2c74 100644 --- a/test/testprog.cc +++ b/test/testprog.cc @@ -5,6 +5,14 @@  extern char **environ; +#if defined(_WIN32) +#define WINDOWS_LEAN_AND_MEAN +#include <windows.h> +#undef max +#else +extern char **environ; // see 'man environ' +#endif +  int main(int argc, const char* argv[])  {  	if(argc < 2) @@ -20,11 +28,41 @@ int main(int argc, const char* argv[])  		{  			return 0;  		} +  		std::ofstream ostrm(argv[2], std::ios::binary); +		if(ostrm.bad()) +		{ +			std::cout << "Error: Could not write to " << argv[2] << "\n"; +		} +#if defined(_WIN32) +		auto env_strings = GetEnvironmentStrings(); +		const char* ptr = env_strings; +		std::string env; +		while(true) +		{ +			if(*ptr == '\0') +			{ +				if(env.empty()) +				{ +					// no more +					break; +				} +				ostrm << env << "\n"; +				env.clear(); +				++ptr; +				continue; +			} + +			env += *ptr; +			++ptr; +		} +		FreeEnvironmentStrings(env_strings); +#else  		for(auto current = environ; *current; ++current)  		{  			ostrm << (*current) << "\n";  		} +#endif  	}  	if(cmd == "retval") diff --git a/test/tmpfile.h b/test/tmpfile.h index 0f83a20..5887e36 100644 --- a/test/tmpfile.h +++ b/test/tmpfile.h @@ -17,7 +17,12 @@ public:  		while(!fp)  		{  			filename = tmp_file_template.string() + std::to_string(counter++); +			// TODO: Use std::fstream.open() with openmode noreplace when using c++23 +#if defined(_WIN32) +			fopen_s(&fp, filename.data(), "wx"); +#else  			fp = std::fopen(filename.data(), "wx"); +#endif  		}  		std::fwrite(data.data(), data.size(), 1, fp);  		std::fclose(fp); diff --git a/test/tools_test.cc b/test/tools_test.cc index 5ae04c3..15270b3 100644 --- a/test/tools_test.cc +++ b/test/tools_test.cc @@ -22,6 +22,9 @@ std::ostream& operator<<(std::ostream& stream, const ctor::toolchain& toolchain)  	case ctor::toolchain::clang:  		stream << "ctor::toolchain::clang";  		break; +	case ctor::toolchain::msvc: +		stream << "ctor::toolchain::msvc"; +		break;  	}  	return stream;  }  | 
