Mercurial > libjeffpc
changeset 663:10cf546692c8
tests: use common check_rets function
Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author | Josef 'Jeff' Sipek <jeffpc@josefsipek.net> |
---|---|
date | Sun, 10 Feb 2019 21:26:55 -0500 |
parents | e5d8203935d2 |
children | da3cc572a748 |
files | tests/test_nvl.c tests/test_nvl_pack.c |
diffstat | 2 files changed, 11 insertions(+), 85 deletions(-) [+] |
line wrap: on
line diff
--- a/tests/test_nvl.c Sun Feb 10 21:29:23 2019 -0500 +++ b/tests/test_nvl.c Sun Feb 10 21:26:55 2019 -0500 @@ -76,21 +76,11 @@ int err, int expected_err, const char *fxn, const char *key) { - if (!iserr && !expected_iserr) - return; - - if (iserr && !expected_iserr) - fail("%s(..., '%s') failed (%s), expected success", - fxn, key, xstrerror(err)); + /* convert iserr to a 0 errno value */ + err = iserr ? err : 0; + expected_err = expected_iserr ? expected_err : 0; - if (!iserr && expected_iserr) - fail("%s(..., '%s') succeded, expected failure (%s)", - fxn, key, xstrerror(expected_err)); - - if (err != expected_err) - fail("%s(..., '%s') returned %s (%d), expected %s (%d)", - fxn, key, xstrerror(err), err, xstrerror(expected_err), - expected_err); + check_rets(expected_err, err, "%s(..., '%s')", fxn, key); } static void check_key_not_exists(struct nvlist *nvl, const char *key)
--- a/tests/test_nvl_pack.c Sun Feb 10 21:29:23 2019 -0500 +++ b/tests/test_nvl_pack.c Sun Feb 10 21:26:55 2019 -0500 @@ -47,20 +47,8 @@ ret = nvl_set_bool(nvl, key, b); - if (ret == expected_ret) - return; - - if (ret && !expected_ret) - fail("nvl_set_bool(..., '%s', %s) returned %s, expected success", - key, bstr, xstrerror(ret)); - - if (ret && expected_ret) - fail("nvl_set_bool(..., '%s', %s) returned %s, expected %s", key, - bstr, xstrerror(ret), xstrerror(expected_ret)); - - if (!ret && expected_ret) - fail("nvl_set_bool(..., '%s', %s) succeded, expected %s", key, - bstr, xstrerror(expected_ret)); + check_rets(expected_ret, ret, "nvl_set_bool(..., '%s', %s)", key, + bstr); } static inline void set_int(struct nvlist *nvl, const char *key, uint64_t i, @@ -70,21 +58,8 @@ ret = nvl_set_int(nvl, key, i); - if (ret == expected_ret) - return; - - if (ret && !expected_ret) - fail("nvl_set_int(..., '%s', %"PRIu64") returned %s, " - "expected success", key, i, xstrerror(ret)); - - if (ret && expected_ret) - fail("nvl_set_int(..., '%s', %"PRIu64") returned %s, " - "expected %s", key, i, xstrerror(ret), - xstrerror(expected_ret)); - - if (!ret && expected_ret) - fail("nvl_set_int(..., '%s', %"PRIu64") succeded, " - "expected %s", key, i, xstrerror(expected_ret)); + check_rets(expected_ret, ret, "nvl_set_int(..., '%s', %"PRIu64")", key, + i); } static inline void set_null(struct nvlist *nvl, const char *key, @@ -94,20 +69,7 @@ ret = nvl_set_null(nvl, key); - if (ret == expected_ret) - return; - - if (ret && !expected_ret) - fail("nvl_set_null(..., '%s') returned %s, expected success", - key, xstrerror(ret)); - - if (ret && expected_ret) - fail("nvl_set_null(..., '%s') returned %s, expected %s", key, - xstrerror(ret), xstrerror(expected_ret)); - - if (!ret && expected_ret) - fail("nvl_set_null(..., '%s') succeded, expected %s", key, - xstrerror(expected_ret)); + check_rets(expected_ret, ret, "nvl_set_null(..., '%s')", key); } static inline void set_str(struct nvlist *nvl, const char *key, struct str *str, @@ -117,20 +79,7 @@ ret = nvl_set_str(nvl, key, str); - if (ret == expected_ret) - return; - - if (ret && !expected_ret) - fail("nvl_set_str(..., '%s', ...) returned %s, expected success", - key, xstrerror(ret)); - - if (ret && expected_ret) - fail("nvl_set_str(..., '%s', ...) returned %s, expected %s", key, - xstrerror(ret), xstrerror(expected_ret)); - - if (!ret && expected_ret) - fail("nvl_set_str(..., '%s', ...) succeded, expected %s", key, - xstrerror(expected_ret)); + check_rets(expected_ret, ret, "nvl_set_str(..., '%s', ...)", key); } static inline void unset(struct nvlist *nvl, const char *key, int expected_ret) @@ -139,20 +88,7 @@ ret = nvl_unset(nvl, key); - if (ret == expected_ret) - return; - - if (ret && !expected_ret) - fail("nvl_unset(..., '%s') returned %s, expected success", key, - xstrerror(ret)); - - if (ret && expected_ret) - fail("nvl_unset(..., '%s') returned %s, expected %s", key, - xstrerror(ret), xstrerror(expected_ret)); - - if (!ret && expected_ret) - fail("nvl_unset(..., '%s') succeded, expected %s", key, - xstrerror(expected_ret)); + check_rets(expected_ret, ret, "nvl_unset(..., '%s')", key); } static inline void dumpbuf(struct buffer *buf, bool hex)