summaryrefslogtreecommitdiff
path: root/ept/test.h
diff options
context:
space:
mode:
Diffstat (limited to 'ept/test.h')
-rw-r--r--ept/test.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/ept/test.h b/ept/test.h
index dfab4d7..26a900a 100644
--- a/ept/test.h
+++ b/ept/test.h
@@ -12,6 +12,7 @@
#include <apt-pkg/progress.h>
#include <apt-pkg/pkgcachegen.h>
#include <apt-pkg/init.h>
+#include <cstdlib>
#ifndef EPT_TEST_H
@@ -46,4 +47,31 @@ struct DebtagsTestEnvironment : AptTestEnvironment {
{}
};
+struct EnvOverride
+{
+ const char* name;
+ bool old_value_set;
+ std::string old_value;
+
+ EnvOverride(const char* name, const char* value)
+ : name(name)
+ {
+ const char* old = getenv(name);
+ if (old)
+ {
+ old_value_set = true;
+ old_value = old;
+ } else
+ old_value_set = false;
+ setenv(name, value, 1);
+ }
+ ~EnvOverride()
+ {
+ if (old_value_set)
+ setenv(name, old_value.c_str(), 1);
+ else
+ unsetenv(name);
+ }
+};
+
#endif