Skip to content

Commit 6c762a4

Browse files
Update mock.c
1 parent 9b8edc1 commit 6c762a4

File tree

1 file changed

+3
-29
lines changed

1 file changed

+3
-29
lines changed

code/logic/mock.c

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -135,27 +135,16 @@ void fossil_mock_print(fossil_mock_calllist_t *list) {
135135
}
136136
}
137137

138-
/**
139-
* Captures the output of a function to a buffer for testing purposes.
140-
*
141-
* @param buffer The buffer to store the captured output.
142-
* @param size The size of the buffer.
143-
* @param function The function whose output is to be captured.
144-
* @param ... The arguments to pass to the function.
145-
* @return The number of characters captured.
146-
*/
147-
int fossil_mock_capture_output(char *buffer, size_t size, void (*function)(void), ...) {
138+
int fossil_mock_capture_output(char *buffer, size_t size, void (*function)(void)) {
148139
if (!buffer || size == 0 || !function) {
149140
return -1;
150141
}
151142

152-
// Create a temporary file to capture stdout
153143
FILE *temp_file = tmpfile();
154144
if (!temp_file) {
155145
return -1;
156146
}
157147

158-
// Redirect stdout to the temporary file
159148
int original_stdout_fd = dup(STDOUT_FILENO);
160149
if (original_stdout_fd == -1) {
161150
fclose(temp_file);
@@ -168,35 +157,20 @@ int fossil_mock_capture_output(char *buffer, size_t size, void (*function)(void)
168157
return -1;
169158
}
170159

171-
// Call the function with variable arguments
172-
va_list args;
173-
va_start(args, function);
174-
function();
175-
va_end(args);
160+
function(); // no arguments passed
176161

177-
// Restore stdout
178162
fflush(stdout);
179163
dup2(original_stdout_fd, STDOUT_FILENO);
180164
close(original_stdout_fd);
181165

182-
// Rewind the temporary file and read its contents into the buffer
183166
rewind(temp_file);
184167
size_t read_size = fread(buffer, 1, size - 1, temp_file);
185-
buffer[read_size] = '\0'; // Null-terminate the buffer
168+
buffer[read_size] = '\0';
186169

187-
// Close the temporary file
188170
fclose(temp_file);
189-
190171
return (int)read_size;
191172
}
192173

193-
/**
194-
* Compares the captured output with the expected output.
195-
*
196-
* @param captured The captured output.
197-
* @param expected The expected output.
198-
* @return True if the captured output matches the expected output, false otherwise.
199-
*/
200174
bool fossil_mock_compare_output(const char *captured, const char *expected) {
201175
if (!captured || !expected) {
202176
return false;

0 commit comments

Comments
 (0)