-
Notifications
You must be signed in to change notification settings - Fork 26.4k
t/unit-tests: convert oid-array test to use clar test framework #1892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
821d977
to
61cfc43
Compare
t/unit-tests/u-oid-array.c
Outdated
|
||
void test_oid_array__enumerate_unique(void) | ||
{ | ||
setup(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of calling this explicitly you can use a test_oid_array__initialize()
function.
t/unit-tests/u-oid-array.c
Outdated
cl_assert_equal_i(actual.nr, expect.nr); | ||
|
||
for (i = 0; i < actual.nr; i++) | ||
cl_assert(oideq(&actual.oid[i], &expect.oid[i])); | ||
|
||
oid_array_clear(&actual); | ||
oid_array_clear(&input); | ||
oid_array_clear(&expect); | ||
} | ||
|
||
#define TEST_ENUMERATION(input, expect, desc) \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The description isn't used, so it can be dropped.
t/unit-tests/unit-test.c
Outdated
@@ -2,6 +2,9 @@ | |||
#include "parse-options.h" | |||
#include "string-list.h" | |||
#include "strvec.h" | |||
#include "strbuf.h" | |||
#include "hex.h" | |||
#include "unit-test.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep headers sorted alphabetically (except for "unit-test.h", which is expected to come first. You also got that one duplicated now.
t/unit-tests/unit-test.c
Outdated
return algo; | ||
} | ||
|
||
static int get_oid_arbitrary_hex_algop(const char *hex, struct object_id *oid, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder whether we want to give these functions names which give a bit of a better hint that they are part of the test suite. E.g. cl_parse_oid()
.
t/unit-tests/unit-test.c
Outdated
cl_assert_equal_i(ret, 0); | ||
|
||
strbuf_release(&buf); | ||
return ret; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return value can be removed as you already assert that it's always 0.
t/unit-tests/unit-test.c
Outdated
} | ||
|
||
|
||
int get_oid_arbitrary_hex(const char *hex, struct object_id *oid) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. How about cl_parse_any_oid()
?
t/unit-tests/unit-test.c
Outdated
int hash_algo = init_hash_algo(); | ||
|
||
cl_assert(hash_algo != GIT_HASH_UNKNOWN); | ||
return get_oid_arbitrary_hex_algop(hex, oid, &hash_algos[hash_algo]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to also assert that the return value is 0? I guess that should be a safe assumption given that this is a helper. We can then drop the return value again.
998ff22
to
7c9c2b8
Compare
@@ -0,0 +1,152 @@ | |||
#include "unit-test.h" | |||
#include "lib-oid.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This header does not need to be included as it only contains the "old" assertions used by the other unit testing framework, right?
t/unit-tests/u-oidmap.c
Outdated
FLEX_ALLOC_STR(entry, name, key_val[i][1]); | ||
cl_parse_any_oid(key_val[i][0], &entry->entry.oid); | ||
entry = oidmap_put(&map, entry); | ||
cl_assert(entry == NULL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can probably drop the entry
variable and directly cl_assert_equal_p(oidmap_put(&map, entry), NULL)
. The same is also true in other cases.
t/unit-tests/u-oidmap.c
Outdated
{ "22", "two" }, | ||
{ "33", "three" } }; | ||
|
||
static void setup(void (*f)(struct oidmap *map)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using a setup()
function, let's use a test_oidmap__initialize()
function that gets executed automatically and initializes a global variable, as well as a test_oidmap__cleanup()
function that cleans up state. When we have that we can get rid of setup()
and also of functions like test_oidmap__replace()
, where t_replace_()
itself would be renamed.
t/unit-tests/u-oidmap.c
Outdated
oidmap_iter_init(map, &iter); | ||
while ((entry = oidmap_iter_next(&iter))) { | ||
int ret; | ||
cl_assert_equal_i(ret = key_val_contains(entry, seen), 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ret
is unneeded here, so we can drop it.
98604fd
to
f1ab0d6
Compare
There are issues in commit f1ab0d6: |
f1ab0d6
to
504a4bb
Compare
There are issues in commit 504a4bb: |
504a4bb
to
7cdea9e
Compare
There are issues in commit 7cdea9e: |
7cdea9e
to
c7ae177
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
معالجة جمبع الاخطا
معالجة السطر 732 |
c7ae177
to
e81ec73
Compare
`get_oid_arbitrary_hex()` and `init_hash_algo()` are both required for oid-related tests to run without errors. In the current implementation, both functions are defined and declared in the `t/unit-tests/lib-oid.{c,h}` which is utilized by oid-related tests in the homegrown unit tests structure. Adapt functions in lib-oid.{c,h} to use clar. Both these functions become available for oid-related test files implemented using the clar testing framework, which requires them. This will be used by subsequent commits. Mentored-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Seyi Kuforiji <kuforiji98@gmail.com>
Adapt oid-array test script to clar framework by using clar assertions where necessary. Remove descriptions from macros to reduce redundancy, and move test input arrays to global scope for reuse across multiple test functions. Introduce `test_oid_array__initialize()` to explicitly initialize the hash algorithm. These changes streamline the test suite, making individual tests self-contained and reducing redundant code. Mentored-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Seyi Kuforiji <kuforiji98@gmail.com>
Adapt oidmap test script to clar framework by using clar assertions where necessary. `cl_parse_any_oid()` ensures the hash algorithm is set before parsing. This prevents issues from an uninitialized or invalid hash algorithm. Introduce 'test_oidmap__initialize` handles the to set up of the global oidmap map with predefined key-value pairs, and `test_oidmap__cleanup` frees the oidmap and its entries when all tests are completed. The test loops through all entries to detect multiple errors. With this change, it stops at the first error encountered, making it easier to address it. Mentored-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Seyi Kuforiji <kuforiji98@gmail.com>
Adapt oidtree test script to clar framework by using clar assertions where necessary. `cl_parse_any_oid()` ensures the hash algorithm is set before parsing. This prevents issues from an uninitialized or invalid hash algorithm. Introduce 'test_oidtree__initialize` handles the to set up of the global oidtree variable and `test_oidtree__cleanup` frees the oidtree when all tests are completed. With this change, `check_each` stops at the first error encountered, making it easier to address it. Mentored-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Seyi Kuforiji <kuforiji98@gmail.com>
e81ec73
to
cda8dc1
Compare
Adapt oid-array test script to clar framework by using clar assertions where necessary.
Mentored-by: Patrick Steinhardt ps@pks.im
Signed-off-by: Seyi Kuforiji kuforiji98@gmail.com