Message ID | 20240904150132.11567-4-chandrapratap3519@gmail.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | t: port reftable/stack_test.c to the unit testing framework | expand |
On Wed, Sep 04, 2024 at 08:08:03PM +0530, Chandra Pratap wrote: > Git's tempfile API defined by $GIT_DIR/tempfile.{c,h} provides > a unified interface for tempfile operations. Since reftable/stack.c > uses this API for all its tempfile needs instead of raw functions > like mkstemp(), make the ported stack test strictly use Git's > tempfile API as well. I don't quite think that this is sufficient motivation. The real benefit is that we know to clean up the tempfile in case the test fails because it gets registered and pruned via a signal handler. Patrick > Mentored-by: Patrick Steinhardt <ps@pks.im> > Mentored-by: Christian Couder <chriscool@tuxfamily.org> > Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com> > --- > t/unit-tests/t-reftable-stack.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/t/unit-tests/t-reftable-stack.c b/t/unit-tests/t-reftable-stack.c > index c74660a1e2..8047e25c48 100644 > --- a/t/unit-tests/t-reftable-stack.c > +++ b/t/unit-tests/t-reftable-stack.c > @@ -76,7 +76,8 @@ static char *get_tmp_dir(int linenumber) > static void t_read_file(void) > { > char *fn = get_tmp_template(__LINE__); > - int fd = mkstemp(fn); > + struct tempfile *tmp = mks_tempfile(fn); > + int fd = get_tempfile_fd(tmp); > char out[1024] = "line1\n\nline2\nline3"; > int n, err; > char **names = NULL; > @@ -95,6 +96,7 @@ static void t_read_file(void) > check_str(want[i], names[i]); > free_names(names); > (void) remove(fn); > + delete_tempfile(&tmp); > } > > static int write_test_ref(struct reftable_writer *wr, void *arg) > -- > 2.45.GIT >
diff --git a/t/unit-tests/t-reftable-stack.c b/t/unit-tests/t-reftable-stack.c index c74660a1e2..8047e25c48 100644 --- a/t/unit-tests/t-reftable-stack.c +++ b/t/unit-tests/t-reftable-stack.c @@ -76,7 +76,8 @@ static char *get_tmp_dir(int linenumber) static void t_read_file(void) { char *fn = get_tmp_template(__LINE__); - int fd = mkstemp(fn); + struct tempfile *tmp = mks_tempfile(fn); + int fd = get_tempfile_fd(tmp); char out[1024] = "line1\n\nline2\nline3"; int n, err; char **names = NULL; @@ -95,6 +96,7 @@ static void t_read_file(void) check_str(want[i], names[i]); free_names(names); (void) remove(fn); + delete_tempfile(&tmp); } static int write_test_ref(struct reftable_writer *wr, void *arg)
Git's tempfile API defined by $GIT_DIR/tempfile.{c,h} provides a unified interface for tempfile operations. Since reftable/stack.c uses this API for all its tempfile needs instead of raw functions like mkstemp(), make the ported stack test strictly use Git's tempfile API as well. Mentored-by: Patrick Steinhardt <ps@pks.im> Mentored-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com> --- t/unit-tests/t-reftable-stack.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)