diff --git a/.github/workflows/meson_ci.yml b/.github/workflows/meson_ci.yml index 16372d3..ba38bbf 100644 --- a/.github/workflows/meson_ci.yml +++ b/.github/workflows/meson_ci.yml @@ -5,16 +5,20 @@ on: paths: - "**.c" - "**.h" - - "**.kt" + - "**.cpp" + - "**.hpp" - "**.py" - - "meson.**" + - "**.build" + - "**.options" pull_request: paths: - "**.c" - "**.h" - - "**.kt" + - "**.cpp" + - "**.hpp" - "**.py" - - "meson.**" + - "**.build" + - "**.options" jobs: build_msvc: diff --git a/code/logic/fossil/io/framework.h b/code/logic/fossil/io/framework.h index 838cd3e..397642d 100644 --- a/code/logic/fossil/io/framework.h +++ b/code/logic/fossil/io/framework.h @@ -14,6 +14,7 @@ #ifndef FOSSIL_IO_FRAMEWORK_H #define FOSSIL_IO_FRAMEWORK_H +// Include the necessary headers #include "output.h" #include "input.h" #include "error.h" diff --git a/code/logic/soap.c b/code/logic/soap.c index 81afd11..93df393 100644 --- a/code/logic/soap.c +++ b/code/logic/soap.c @@ -106,7 +106,7 @@ static void replace_substring_case_insensitive(char *str, const char *old_substr } void fossil_soap_sanitize(char *input) { - if (input == NULL) return; + if (input == NULL || *input == '\0') return; // Perform single-threaded sanitization for (size_t i = 0; i < sizeof(offensive_words) / sizeof(offensive_words[0]); ++i) { @@ -118,7 +118,7 @@ void fossil_soap_sanitize(char *input) { // Function to check if a word is an offensive word or phrase int32_t fossil_soap_is_offensive(const char *word) { - if (word == NULL) return EXIT_SUCCESS; + if (word == NULL || *word == '\0') return EXIT_SUCCESS; for (size_t i = 0; i < sizeof(offensive_words) / sizeof(offensive_words[0]); ++i) { if (strcasecmp(word, offensive_words[i]) == 0) { @@ -130,7 +130,7 @@ int32_t fossil_soap_is_offensive(const char *word) { // Function to get the number of offensive words found in a string int32_t fossil_soap_count_offensive(const char *input) { - if (input == NULL) return 0; + if (input == NULL || *input == '\0') return 0; int count = 0; char *copy = _custom_fossil_strdup(input); diff --git a/code/tests/test_soap.c b/code/tests/cases/test_soap.c similarity index 54% rename from code/tests/test_soap.c rename to code/tests/cases/test_soap.c index 84cc156..0f166a9 100644 --- a/code/tests/test_soap.c +++ b/code/tests/cases/test_soap.c @@ -11,18 +11,39 @@ * Copyright (C) 2024 Fossil Logic. All rights reserved. * ----------------------------------------------------------------------------- */ -#include -#include -#include +#include #include "fossil/io/framework.h" +// * * * * * * * * * * * * * * * * * * * * * * * * +// * Fossil Logic Test Utilites +// * * * * * * * * * * * * * * * * * * * * * * * * +// Setup steps for things like test fixtures and +// mock objects are set here. +// * * * * * * * * * * * * * * * * * * * * * * * * + +// Define the test suite and add test cases +FOSSIL_TEST_SUITE(c_soap_suite); + +// Setup function for the test suite +FOSSIL_SETUP(c_soap_suite) { + // Setup code here +} + +// Teardown function for the test suite +FOSSIL_TEARDOWN(c_soap_suite) { + // Teardown code here +} // * * * * * * * * * * * * * * * * * * * * * * * * -// * Fossil Logic Test +// * Fossil Logic Test Cases +// * * * * * * * * * * * * * * * * * * * * * * * * +// The test cases below are provided as samples, inspired +// by the Meson build system's approach of using test cases +// as samples for library usage. // * * * * * * * * * * * * * * * * * * * * * * * * -FOSSIL_TEST(test_fossil_soap_sanitize) { +FOSSIL_TEST_CASE(c_test_soap_sanitize) { char input[] = "This is a test with curse1 and racist_phrase1."; char expected[] = "This is a test with *** and ***."; @@ -31,13 +52,13 @@ FOSSIL_TEST(test_fossil_soap_sanitize) { ASSUME_ITS_EQUAL_CSTR(expected, input); } -FOSSIL_TEST(test_fossil_soap_is_offensive) { +FOSSIL_TEST_CASE(c_test_soap_is_offensive) { ASSUME_ITS_TRUE(fossil_soap_is_offensive("curse1")); ASSUME_ITS_TRUE(fossil_soap_is_offensive("racist_phrase2")); ASSUME_ITS_FALSE(fossil_soap_is_offensive("non_offensive_word")); } -FOSSIL_TEST(test_fossil_soap_count_offensive) { +FOSSIL_TEST_CASE(c_test_soap_count_offensive) { char input[] = "This is a test with curse1 and racist_phrase1"; ASSUME_ITS_EQUAL_I32(2, fossil_soap_count_offensive(input)); } @@ -47,7 +68,9 @@ FOSSIL_TEST(test_fossil_soap_count_offensive) { // * * * * * * * * * * * * * * * * * * * * * * * * FOSSIL_TEST_GROUP(c_soap_tests) { - ADD_TEST(test_fossil_soap_sanitize); - ADD_TEST(test_fossil_soap_is_offensive); - ADD_TEST(test_fossil_soap_count_offensive); + FOSSIL_TEST_ADD(c_soap_suite, c_test_soap_sanitize); + FOSSIL_TEST_ADD(c_soap_suite, c_test_soap_is_offensive); + FOSSIL_TEST_ADD(c_soap_suite, c_test_soap_count_offensive); + + FOSSIL_TEST_REGISTER(c_soap_suite); } diff --git a/code/tests/cases/test_soap.cpp b/code/tests/cases/test_soap.cpp new file mode 100644 index 0000000..773fcac --- /dev/null +++ b/code/tests/cases/test_soap.cpp @@ -0,0 +1,76 @@ +/* + * ----------------------------------------------------------------------------- + * Project: Fossil Logic + * + * This file is part of the Fossil Logic project, which aims to develop high- + * performance, cross-platform applications and libraries. The code contained + * herein is subject to the terms and conditions defined in the project license. + * + * Author: Michael Gene Brockus (Dreamer) + * + * Copyright (C) 2024 Fossil Logic. All rights reserved. + * ----------------------------------------------------------------------------- + */ +#include + +#include "fossil/io/framework.h" + +// * * * * * * * * * * * * * * * * * * * * * * * * +// * Fossil Logic Test Utilites +// * * * * * * * * * * * * * * * * * * * * * * * * +// Setup steps for things like test fixtures and +// mock objects are set here. +// * * * * * * * * * * * * * * * * * * * * * * * * + +// Define the test suite and add test cases +FOSSIL_TEST_SUITE(cpp_soap_suite); + +// Setup function for the test suite +FOSSIL_SETUP(cpp_soap_suite) { + // Setup code here +} + +// Teardown function for the test suite +FOSSIL_TEARDOWN(cpp_soap_suite) { + // Teardown code here +} + +// * * * * * * * * * * * * * * * * * * * * * * * * +// * Fossil Logic Test Cases +// * * * * * * * * * * * * * * * * * * * * * * * * +// The test cases below are provided as samples, inspired +// by the Meson build system's approach of using test cases +// as samples for library usage. +// * * * * * * * * * * * * * * * * * * * * * * * * + +FOSSIL_TEST_CASE(cpp_test_soap_sanitize) { + char input[] = "This is a test with curse1 and racist_phrase1."; + char expected[] = "This is a test with *** and ***."; + + fossil_soap_sanitize(input); + + ASSUME_ITS_EQUAL_CSTR(expected, input); +} + +FOSSIL_TEST_CASE(cpp_test_soap_is_offensive) { + ASSUME_ITS_TRUE(fossil_soap_is_offensive("curse1")); + ASSUME_ITS_TRUE(fossil_soap_is_offensive("racist_phrase2")); + ASSUME_ITS_FALSE(fossil_soap_is_offensive("non_offensive_word")); +} + +FOSSIL_TEST_CASE(cpp_test_soap_count_offensive) { + char input[] = "This is a test with curse1 and racist_phrase1"; + ASSUME_ITS_EQUAL_I32(2, fossil_soap_count_offensive(input)); +} + +// * * * * * * * * * * * * * * * * * * * * * * * * +// * Fossil Logic Test Pool +// * * * * * * * * * * * * * * * * * * * * * * * * + +FOSSIL_TEST_GROUP(cpp_soap_tests) { + FOSSIL_TEST_ADD(cpp_soap_suite, cpp_test_soap_sanitize); + FOSSIL_TEST_ADD(cpp_soap_suite, cpp_test_soap_is_offensive); + FOSSIL_TEST_ADD(cpp_soap_suite, cpp_test_soap_count_offensive); + + FOSSIL_TEST_REGISTER(cpp_soap_suite); +} diff --git a/code/tests/cases/test_stream.c b/code/tests/cases/test_stream.c new file mode 100644 index 0000000..f6dec5f --- /dev/null +++ b/code/tests/cases/test_stream.c @@ -0,0 +1,119 @@ +/* + * ----------------------------------------------------------------------------- + * Project: Fossil Logic + * + * This file is part of the Fossil Logic project, which aims to develop high- + * performance, cross-platform applications and libraries. The code contained + * herein is subject to the terms and conditions defined in the project license. + * + * Author: Michael Gene Brockus (Dreamer) + * + * Copyright (C) 2024 Fossil Logic. All rights reserved. + * ----------------------------------------------------------------------------- + */ +#include + +#include "fossil/io/framework.h" + + +// * * * * * * * * * * * * * * * * * * * * * * * * +// * Fossil Logic Test Utilites +// * * * * * * * * * * * * * * * * * * * * * * * * +// Setup steps for things like test fixtures and +// mock objects are set here. +// * * * * * * * * * * * * * * * * * * * * * * * * + +// Define the test suite and add test cases +FOSSIL_TEST_SUITE(c_stream_suite); +fossil_fstream_t c_stream; + +// Setup function for the test suite +FOSSIL_SETUP(c_stream_suite) { + // Setup code here +} + +// Teardown function for the test suite +FOSSIL_TEARDOWN(c_stream_suite) { + // Teardown code here +} + +// * * * * * * * * * * * * * * * * * * * * * * * * +// * Fossil Logic Test Cases +// * * * * * * * * * * * * * * * * * * * * * * * * +// The test cases below are provided as samples, inspired +// by the Meson build system's approach of using test cases +// as samples for library usage. +// * * * * * * * * * * * * * * * * * * * * * * * * + +FOSSIL_TEST_CASE(c_test_stream_let_write_and_read_file) { + const char *filename = "testfile.txt"; + const char *content = "This is a test."; + + // Write data to the file + ASSUME_ITS_EQUAL_I32(0, fossil_fstream_open(&c_stream, filename, "w")); + fossil_fstream_write(&c_stream, content, strlen(content), 1); + fossil_fstream_close(&c_stream); + + // Read data from the file + char buffer[1024]; + ASSUME_ITS_EQUAL_I32(0, fossil_fstream_open(&c_stream, filename, "r")); + fossil_fstream_read(&c_stream, buffer, sizeof(buffer), 1); + fossil_fstream_close(&c_stream); +} + +FOSSIL_TEST_CASE(c_test_stream_let_open_and_close_file) { + const char *filename = "testfile.txt"; + + // Open the file + ASSUME_ITS_EQUAL_I32(0, fossil_fstream_open(&c_stream, filename, "w")); + fossil_fstream_close(&c_stream); +} + +FOSSIL_TEST_CASE(c_test_stream_multiple_files) { + const char *filename1 = "testfile1.txt"; + const char *filename2 = "testfile2.txt"; + + // Open the first file + ASSUME_ITS_EQUAL_I32(0, fossil_fstream_open(&c_stream, filename1, "w")); + fossil_fstream_close(&c_stream); + + // Open the second file + ASSUME_ITS_EQUAL_I32(0, fossil_fstream_open(&c_stream, filename2, "w")); + fossil_fstream_close(&c_stream); +} + +FOSSIL_TEST_CASE(c_test_stream_seek_and_tell) { + const char *filename = "testfile.txt"; + const char *content = "This is a test."; + + // Write data to the file + ASSUME_ITS_EQUAL_I32(0, fossil_fstream_open(&c_stream, filename, "w")); + fossil_fstream_write(&c_stream, content, strlen(content), 1); + fossil_fstream_close(&c_stream); + + // Open the file + ASSUME_ITS_EQUAL_I32(0, fossil_fstream_open(&c_stream, filename, "r")); + + // Seek to the end of the file + fossil_fstream_seek(&c_stream, 0, SEEK_END); + + // Get the current position + long position = fossil_fstream_tell(&c_stream); + + ASSUME_ITS_TRUE(position > 0); + + // Close the file + fossil_fstream_close(&c_stream); +} + +// * * * * * * * * * * * * * * * * * * * * * * * * +// * Fossil Logic Test Pool +// * * * * * * * * * * * * * * * * * * * * * * * * + +FOSSIL_TEST_GROUP(c_file_tests) { + FOSSIL_TEST_ADD(c_stream_suite, c_test_stream_let_write_and_read_file); + FOSSIL_TEST_ADD(c_stream_suite, c_test_stream_let_open_and_close_file); + FOSSIL_TEST_ADD(c_stream_suite, c_test_stream_multiple_files); + + FOSSIL_TEST_REGISTER(c_stream_suite); +} diff --git a/code/tests/cases/test_stream.cpp b/code/tests/cases/test_stream.cpp new file mode 100644 index 0000000..a9cc502 --- /dev/null +++ b/code/tests/cases/test_stream.cpp @@ -0,0 +1,119 @@ +/* + * ----------------------------------------------------------------------------- + * Project: Fossil Logic + * + * This file is part of the Fossil Logic project, which aims to develop high- + * performance, cross-platform applications and libraries. The code contained + * herein is subject to the terms and conditions defined in the project license. + * + * Author: Michael Gene Brockus (Dreamer) + * + * Copyright (C) 2024 Fossil Logic. All rights reserved. + * ----------------------------------------------------------------------------- + */ +#include + +#include "fossil/io/framework.h" + + +// * * * * * * * * * * * * * * * * * * * * * * * * +// * Fossil Logic Test Utilites +// * * * * * * * * * * * * * * * * * * * * * * * * +// Setup steps for things like test fixtures and +// mock objects are set here. +// * * * * * * * * * * * * * * * * * * * * * * * * + +// Define the test suite and add test cases +FOSSIL_TEST_SUITE(cpp_stream_suite); +fossil_fstream_t cpp_stream; + +// Setup function for the test suite +FOSSIL_SETUP(cpp_stream_suite) { + // Setup code here +} + +// Teardown function for the test suite +FOSSIL_TEARDOWN(cpp_stream_suite) { + // Teardown code here +} + +// * * * * * * * * * * * * * * * * * * * * * * * * +// * Fossil Logic Test Cases +// * * * * * * * * * * * * * * * * * * * * * * * * +// The test cases below are provided as samples, inspired +// by the Meson build system's approach of using test cases +// as samples for library usage. +// * * * * * * * * * * * * * * * * * * * * * * * * + +FOSSIL_TEST_CASE(cpp_test_stream_let_write_and_read_file) { + const char *filename = "testfile.txt"; + const char *content = "This is a test."; + + // Write data to the file + ASSUME_ITS_EQUAL_I32(0, fossil_fstream_open(&cpp_stream, filename, "w")); + fossil_fstream_write(&cpp_stream, content, strlen(content), 1); + fossil_fstream_close(&cpp_stream); + + // Read data from the file + char buffer[1024]; + ASSUME_ITS_EQUAL_I32(0, fossil_fstream_open(&cpp_stream, filename, "r")); + fossil_fstream_read(&cpp_stream, buffer, sizeof(buffer), 1); + fossil_fstream_close(&cpp_stream); +} + +FOSSIL_TEST_CASE(cpp_test_stream_let_open_and_close_file) { + const char *filename = "testfile.txt"; + + // Open the file + ASSUME_ITS_EQUAL_I32(0, fossil_fstream_open(&cpp_stream, filename, "w")); + fossil_fstream_close(&cpp_stream); +} + +FOSSIL_TEST_CASE(cpp_test_stream_multiple_files) { + const char *filename1 = "testfile1.txt"; + const char *filename2 = "testfile2.txt"; + + // Open the first file + ASSUME_ITS_EQUAL_I32(0, fossil_fstream_open(&cpp_stream, filename1, "w")); + fossil_fstream_close(&cpp_stream); + + // Open the second file + ASSUME_ITS_EQUAL_I32(0, fossil_fstream_open(&cpp_stream, filename2, "w")); + fossil_fstream_close(&cpp_stream); +} + +FOSSIL_TEST_CASE(cpp_test_stream_seek_and_tell) { + const char *filename = "testfile.txt"; + const char *content = "This is a test."; + + // Write data to the file + ASSUME_ITS_EQUAL_I32(0, fossil_fstream_open(&cpp_stream, filename, "w")); + fossil_fstream_write(&cpp_stream, content, strlen(content), 1); + fossil_fstream_close(&cpp_stream); + + // Open the file + ASSUME_ITS_EQUAL_I32(0, fossil_fstream_open(&cpp_stream, filename, "r")); + + // Seek to the end of the file + fossil_fstream_seek(&cpp_stream, 0, SEEK_END); + + // Get the current position + long position = fossil_fstream_tell(&cpp_stream); + + ASSUME_ITS_TRUE(position > 0); + + // Close the file + fossil_fstream_close(&cpp_stream); +} + +// * * * * * * * * * * * * * * * * * * * * * * * * +// * Fossil Logic Test Pool +// * * * * * * * * * * * * * * * * * * * * * * * * + +FOSSIL_TEST_GROUP(cpp_file_tests) { + FOSSIL_TEST_ADD(cpp_stream_suite, cpp_test_stream_let_write_and_read_file); + FOSSIL_TEST_ADD(cpp_stream_suite, cpp_test_stream_let_open_and_close_file); + FOSSIL_TEST_ADD(cpp_stream_suite, cpp_test_stream_multiple_files); + + FOSSIL_TEST_REGISTER(cpp_stream_suite); +} diff --git a/code/tests/meson.build b/code/tests/meson.build index fd151d0..8e00f42 100644 --- a/code/tests/meson.build +++ b/code/tests/meson.build @@ -1,21 +1,15 @@ if get_option('with_test').enabled() run_command(['python3', 'tools' / 'generate-runner.py'], check: true) - test_src = ['unit_runner.c'] - test_cubes = [ - 'input', 'soap', 'stream', - ] + test_c = ['unit_runner.c'] + test_cases = ['stream', 'soap'] - foreach cube : test_cubes - test_src += ['test_' + cube + '.c'] + foreach cases : test_cases + test_c += ['cases' / 'test_' + cases + '.c'] + test_c += ['cases' / 'test_' + cases + '.cpp'] endforeach - pizza = executable('runner', test_src, - include_directories: dir, - dependencies: [ - dependency('fossil-test'), - dependency('fossil-mock'), - fossil_io_dep]) + pizza_c = executable('testbed-c', test_c, include_directories: dir, dependencies: [fossil_io_dep, dependency('fossil-test')]) - test('xunit_tests', pizza) # Renamed the test target for clarity + test('fossil testing C', pizza_c) endif \ No newline at end of file diff --git a/code/tests/test_input.c b/code/tests/test_input.c deleted file mode 100644 index 926f740..0000000 --- a/code/tests/test_input.c +++ /dev/null @@ -1,101 +0,0 @@ -/* - * ----------------------------------------------------------------------------- - * Project: Fossil Logic - * - * This file is part of the Fossil Logic project, which aims to develop high- - * performance, cross-platform applications and libraries. The code contained - * herein is subject to the terms and conditions defined in the project license. - * - * Author: Michael Gene Brockus (Dreamer) - * - * Copyright (C) 2024 Fossil Logic. All rights reserved. - * ----------------------------------------------------------------------------- - */ -#include -#include -#include - -#include "fossil/io/framework.h" - -#ifdef _WIN32 -// For Windows, use tmpfile and fwrite to simulate input -FILE *create_mock_input(const char *input) { - FILE *mock_input = tmpfile(); - fwrite(input, sizeof(char), strlen(input), mock_input); - rewind(mock_input); - return mock_input; -} -#else -// For Unix-like systems, use fmemopen -FILE *create_mock_input(const char *input) { - return fmemopen((void *)input, strlen(input), "r"); -} -#endif - -// * * * * * * * * * * * * * * * * * * * * * * * * -// * Fossil Logic Test -// * * * * * * * * * * * * * * * * * * * * * * * * - -FOSSIL_TEST(test_fossil_io_gets) { - const char *input = "Hello, World!\n"; - FILE *mock_input = create_mock_input(input); - char buf[50]; - - // Pass the mock input stream directly to the function - char *result = fossil_io_gets_from_stream(buf, sizeof(buf), mock_input); - ASSUME_NOT_CNULL(result); - printf("buf: %s\n", buf); - ASSUME_ITS_EQUAL_CSTR("Hello, World!", buf); - - fclose(mock_input); -} - -FOSSIL_TEST(test_fossil_io_gets_buffer_too_small) { - const char *input = "Hello, World!\n"; - FILE *mock_input = create_mock_input(input); - char buf[5]; // Buffer smaller than the input - - // Pass the mock input stream directly to the function - char *result = fossil_io_gets_from_stream(buf, sizeof(buf), mock_input); - ASSUME_NOT_CNULL(result); - printf("buf: %s\n", buf); - ASSUME_ITS_EQUAL_CSTR("Hell", buf); // Only part of the input should fit - - fclose(mock_input); -} - -FOSSIL_TEST(test_fossil_io_gets_with_dialog) { - const char *input = "Hello, Dialog!\n"; - FILE *mock_input = create_mock_input(input); - char buf[50]; - const char *dialog = "Please enter input: "; - - // Simulate dialog display and read input from the mock stream - printf("%s", dialog); - char *result = fossil_io_gets_from_stream(buf, sizeof(buf), mock_input); - ASSUME_NOT_CNULL(result); - ASSUME_ITS_EQUAL_CSTR("Hello, Dialog!", buf); - - fclose(mock_input); -} - -FOSSIL_TEST(test_fossil_io_gets_with_dialog_empty_buffer) { - const char *dialog = "Please enter input: "; - char buf[1]; // Buffer size is too small to read anything - - // Simulate dialog display and attempt to read input - printf("%s", dialog); - char *result = fossil_io_gets_from_stream(buf, sizeof(buf), stdin); - ASSUME_NOT_CNULL(result); // Should be NULL as buffer size is insufficient -} - -// * * * * * * * * * * * * * * * * * * * * * * * * -// * Fossil Logic Test Pool -// * * * * * * * * * * * * * * * * * * * * * * * * - -FOSSIL_TEST_GROUP(c_input_tests) { - ADD_TEST(test_fossil_io_gets); - ADD_TEST(test_fossil_io_gets_buffer_too_small); - ADD_TEST(test_fossil_io_gets_with_dialog); - ADD_TEST(test_fossil_io_gets_with_dialog_empty_buffer); -} diff --git a/code/tests/test_stream.c b/code/tests/test_stream.c deleted file mode 100644 index 604e74a..0000000 --- a/code/tests/test_stream.c +++ /dev/null @@ -1,97 +0,0 @@ -/* - * ----------------------------------------------------------------------------- - * Project: Fossil Logic - * - * This file is part of the Fossil Logic project, which aims to develop high- - * performance, cross-platform applications and libraries. The code contained - * herein is subject to the terms and conditions defined in the project license. - * - * Author: Michael Gene Brockus (Dreamer) - * - * Copyright (C) 2024 Fossil Logic. All rights reserved. - * ----------------------------------------------------------------------------- - */ -#include -#include -#include - -#include "fossil/io/framework.h" - -FOSSIL_TEST_DATA(StreamTestData) { - fossil_fstream_t stream; -} io; - -// * * * * * * * * * * * * * * * * * * * * * * * * -// * Fossil Logic Test -// * * * * * * * * * * * * * * * * * * * * * * * * - -FOSSIL_TEST(stream_let_write_and_read_file) { - const char *filename = "testfile.txt"; - const char *content = "This is a test."; - - // Write data to the file - ASSUME_ITS_EQUAL_I32(0, fossil_fstream_open(&io.stream, filename, "w")); - fossil_fstream_write(&io.stream, content, strlen(content), 1); - fossil_fstream_close(&io.stream); - - // Read data from the file - char buffer[1024]; - ASSUME_ITS_EQUAL_I32(0, fossil_fstream_open(&io.stream, filename, "r")); - fossil_fstream_read(&io.stream, buffer, sizeof(buffer), 1); - fossil_fstream_close(&io.stream); -} - -FOSSIL_TEST(stream_let_open_and_close_file) { - const char *filename = "testfile.txt"; - - // Open the file - ASSUME_ITS_EQUAL_I32(0, fossil_fstream_open(&io.stream, filename, "w")); - fossil_fstream_close(&io.stream); -} - -FOSSIL_TEST(stream_multiple_files) { - const char *filename1 = "testfile1.txt"; - const char *filename2 = "testfile2.txt"; - - // Open the first file - ASSUME_ITS_EQUAL_I32(0, fossil_fstream_open(&io.stream, filename1, "w")); - fossil_fstream_close(&io.stream); - - // Open the second file - ASSUME_ITS_EQUAL_I32(0, fossil_fstream_open(&io.stream, filename2, "w")); - fossil_fstream_close(&io.stream); -} - -FOSSIL_TEST(stream_seek_and_tell) { - const char *filename = "testfile.txt"; - const char *content = "This is a test."; - - // Write data to the file - ASSUME_ITS_EQUAL_I32(0, fossil_fstream_open(&io.stream, filename, "w")); - fossil_fstream_write(&io.stream, content, strlen(content), 1); - fossil_fstream_close(&io.stream); - - // Open the file - ASSUME_ITS_EQUAL_I32(0, fossil_fstream_open(&io.stream, filename, "r")); - - // Seek to the end of the file - fossil_fstream_seek(&io.stream, 0, SEEK_END); - - // Get the current position - long position = fossil_fstream_tell(&io.stream); - - ASSUME_ITS_TRUE(position > 0); - - // Close the file - fossil_fstream_close(&io.stream); -} - -// * * * * * * * * * * * * * * * * * * * * * * * * -// * Fossil Logic Test Pool -// * * * * * * * * * * * * * * * * * * * * * * * * - -FOSSIL_TEST_GROUP(c_file_tests) { - ADD_TEST(stream_let_write_and_read_file); - ADD_TEST(stream_let_open_and_close_file); - ADD_TEST(stream_multiple_files); -} diff --git a/code/tests/tools/generate-runner.py b/code/tests/tools/generate-runner.py index cdc3e06..848b24e 100644 --- a/code/tests/tools/generate-runner.py +++ b/code/tests/tools/generate-runner.py @@ -4,15 +4,18 @@ class TestRunnerGenerator: def __init__(self): - self.directory = os.getcwd() + # Set the directory to a subdirectory named 'cases' within the current working directory + self.directory = os.path.join(os.getcwd(), "cases") def find_test_groups(self): test_groups = set() pattern = r"FOSSIL_TEST_GROUP\((\w+)\)" + # Walk through files in the specified directory, 'cases' for root, _, files in os.walk(self.directory): for file in files: - if file.startswith("test_") and file.endswith(".c"): + # Search for C and C++ files + if (file.startswith("test_") and file.endswith(".c")) or file.endswith(".cpp"): with open(os.path.join(root, file), "r") as f: content = f.read() matches = re.findall(pattern, content) @@ -20,55 +23,55 @@ def find_test_groups(self): return list(test_groups) - def generate_test_runner(self, test_groups): + def generate_c_runner(self, test_groups): + # Prepare header content for the test runner header = """ -// Generated Fossil Logic Test -""" - - header += """ -#include -""" - - header += """ +// Generated Fossil Logic Test Runner +#include // * * * * * * * * * * * * * * * * * * * * * * * * // * Fossil Logic Test List -// * * * * * * * * * * * * * * * * * * * * * * * *\n""" +// * * * * * * * * * * * * * * * * * * * * * * * * +""" - extern_pools = "\n".join( + # Declare test group externs + extern_test_groups = "\n".join( [f"FOSSIL_TEST_EXPORT({group});" for group in test_groups] ) - runner = """ - + # Prepare runner content + runner = """\n // * * * * * * * * * * * * * * * * * * * * * * * * // * Fossil Logic Test Runner -// * * * * * * * * * * * * * * * * * * * * * * * *""" - - runner += """ +// * * * * * * * * * * * * * * * * * * * * * * * * int main(int argc, char **argv) { - FOSSIL_TEST_CREATE(argc, argv);\n""" + FOSSIL_TEST_START(argc, argv);\n""" - import_pools = "\n".join( + # Import test groups in the main function + import_test_groups = "\n".join( [f" FOSSIL_TEST_IMPORT({group});" for group in test_groups] ) - footer = """ + # Complete with footer + footer = """\n FOSSIL_TEST_RUN(); - return FOSSIL_TEST_ERASE(); -} // end of func + FOSSIL_TEST_SUMMARY(); + FOSSIL_TEST_END(); +} // end of main """ + # Write the generated test runner to 'unit_runner.c' with open("unit_runner.c", "w") as file: file.write(header) - file.write("\n") - file.write(extern_pools) + file.write(extern_test_groups) file.write(runner) - file.write(import_pools) - file.write("\n") + file.write(import_test_groups) file.write(footer) +# Instantiate the generator, find test groups, and generate the test runner generator = TestRunnerGenerator() test_groups = generator.find_test_groups() -generator.generate_test_runner(test_groups) + +# Generate the test runner for C and C++ tests +generator.generate_c_runner(test_groups) diff --git a/subprojects/fossil-test.wrap b/subprojects/fossil-test.wrap index bafdb69..05aed56 100644 --- a/subprojects/fossil-test.wrap +++ b/subprojects/fossil-test.wrap @@ -3,9 +3,7 @@ # ====================== [wrap-git] url = https://github.com/fossillogic/fossil-test.git -revision = v1.0.5 +revision = v1.1.2 [provide] -fossil-test = fossil_test_dep -fossil-mock = fossil_mock_dep -fossil-mark = fossil_mark_dep +fossil-test = fossil_test_dep \ No newline at end of file