]> Kevux Git Server - fll/commitdiff
Update: Directory tests following recent changes.
authorKevin Day <thekevinday@gmail.com>
Fri, 15 Apr 2022 21:01:40 +0000 (16:01 -0500)
committerKevin Day <thekevinday@gmail.com>
Fri, 15 Apr 2022 21:01:40 +0000 (16:01 -0500)
The change from a7d607fecf1fdd5eff36d53b6108b6cc316bdf1f didn't include test updates.
The tests need to provide properly dynamically allocated structure for the mocks so that the deallocation internal to the called functions work as expected.

level_0/f_directory/tests/unit/c/test-directory-list.c

index f4f127c033b4967a30c8648fb14ac21313d19ea1..64a16392c336f9e9c64be9f127b51b373defd801 100644 (file)
@@ -69,9 +69,10 @@ void test__f_directory_list__returns_directory_empty(void **state) {
   const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
 
   {
-    struct dirent *directories[0];
+    struct dirent **directories;
 
-    memset(directories, 0, sizeof(struct dirent *));
+    // The scandir() allocates each struct dirent.
+    directories = malloc(sizeof(struct dirent *));
 
     will_return(__wrap_scandir, false);
     will_return(__wrap_scandir, directories);
@@ -91,9 +92,10 @@ void test__f_directory_list__works(void **state) {
   const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
 
   {
-    struct dirent *directories[1];
+    struct dirent **directories;
 
     // The scandir() allocates each struct dirent.
+    directories = malloc(sizeof(struct dirent *));
     directories[0] = (struct dirent *) malloc(sizeof(struct dirent));
 
     memset(directories[0], 0, sizeof(struct dirent));