Mercurial
diff mrjunejune/test/integration_test.c @ 128:7eb79fd91c7e
[Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Thu, 08 Jan 2026 19:20:56 -0800 |
| parents | e7899c93da77 |
| children | f3084bca7317 |
line wrap: on
line diff
--- a/mrjunejune/test/integration_test.c Thu Jan 08 18:05:47 2026 -0800 +++ b/mrjunejune/test/integration_test.c Thu Jan 08 19:20:56 2026 -0800 @@ -1,4 +1,4 @@ -#include "seobeo/test/test.h" +#include "mrjunejune/test/test.h" // Test case structure typedef struct { @@ -10,6 +10,37 @@ size_t response_len; } TestCase; +void debug_diff(const char *expected, const char *actual) +{ + printf("\n--- DIFF (Expected vs Actual) ---\n"); + + // Create copies to use with strtok (strtok modifies the string) + char *exp_copy = strdup(expected); + char *act_copy = strdup(actual); + + char *exp_line = strtok(exp_copy, "\n"); + char *act_line = strtok(act_copy, "\n"); + + int line_num = 1; + while (exp_line != NULL || act_line != NULL) { + if (exp_line && act_line && strcmp(exp_line, act_line) == 0) { + // Lines match - optional: print nothing or a dot + } else { + printf("Line %d mismatch:\n", line_num); + printf(" EXP: [%s]\n", exp_line ? exp_line : "(end of string)"); + printf(" ACT: [%s]\n", act_line ? act_line : "(end of string)"); + printf(" -----------------------------------\n"); + } + + exp_line = strtok(NULL, "\n"); + act_line = strtok(NULL, "\n"); + line_num++; + } + + free(exp_copy); + free(act_copy); +} + // Helper: Convert URL path to filename // "/" -> "root.snapshot" // "/index.html" -> "index.html.snapshot" @@ -149,6 +180,7 @@ { printf(" ✗ Response does not match expected snapshot\n"); printf(" Expected file: %s\n", test->expected_file_path); + debug_diff(p_resp->body, test->expected_content); Seobeo_Client_Response_Destroy(p_resp); Seobeo_Client_Request_Destroy(p_req); return -1; @@ -297,60 +329,6 @@ return 0; } -pid_t start_test_server(const char *server_binary) -{ - pid_t server_pid = fork(); - - if (server_pid < 0) - { - perror("fork"); - return -1; - } - - if (server_pid == 0) - { - printf("Starting server on port %s...\n", TEST_PORT); - execl(server_binary, server_binary, NULL); - perror("execl failed"); - exit(1); - } - - printf("Server started (PID: %d)\n", server_pid); - - usleep(100000); - int status; - pid_t result = waitpid(server_pid, &status, WNOHANG); - if (result != 0) - { - if (WIFEXITED(status)) - { - fprintf(stderr, "Server exited immediately with code: %d\n", WEXITSTATUS(status)); - } - else if (WIFSIGNALED(status)) - { - fprintf(stderr, "Server was killed by signal: %d\n", WTERMSIG(status)); - } - return -1; - } - - sleep(2); - printf("Server ready\n\n"); - - return server_pid; -} - -// Helper: Stop test server -void stop_test_server(pid_t server_pid) -{ - if (server_pid > 0) - { - printf("\nStopping server (PID: %d)...\n", server_pid); - kill(server_pid, SIGTERM); - waitpid(server_pid, NULL, 0); - printf("Server stopped\n"); - } -} - // Helper: Initialize test case with snapshot file void init_test_case(TestCase *test) { @@ -413,6 +391,7 @@ {"/tools", 200, NULL, NULL, NULL, 0}, {"/tools/markdown_to_html", 200, NULL, NULL, NULL, 0}, {"/tools/file_converter", 200, NULL, NULL, NULL, 0}, + {"/talk", 200, NULL, NULL, NULL, 0}, }; int num_success_tests = sizeof(success_tests) / sizeof(success_tests[0]);