diff options
author | Guillem Jover <guillem@debian.org> | 2018-08-22 22:38:50 +0200 |
---|---|---|
committer | Guillem Jover <guillem@debian.org> | 2018-08-30 03:14:08 +0200 |
commit | 7094f7c428f1f871b1b83bf5f895ab66f9e3d55a (patch) | |
tree | 53b62e4d44d3ca2e8745bfdc25d00077b7e0a74b /lib | |
parent | 1166bbb5f099580a0c1c26d0e29b1ae3fe11ad0f (diff) | |
download | dpkg-7094f7c428f1f871b1b83bf5f895ab66f9e3d55a.tar.gz |
libdpkg: Add support for new test_get_srcdir() and test_get_builddir()
Diffstat (limited to 'lib')
-rw-r--r-- | lib/dpkg/t/t-test.c | 7 | ||||
-rw-r--r-- | lib/dpkg/test.h | 12 |
2 files changed, 18 insertions, 1 deletions
diff --git a/lib/dpkg/t/t-test.c b/lib/dpkg/t/t-test.c index 62b35ce2f..48ce8726b 100644 --- a/lib/dpkg/t/t-test.c +++ b/lib/dpkg/t/t-test.c @@ -25,7 +25,7 @@ TEST_ENTRY(test) { - test_plan(20); + test_plan(22); test_pass(1); test_fail(0); @@ -58,4 +58,9 @@ TEST_ENTRY(test) test_mem("abcd", ==, "abcd", 5); test_mem("ababcd", ==, "ababff", 4); test_mem("ababcd", !=, "ababff", 6); + + setenv("srcdir", "aaa", 1); + setenv("builddir", "bbb", 1); + test_str(test_get_srcdir(), ==, "aaa"); + test_str(test_get_builddir(), ==, "bbb"); } diff --git a/lib/dpkg/test.h b/lib/dpkg/test.h index 39ecb967b..a0e5ffdae 100644 --- a/lib/dpkg/test.h +++ b/lib/dpkg/test.h @@ -59,6 +59,18 @@ test_alloc(void *ptr, const char *reason) #define test_alloc(ptr) \ test_alloc((ptr), "cannot allocate memory for " #ptr " in " __FILE__ ":" test_stringify(__LINE__)) +static inline const char * +test_get_envdir(const char *envvar) +{ + const char *envdir = getenv(envvar); + return envdir ? envdir : "."; +} + +#define test_get_srcdir() \ + test_get_envdir("srcdir") +#define test_get_builddir() \ + test_get_envdir("builddir") + static int test_id = 1; static int test_skip_code; static const char *test_skip_prefix; |