scope_ut.cpp 947 B

12345678910111213141516171819202122232425262728
  1. #include <library/cpp/testing/common/scope.h>
  2. #include <util/system/env.h>
  3. #include <library/cpp/testing/gtest/gtest.h>
  4. TEST(TScopedEnvironment, SingleValue) {
  5. auto before = GetEnv("ARCADIA_SOURCE_ROOT");
  6. {
  7. NTesting::TScopedEnvironment guard("ARCADIA_SOURCE_ROOT", "source");
  8. EXPECT_EQ("source", GetEnv("ARCADIA_SOURCE_ROOT"));
  9. }
  10. EXPECT_EQ(before, GetEnv("ARCADIA_SOURCE_ROOT"));
  11. }
  12. TEST(TScopedEnvironment, MultiValue) {
  13. TVector<TString> before{GetEnv("ARCADIA_SOURCE_ROOT"), GetEnv("ARCADIA_BUILD_ROOT")};
  14. {
  15. NTesting::TScopedEnvironment guard{{
  16. {"ARCADIA_SOURCE_ROOT", "source"},
  17. {"ARCADIA_BUILD_ROOT", "build"},
  18. }};
  19. EXPECT_EQ("source", GetEnv("ARCADIA_SOURCE_ROOT"));
  20. EXPECT_EQ("build", GetEnv("ARCADIA_BUILD_ROOT"));
  21. }
  22. TVector<TString> after{GetEnv("ARCADIA_SOURCE_ROOT"), GetEnv("ARCADIA_BUILD_ROOT")};
  23. EXPECT_EQ(before, after);
  24. }