aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src/vcpkg-test
diff options
context:
space:
mode:
Diffstat (limited to 'toolsrc/src/vcpkg-test')
-rw-r--r--toolsrc/src/vcpkg-test/optional.cpp21
-rw-r--r--toolsrc/src/vcpkg-test/system.cpp30
2 files changed, 22 insertions, 29 deletions
diff --git a/toolsrc/src/vcpkg-test/optional.cpp b/toolsrc/src/vcpkg-test/optional.cpp
index f3c61387f..520867f2c 100644
--- a/toolsrc/src/vcpkg-test/optional.cpp
+++ b/toolsrc/src/vcpkg-test/optional.cpp
@@ -58,6 +58,27 @@ TEST_CASE ("ref conversion", "[optional]")
REQUIRE(cref_1.get() == &x);
}
+TEST_CASE ("value conversion", "[optional]")
+{
+ using vcpkg::Optional;
+
+ Optional<long> j = 1;
+ Optional<int> i = j;
+ Optional<const char*> cstr = "hello, world!";
+ Optional<std::string> cppstr = cstr;
+
+ std::vector<int> v{1, 2, 3};
+ Optional<std::vector<int>&> o_v(v);
+ REQUIRE(o_v.has_value());
+ REQUIRE(o_v.get()->size() == 3);
+ Optional<std::vector<int>> o_w(std::move(o_v));
+ REQUIRE(o_w.has_value());
+ REQUIRE(o_w.get()->size() == 3);
+ // Moving from Optional<&> should not move the underlying object
+ REQUIRE(o_v.has_value());
+ REQUIRE(o_v.get()->size() == 3);
+}
+
TEST_CASE ("common_projection", "[optional]")
{
using vcpkg::Util::common_projection;
diff --git a/toolsrc/src/vcpkg-test/system.cpp b/toolsrc/src/vcpkg-test/system.cpp
index dec7b5769..e7f8aca8f 100644
--- a/toolsrc/src/vcpkg-test/system.cpp
+++ b/toolsrc/src/vcpkg-test/system.cpp
@@ -23,39 +23,11 @@ using vcpkg::Checks::check_exit;
using vcpkg::System::CPUArchitecture;
using vcpkg::System::get_environment_variable;
using vcpkg::System::guess_visual_studio_prompt_target_architecture;
+using vcpkg::System::set_environment_variable;
using vcpkg::System::to_cpu_architecture;
namespace
{
- void set_environment_variable(ZStringView varname, Optional<std::string> value)
- {
-#if defined(_WIN32)
- const auto w_varname = vcpkg::Strings::to_utf16(varname);
- const auto w_varcstr = w_varname.c_str();
- BOOL exit_code;
- if (value)
- {
- const auto w_value = vcpkg::Strings::to_utf16(value.value_or_exit(VCPKG_LINE_INFO));
- exit_code = SetEnvironmentVariableW(w_varcstr, w_value.c_str());
- }
- else
- {
- exit_code = SetEnvironmentVariableW(w_varcstr, nullptr);
- }
-
- check_exit(VCPKG_LINE_INFO, exit_code != 0);
-#else // ^^^ defined(_WIN32) / !defined(_WIN32) vvv
- if (auto v = value.get())
- {
- check_exit(VCPKG_LINE_INFO, setenv(varname.c_str(), v->c_str(), 1) == 0);
- }
- else
- {
- check_exit(VCPKG_LINE_INFO, unsetenv(varname.c_str()) == 0);
- }
-#endif // defined(_WIN32)
- }
-
struct environment_variable_resetter
{
explicit environment_variable_resetter(ZStringView varname_)