t: port reftable/basics_test.c to the unit testing
PATCH 1/1 t: port reftable/basics_test.c to the unit testing
In the recent codebase update (commit 8bf6fbd, 2023-12-09), a new unit testing framework written entirely in C was introduced to the Git project aimed at simplifying testing and reducing test run times.
Currently, tests for the raftable refs-backend are performed by a custom testing framework defined by reftable/test_framework.{c, h}. Port reftable/basics_test.c to the unit testing framework and improve upon the ported test.
PATCH 1/2 t: move reftable/basics_test.c to the unit testing framework
reftable/basics_test.c exercise the functions defined in reftable/basics.{c, h}. Migrate reftable/basics_test.c to the unit testing framework. Migration involves refactoring the tests to use the unit testing framework instead of reftable's test framework.
--- Makefile | 2 +- t/helper/test-reftable.c | 1 - .../unit-tests/t-reftable-basics.c | 50 ++++++++----------- 3 files changed, 21 insertions(+), 32 deletions(-) rename reftable/basics_test.c => t/unit-tests/t-reftable-basics.c (60%)
Makefile +1 -1
@@ -1337,6 +1337,7 @@ THIRD_PARTY_SOURCES += sha1dc/% UNIT_TEST_PROGRAMS += t-ctype UNIT_TEST_PROGRAMS += t-mem-pool UNIT_TEST_PROGRAMS += t-prio-queue +UNIT_TEST_PROGRAMS += t-reftable-basics UNIT_TEST_PROGRAMS += t-strbuf UNIT_TEST_PROGRAMS += t-trailer UNIT_TEST_PROGS = $(patsubst %,$(UNIT_TEST_BIN)/%$X,$(UNIT_TEST_PROGRAMS))
@@ -2671,7 +2672,6 @@ REFTABLE_OBJS += reftable/stack.o REFTABLE_OBJS += reftable/tree.o REFTABLE_OBJS += reftable/writer.o -REFTABLE_TEST_OBJS += reftable/basics_test.o REFTABLE_TEST_OBJS += reftable/block_test.o REFTABLE_TEST_OBJS += reftable/dump.o REFTABLE_TEST_OBJS += reftable/merged_test.o
t/helper/test-reftable.c +0 -1
@@ -5,7 +5,6 @@int cmd__reftable (int argc,const char **argv) {/* test from simple to complex. */ -basics_test_main (argc, argv);record_test_main (argc, argv);block_test_main (argc, argv);tree_test_main (argc, argv);
t/unit-tests/t-reftable-basics.c renamed from reftable/basics_test.c +20 -30
93 lines not on this page · raw message
Signature · 1 line
2.45.GIT
PATCH 2/2 t: improve upon reftable/basics_test.c in the unit testing framework
In reply to Chandra PratapEnhance the new test for reftable/basics.{c, h} in the unit testing framework. The enhancements include:
- Move tests for functions in reftable/basics.{c, h} from reftable/record_test.c and reftable/stack_test.c to the new unit test.
- Add tests for functions that are not currently tested, like put_be16.
- Improve the test-cases for the already existing tests.
--- reftable/record_test.c | 37 --------------- reftable/stack_test.c | 25 ----------- t/unit-tests/t-reftable-basics.c | 77 +++++++++++++++++++++++++++----- 3 files changed, 65 insertions(+), 74 deletions(-)
reftable/record_test.c +0 -37
@@ -64,31 +64,6 @@ static void test_varint_roundtrip(void) } } -static void test_common_prefix (void ) -{ -struct { -const char *a, *b; -int want; - } cases[] = { - {"abc" ,"ab" ,2 }, - {"" ,"abc" ,0 }, - {"abc" ,"abd" ,2 }, - {"abc" ,"pqr" ,0 }, - }; - -int i =0 ; -for (i =0 ; i <ARRAY_SIZE (cases); i++) { -struct strbuf a =STRBUF_INIT ; -struct strbuf b =STRBUF_INIT ; -strbuf_addstr (&a, cases[i].a); -strbuf_addstr (&b, cases[i].b); -EXPECT (common_prefix_size (&a, &b) == cases[i].want); - -strbuf_release (&a); -strbuf_release (&b); - } -} -static void set_hash (uint8_t *h,int j) {int i =0 ;
@@ -258,16 +233,6 @@ static void test_reftable_log_record_roundtrip(void)strbuf_release (&scratch); } -static void test_u24_roundtrip (void ) -{ -uint32_t in =0x112233 ; -uint8_t dest[3 ]; -uint32_t out; -put_be24 (dest, in); - out =get_be24 (dest); -EXPECT (in == out); -} -static void test_key_roundtrip (void ) {uint8_t buffer[1024 ] = {0 };
@@ -411,9 +376,7 @@ int record_test_main(int argc, const char *argv[])RUN_TEST (test_reftable_ref_record_roundtrip);RUN_TEST (test_varint_roundtrip);RUN_TEST (test_key_roundtrip); -RUN_TEST (test_common_prefix);RUN_TEST (test_reftable_obj_record_roundtrip);RUN_TEST (test_reftable_index_record_roundtrip); -RUN_TEST (test_u24_roundtrip);return 0 ; }
reftable/stack_test.c +0 -25
@@ -102,29 +102,6 @@ static void test_read_file(void) (void )remove (fn); } -static void test_parse_names (void ) -{ -char buf[] ="line\n" ; -char **names =NULL ; -parse_names (buf,strlen (buf), &names); - -EXPECT (NULL != names[0 ]); -EXPECT (0 ==strcmp (names[0 ],"line" )); -EXPECT (NULL == names[1 ]); -free_names (names); -} - -static void test_names_equal (void ) -{ -char *a[] = {"a" ,"b" ,"c" ,NULL }; -char *b[] = {"a" ,"b" ,"d" ,NULL }; -char *c[] = {"a" ,"b" ,NULL }; - -EXPECT (names_equal (a, a)); -EXPECT (!names_equal (a, b)); -EXPECT (!names_equal (a, c)); -} -static int write_test_ref (struct reftable_writer *wr,void *arg) {struct reftable_ref_record *ref = arg;
@@ -1048,8 +1025,6 @@ static void test_reftable_stack_compaction_concurrent_clean(void)int stack_test_main (int argc,const char *argv[]) {RUN_TEST (test_empty_add); -RUN_TEST (test_names_equal); -RUN_TEST (test_parse_names);RUN_TEST (test_read_file);RUN_TEST (test_reflog_expire);RUN_TEST (test_reftable_stack_add);
t/unit-tests/t-reftable-basics.c +65 -12
107 lines not on this page · raw message
Signature · 1 line
2.45.GIT
Quoted 6 lines · Chandra Pratap
In the recent codebase update (commit 8bf6fbd, 2023-12-09), a new unit testing framework written entirely in C was introduced to the Git project aimed at simplifying testing and reducing test run times.
Currently, tests for the raftable refs-backend are performed by a custom
s/raftable/reftable/
Quoted 3 lines
testing framework defined by reftable/test_framework.{c, h}. Port
reftable/basics_test.cto the unit testing framework and improve upon the ported test.
Re: [PATCH 1/2] t: move reftable/basics_test.c to the unit testing framework
In reply to Chandra PratapQuoted 8 lines · Chandra Pratap
t/unit-tests/t-reftable-basics.c renamed from reftable/basics_test.c +0
-0
t/unit-tests/t-reftable-basics.c line 7
Quoted 7 lines
t/unit-tests/t-reftable-basics.c renamed from reftable/basics_test.c +0
-7@@ -1,16 +1,6 @@ -/* -Copyright 2020 Google LLC - -Use of this source code is governed by a BSD-style -license that can be found in the LICENSE file or at -https://developers.google.com/open-source/licenses/bsd -*/
Are we sure it's Ok to remove the above Copyright? Or is it safer to just move it over (and perhaps add our own)?
Re: [PATCH 2/2] t: improve upon reftable/basics_test.c in the unit testing framework
In reply to Chandra PratapQuoted 5 lines · Chandra Pratap
Enhance the new test for reftable/basics.{c, h} in the unit testing framework. The enhancements include:
- Move tests for functions in reftable/basics.{c, h} fromreftable/record_test.candreftable/stack_test.cto the new unit test.
It might be easier for readers if one patch moved tests from reftable/record_test.c and a separate patch moved tests from reftable/stack_test.c.
Quoted 1 line
- Add tests for functions that are not currently tested, like
put_be16.
This could perhaps be done in a separate patch.
Quoted 1 line
- Improve the test-cases for the already existing tests.
Are these improvements to tests that were moved in patch 1/2 of this series? If that's the case, these improvements could be in a separate patch too.
Re: [PATCH 2/2] t: improve upon reftable/basics_test.c in the unit testing framework
Quoted 14 lines · Christian Couder
Quoted 5 lines · Chandra Pratap
Enhance the new test for reftable/basics.{c, h} in the unit testing framework. The enhancements include:
- Move tests for functions in reftable/basics.{c, h} fromreftable/record_test.candreftable/stack_test.cto the new unit test.It might be easier for readers if one patch moved tests from
reftable/record_test.cand a separate patch moved tests fromreftable/stack_test.c.Quoted 1 line
- Add tests for functions that are not currently tested, like
put_be16.
Quoted 7 lines
This could perhaps be done in a separate patch.
Quoted 1 line
- Improve the test-cases for the already existing tests.
Are these improvements to tests that were moved in patch 1/2 of this series? If that's the case, these improvements could be in a separate patch too.
Some of the test cases are extended to also cover additional edge cases. But I agree that this is easy to miss, and also think that this patch should be split up further.
Patrick
Re: [PATCH 1/2] t: move reftable/basics_test.c to the unit testing framework
In reply to Chandra PratapQuoted 8 lines · Chandra Pratap
t/unit-tests/t-reftable-basics.c renamed from reftable/basics_test.c +0
-5@@ -1,16 +1,6 @@ -/* -Copyright 2020 Google LLC - -Use of this source code is governed by a BSD-style -license that can be found in the LICENSE file or at
t/unit-tests/t-reftable-basics.c line 2
Quoted 10 lines
t/unit-tests/t-reftable-basics.c renamed from reftable/basics_test.c +2
-8-https://developers.google.com/open-source/licenses/bsd -*/ - -#include "system.h" - -#include "basics.h" -#include "test_framework.h" -#include "reftable-tests.h" +#include "test-lib.h" +#include "reftable/system.h"
There is no need to include "reftable/system.h" explicitly as it is already transitively included via "reftable/basics.h". The same should be true for all other reftable headers.
Patrick
Re: [PATCH 1/2] t: move reftable/basics_test.c to the unit testing framework
In reply to Christian CouderQuoted 13 lines · Christian Couder
Quoted 10 lines · Chandra Pratap
t/unit-tests/t-reftable-basics.c renamed from reftable/basics_test.c +0
-2@@ -1,16 +1,6 @@ -/* -Copyright 2020 Google LLC
Quoted 8 lines
t/unit-tests/t-reftable-basics.c line 7
Quoted 5 lines
t/unit-tests/t-reftable-basics.c renamed from reftable/basics_test.c +0
-5- -Use of this source code is governed by a BSD-style -license that can be found in the LICENSE file or at -https://developers.google.com/open-source/licenses/bsd -*/ Are we sure it's Ok to remove the above Copyright? Or is it safer to just move it over (and perhaps add our own)?
Good question indeed. We should retain the copyright header given that these source files have a different license compared to the rest of the codebase.
Patrick