diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/ctor.cc | 41 | ||||
-rw-r--r-- | test/execute_test.cc | 14 | ||||
-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 | 44 | ||||
-rw-r--r-- | test/tools_test.cc | 3 |
7 files changed, 122 insertions, 28 deletions
diff --git a/test/ctor.cc b/test/ctor.cc index b7bcc6d..fa53802 100644 --- a/test/ctor.cc +++ b/test/ctor.cc @@ -23,6 +23,8 @@ ctor::build_configurations ctorTestConfigs(const ctor::settings& settings) "-std=c++20", "-O3", "-Wall", "-Werror", "-I../src", "-Iuunit", "-DOUTPUT=\"argsplit\"", + {ctor::toolchain::msvc, ctor::cxx_opt::custom, "/EHsc"}, + {ctor::toolchain::msvc, ctor::cxx_opt::custom, "/D_CRT_SECURE_NO_WARNINGS"}, }, }, }, @@ -40,6 +42,8 @@ ctor::build_configurations ctorTestConfigs(const ctor::settings& settings) "-std=c++20", "-O3", "-Wall", "-Werror", "-I../src", "-Iuunit", "-DOUTPUT=\"pointerlist\"", + {ctor::toolchain::msvc, ctor::cxx_opt::custom, "/EHsc"}, + {ctor::toolchain::msvc, ctor::cxx_opt::custom, "/D_CRT_SECURE_NO_WARNINGS"}, }, }, }, @@ -58,7 +62,10 @@ ctor::build_configurations ctorTestConfigs(const ctor::settings& settings) .cxxflags = { "-std=c++20", "-O3", "-Wall", "-Werror", "-I../src", "-Iuunit", + "-I../json/include", "-DOUTPUT=\"deps\"", + {ctor::toolchain::msvc, ctor::cxx_opt::custom, "/EHsc"}, + {ctor::toolchain::msvc, ctor::cxx_opt::custom, "/D_CRT_SECURE_NO_WARNINGS"}, }, }, }, @@ -72,6 +79,8 @@ ctor::build_configurations ctorTestConfigs(const ctor::settings& settings) .flags = { .cxxflags = { "-std=c++20", "-O3", "-Wall", "-Werror", + {ctor::toolchain::msvc, ctor::cxx_opt::custom, "/EHsc"}, + {ctor::toolchain::msvc, ctor::cxx_opt::custom, "/D_CRT_SECURE_NO_WARNINGS"}, }, }, }, @@ -92,6 +101,8 @@ ctor::build_configurations ctorTestConfigs(const ctor::settings& settings) "-std=c++20", "-O3", "-Wall", "-Werror", "-I../src", "-Iuunit", "-DOUTPUT=\"execute\"", + {ctor::toolchain::msvc, ctor::cxx_opt::custom, "/EHsc"}, + {ctor::toolchain::msvc, ctor::cxx_opt::custom, "/D_CRT_SECURE_NO_WARNINGS"}, }, .ldflags = { "-pthread" }, }, @@ -110,6 +121,8 @@ ctor::build_configurations ctorTestConfigs(const ctor::settings& settings) "-std=c++20", "-O3", "-Wall", "-Werror", "-I../src", "-Iuunit", "-DOUTPUT=\"tasks\"", + {ctor::toolchain::msvc, ctor::cxx_opt::custom, "/EHsc"}, + {ctor::toolchain::msvc, ctor::cxx_opt::custom, "/D_CRT_SECURE_NO_WARNINGS"}, }, .ldflags = { "-pthread" }, }, @@ -128,6 +141,8 @@ ctor::build_configurations ctorTestConfigs(const ctor::settings& settings) "-std=c++20", "-O3", "-Wall", "-Werror", "-I../src", "-Iuunit", "-DOUTPUT=\"cycle\"", + {ctor::toolchain::msvc, ctor::cxx_opt::custom, "/EHsc"}, + {ctor::toolchain::msvc, ctor::cxx_opt::custom, "/D_CRT_SECURE_NO_WARNINGS"}, }, .ldflags = { "-pthread" }, }, @@ -146,6 +161,8 @@ ctor::build_configurations ctorTestConfigs(const ctor::settings& settings) "-std=c++20", "-O3", "-Wall", "-Werror", "-I../src", "-Iuunit", "-DOUTPUT=\"source_type\"", + {ctor::toolchain::msvc, ctor::cxx_opt::custom, "/EHsc"}, + {ctor::toolchain::msvc, ctor::cxx_opt::custom, "/D_CRT_SECURE_NO_WARNINGS"}, }, .ldflags = { "-pthread" }, }, @@ -166,6 +183,8 @@ ctor::build_configurations ctorTestConfigs(const ctor::settings& settings) "-std=c++20", "-O3", "-Wall", "-Werror", "-I../src", "-Iuunit", "-DOUTPUT=\"tools\"", + {ctor::toolchain::msvc, ctor::cxx_opt::custom, "/EHsc"}, + {ctor::toolchain::msvc, ctor::cxx_opt::custom, "/D_CRT_SECURE_NO_WARNINGS"}, }, }, }, @@ -190,11 +209,33 @@ ctor::build_configurations ctorTestConfigs(const ctor::settings& settings) "../src/tools.cc", "../src/util.cc", "../src/externals_manual.cc", + {ctor::toolchain::msvc, "../getopt-for-windows/getopt.c"}, }, .flags = { + .cflags = { + "-O3", +// "-g", +// "-Wall", +// "-Wconversion", +// "-Wextra", + //"-Werror", + "-I../src", + {ctor::toolchain::msvc, ctor::c_opt::custom, "/I../getopt-for-windows"}, + {ctor::toolchain::msvc, ctor::c_opt::custom, "/D_X86_"}, + {ctor::toolchain::msvc, ctor::c_opt::custom, "/EHsc"}, + {ctor::toolchain::msvc, ctor::c_opt::custom, "/external:W0"}, + {ctor::toolchain::msvc, ctor::c_opt::custom, "/D_CRT_SECURE_NO_WARNINGS"}, + }, .cxxflags = { "-std=c++20", "-O3", "-Wall", "-Werror", "-I../src", + "-I../json/include", + {ctor::toolchain::msvc, ctor::cxx_opt::custom, "/I../getopt-for-windows"}, + {ctor::toolchain::msvc, ctor::cxx_opt::custom, "/D_X86_"}, + {ctor::toolchain::msvc, ctor::cxx_opt::custom, "/EHsc"}, + {ctor::toolchain::msvc, ctor::cxx_opt::custom, "/external:W0"}, + {ctor::toolchain::msvc, ctor::cxx_opt::custom, "/D_CRT_SECURE_NO_WARNINGS"}, + {ctor::toolchain::msvc, ctor::cxx_opt::custom, "/Dstrdup=_strdup"}, }, .ldflags = { "-pthread" }, }, diff --git a/test/execute_test.cc b/test/execute_test.cc index 722b6ea..4084084 100644 --- a/test/execute_test.cc +++ b/test/execute_test.cc @@ -36,11 +36,23 @@ public: value = execute(s, "no-such-binary", {}, {}, false); uASSERT_EQUAL(1, value); value = execute(s, cmd, {"segfault"}, {}, false); +#if !defined(_WIN32) uASSERT_EQUAL(11, value); +#else + uASSERT_EQUAL(3, value); +#endif value = execute(s, cmd, {"throw"}, {}, false); +#if !defined(_WIN32) uASSERT_EQUAL(6, value); +#else + uASSERT_EQUAL(-1073740791, value); +#endif value = execute(s, cmd, {"abort"}, {}, false); +#if !defined(_WIN32) uASSERT_EQUAL(6, value); +#else + uASSERT_EQUAL(-1073740791, value); +#endif } void env() @@ -53,7 +65,7 @@ public: auto cmd = locate("testprog", paths); uASSERT(!cmd.empty()); - tmp_file tmp; + TmpFile tmp; std::map<std::string, std::string> env; 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 97d2551..d57580f 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 5d114d0..0f83a20 100644 --- a/test/tmpfile.h +++ b/test/tmpfile.h @@ -3,39 +3,29 @@ // See accompanying file LICENSE for details. #pragma once -#include <cstdlib> -#include <unistd.h> +#include <cstdio> -#ifdef _WIN32 -#define WIN32_LEAN_AND_MEAN -#include <windows.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#endif - -struct tmp_file +class TmpFile { - tmp_file(const std::string& data = {}) +public: + TmpFile(const std::string& data = {}) { - int fd; -#ifdef _WIN32 - char templ[] = "ctor_tmp_file-XXXXXX"; // buffer for filename - _mktemp_s(templ, sizeof(templ)); - fd = open(templ, O_CREAT | O_RDWR); -#else - char templ[] = "/tmp/ctor_tmp_file-XXXXXX"; // buffer for filename - fd = mkstemp(templ); -#endif - filename = templ; - auto sz = write(fd, data.data(), data.size()); - (void)sz; - close(fd); + auto tmp_dir = std::filesystem::temp_directory_path(); + auto tmp_file_template = tmp_dir / "ctor_tmp_file-"; + std::FILE* fp{nullptr}; + int counter{}; + while(!fp) + { + filename = tmp_file_template.string() + std::to_string(counter++); + fp = std::fopen(filename.data(), "wx"); + } + std::fwrite(data.data(), data.size(), 1, fp); + std::fclose(fp); } - ~tmp_file() + ~TmpFile() { - unlink(filename.data()); + std::filesystem::remove(filename); } const std::string& get() const 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; } |