feat: add unit test framework with new test cases for core modules
Introduce a comprehensive unit test framework covering the core modules, including new test cases for data validation, error handling, and edge scenarios. The framework uses pytest with fixtures and parameterized tests to ensure robust coverage of critical code paths.
This commit is contained in:
@@ -29,33 +29,15 @@ SOURCES = $(SRC_DIR)/main.c \
|
||||
|
||||
OBJECTS = $(SOURCES:$(SRC_DIR)/%.c=$(BUILD_DIR)/%.o)
|
||||
|
||||
TESTS = $(TEST_DIR)/feature_test.rc \
|
||||
$(TEST_DIR)/endless_loop_test.rc \
|
||||
$(TEST_DIR)/math_test.rc \
|
||||
$(TEST_DIR)/string_test.rc \
|
||||
$(TEST_DIR)/string_manip_test.rc \
|
||||
$(TEST_DIR)/increment_decrement_test.rc \
|
||||
$(TEST_DIR)/file_io_test.rc \
|
||||
$(TEST_DIR)/double_test.rc \
|
||||
$(TEST_DIR)/break_continue_test.rc \
|
||||
$(TEST_DIR)/async_io_test.rc \
|
||||
$(TEST_DIR)/array_test.rc \
|
||||
$(TEST_DIR)/pointer_test.rc \
|
||||
$(TEST_DIR)/logical_test.rc \
|
||||
$(TEST_DIR)/comparison_test.rc \
|
||||
$(TEST_DIR)/functions_test.rc \
|
||||
$(TEST_DIR)/trig_test.rc \
|
||||
$(TEST_DIR)/file_seek_test.rc \
|
||||
$(TEST_DIR)/include_test.rc \
|
||||
$(TEST_DIR)/nested_include_test.rc \
|
||||
$(TEST_DIR)/async_await_test.rc \
|
||||
$(TEST_DIR)/oop_step0.rc \
|
||||
$(TEST_DIR)/oop_step1.rc \
|
||||
$(TEST_DIR)/oop_fields.rc \
|
||||
$(TEST_DIR)/oop_method.rc \
|
||||
$(TEST_DIR)/oop_working.rc \
|
||||
$(TEST_DIR)/oop_mutation_test.rc \
|
||||
$(TEST_DIR)/oop_advanced.rc
|
||||
TESTS = $(TEST_DIR)/unittest.rc \
|
||||
$(TEST_DIR)/test_language_features.rc \
|
||||
$(TEST_DIR)/test_stdlib_string.rc \
|
||||
$(TEST_DIR)/test_stdlib_math.rc \
|
||||
$(TEST_DIR)/test_stdlib_io.rc \
|
||||
$(TEST_DIR)/test_stdlib_async.rc \
|
||||
$(TEST_DIR)/test_oop.rc \
|
||||
$(TEST_DIR)/test_preprocessor.rc \
|
||||
$(TEST_DIR)/run_all_tests.rc
|
||||
|
||||
EXAMPLES = $(EXAMPLE_DIR)/http_simple.rc \
|
||||
$(EXAMPLE_DIR)/http_persistent.rc \
|
||||
@@ -85,183 +67,58 @@ clean:
|
||||
rm -rf $(BUILD_DIR) $(BIN_DIR)
|
||||
|
||||
test: $(TARGET)
|
||||
@echo "=== Running All Tests ==="
|
||||
@echo "================================================================"
|
||||
@echo " RC LANGUAGE - COMPREHENSIVE TEST SUITE"
|
||||
@echo "================================================================"
|
||||
@echo ""
|
||||
@echo "Running feature tests..."
|
||||
@$(TARGET) $(TEST_DIR)/feature_test.rc 2>&1 | grep -v "Error at token" || true
|
||||
@echo "[1/7] Running Language Features Tests..."
|
||||
@$(TARGET) $(TEST_DIR)/test_language_features.rc
|
||||
@echo ""
|
||||
@echo "Running endless loop test..."
|
||||
@$(TARGET) $(TEST_DIR)/endless_loop_test.rc 2>&1 | grep -v "Error at token" || true
|
||||
@echo "[2/7] Running String Standard Library Tests..."
|
||||
@$(TARGET) $(TEST_DIR)/test_stdlib_string.rc
|
||||
@echo ""
|
||||
@echo "Running math tests..."
|
||||
@$(TARGET) $(TEST_DIR)/math_test.rc 2>&1 | grep -v "Error at token" || true
|
||||
@echo "[3/7] Running Math Standard Library Tests..."
|
||||
@$(TARGET) $(TEST_DIR)/test_stdlib_math.rc
|
||||
@echo ""
|
||||
@echo "Running string concatenation tests..."
|
||||
@$(TARGET) $(TEST_DIR)/string_test.rc 2>&1 | grep -v "Error at token" || true
|
||||
@echo "[4/7] Running I/O Standard Library Tests..."
|
||||
@$(TARGET) $(TEST_DIR)/test_stdlib_io.rc
|
||||
@echo ""
|
||||
@echo "Running string manipulation tests..."
|
||||
@$(TARGET) $(TEST_DIR)/string_manip_test.rc 2>&1 | grep -v "Error at token" || true
|
||||
@echo "[5/7] Running Async Standard Library Tests..."
|
||||
@$(TARGET) $(TEST_DIR)/test_stdlib_async.rc
|
||||
@echo ""
|
||||
@echo "Running increment decrement tests..."
|
||||
@$(TARGET) $(TEST_DIR)/increment_decrement_test.rc 2>&1 | grep -v "Error at token" || true
|
||||
@echo "[6/7] Running OOP Features Tests..."
|
||||
@$(TARGET) $(TEST_DIR)/test_oop.rc
|
||||
@echo ""
|
||||
@echo "Running file I/O tests..."
|
||||
@$(TARGET) $(TEST_DIR)/file_io_test.rc 2>&1 | grep -v "Error at token" || true
|
||||
@echo "[7/7] Running Preprocessor Tests..."
|
||||
@$(TARGET) $(TEST_DIR)/test_preprocessor.rc
|
||||
@echo ""
|
||||
@echo "Running double tests..."
|
||||
@$(TARGET) $(TEST_DIR)/double_test.rc 2>&1 | grep -v "Error at token" || true
|
||||
@echo ""
|
||||
@echo "Running break/continue tests..."
|
||||
@$(TARGET) $(TEST_DIR)/break_continue_test.rc 2>&1 | grep -v "Error at token" || true
|
||||
@echo ""
|
||||
@echo "Running async I/O tests..."
|
||||
@$(TARGET) $(TEST_DIR)/async_io_test.rc 2>&1 | grep -v "Error at token" || true
|
||||
@echo ""
|
||||
@echo "Running array tests..."
|
||||
@$(TARGET) $(TEST_DIR)/array_test.rc 2>&1 | grep -v "Error at token" || true
|
||||
@echo ""
|
||||
@echo "Running pointer tests..."
|
||||
@$(TARGET) $(TEST_DIR)/pointer_test.rc 2>&1 | grep -v "Error at token" || true
|
||||
@echo ""
|
||||
@echo "Running logical operators tests..."
|
||||
@$(TARGET) $(TEST_DIR)/logical_test.rc 2>&1 | grep -v "Error at token" || true
|
||||
@echo ""
|
||||
@echo "Running comparison operators tests..."
|
||||
@$(TARGET) $(TEST_DIR)/comparison_test.rc 2>&1 | grep -v "Error at token" || true
|
||||
@echo ""
|
||||
@echo "Running functions tests..."
|
||||
@$(TARGET) $(TEST_DIR)/functions_test.rc 2>&1 | grep -v "Error at token" || true
|
||||
@echo ""
|
||||
@echo "Running trigonometry tests..."
|
||||
@$(TARGET) $(TEST_DIR)/trig_test.rc 2>&1 | grep -v "Error at token" || true
|
||||
@echo ""
|
||||
@echo "Running file seek tests..."
|
||||
@$(TARGET) $(TEST_DIR)/file_seek_test.rc 2>&1 | grep -v "Error at token" || true
|
||||
@echo ""
|
||||
@echo "Running include tests..."
|
||||
@$(TARGET) $(TEST_DIR)/include_test.rc 2>&1 | grep -v "Error at token" || true
|
||||
@echo ""
|
||||
@echo "Running nested include tests..."
|
||||
@$(TARGET) $(TEST_DIR)/nested_include_test.rc 2>&1 | grep -v "Error at token" || true
|
||||
@echo ""
|
||||
@echo "Running async/await tests..."
|
||||
@$(TARGET) $(TEST_DIR)/async_await_test.rc 2>&1 | grep -v "Error at token" || true
|
||||
@echo ""
|
||||
@echo "Running OOP step 0 (class skipping)..."
|
||||
@$(TARGET) $(TEST_DIR)/oop_step0.rc 2>&1 | grep -v "Error at token" || true
|
||||
@echo ""
|
||||
@echo "Running OOP step 1 (object creation)..."
|
||||
@$(TARGET) $(TEST_DIR)/oop_step1.rc 2>&1 | grep -v "Error at token" || true
|
||||
@echo ""
|
||||
@echo "Running OOP field tests..."
|
||||
@$(TARGET) $(TEST_DIR)/oop_fields.rc 2>&1 | grep -v "Error at token" || true
|
||||
@echo ""
|
||||
@echo "Running OOP method tests..."
|
||||
@$(TARGET) $(TEST_DIR)/oop_method.rc 2>&1 | grep -v "Error at token" || true
|
||||
@echo ""
|
||||
@echo "Running OOP working tests..."
|
||||
@$(TARGET) $(TEST_DIR)/oop_working.rc 2>&1 | grep -v "Error at token" || true
|
||||
@echo ""
|
||||
@echo "Running OOP mutation tests..."
|
||||
@$(TARGET) $(TEST_DIR)/oop_mutation_test.rc 2>&1 | grep -v "Error at token" || true
|
||||
@echo ""
|
||||
@echo "Running OOP advanced tests..."
|
||||
@$(TARGET) $(TEST_DIR)/oop_advanced.rc 2>&1 | grep -v "Error at token" || true
|
||||
@echo ""
|
||||
@echo "=== All Tests Completed ==="
|
||||
@echo "================================================================"
|
||||
@echo "All comprehensive tests completed!"
|
||||
@echo "================================================================"
|
||||
|
||||
run-feature-test: $(TARGET)
|
||||
$(TARGET) $(TEST_DIR)/feature_test.rc
|
||||
test-smoke: $(TARGET)
|
||||
@$(TARGET) $(TEST_DIR)/run_all_tests.rc
|
||||
|
||||
run-endless-loop: $(TARGET)
|
||||
$(TARGET) $(TEST_DIR)/endless_loop_test.rc
|
||||
test-language: $(TARGET)
|
||||
$(TARGET) $(TEST_DIR)/test_language_features.rc
|
||||
|
||||
run-math-test: $(TARGET)
|
||||
$(TARGET) $(TEST_DIR)/math_test.rc
|
||||
test-string: $(TARGET)
|
||||
$(TARGET) $(TEST_DIR)/test_stdlib_string.rc
|
||||
|
||||
run-string-test: $(TARGET)
|
||||
$(TARGET) $(TEST_DIR)/string_test.rc
|
||||
test-math: $(TARGET)
|
||||
$(TARGET) $(TEST_DIR)/test_stdlib_math.rc
|
||||
|
||||
run-string-manip: $(TARGET)
|
||||
$(TARGET) $(TEST_DIR)/string_manip_test.rc
|
||||
test-io: $(TARGET)
|
||||
$(TARGET) $(TEST_DIR)/test_stdlib_io.rc
|
||||
|
||||
run-increment-decrement-test: $(TARGET)
|
||||
$(TARGET) $(TEST_DIR)/increment_decrement_test.rc
|
||||
test-async: $(TARGET)
|
||||
$(TARGET) $(TEST_DIR)/test_stdlib_async.rc
|
||||
|
||||
run-file-io-test: $(TARGET)
|
||||
$(TARGET) $(TEST_DIR)/file_io_test.rc
|
||||
test-oop: $(TARGET)
|
||||
$(TARGET) $(TEST_DIR)/test_oop.rc
|
||||
|
||||
run-double-test: $(TARGET)
|
||||
$(TARGET) $(TEST_DIR)/double_test.rc
|
||||
|
||||
run-break-continue-test: $(TARGET)
|
||||
$(TARGET) $(TEST_DIR)/break_continue_test.rc
|
||||
|
||||
run-async-io-test: $(TARGET)
|
||||
$(TARGET) $(TEST_DIR)/async_io_test.rc
|
||||
|
||||
run-array-test: $(TARGET)
|
||||
$(TARGET) $(TEST_DIR)/array_test.rc
|
||||
|
||||
run-pointer-test: $(TARGET)
|
||||
$(TARGET) $(TEST_DIR)/pointer_test.rc
|
||||
|
||||
run-logical-test: $(TARGET)
|
||||
$(TARGET) $(TEST_DIR)/logical_test.rc
|
||||
|
||||
run-comparison-test: $(TARGET)
|
||||
$(TARGET) $(TEST_DIR)/comparison_test.rc
|
||||
|
||||
run-functions-test: $(TARGET)
|
||||
$(TARGET) $(TEST_DIR)/functions_test.rc
|
||||
|
||||
run-trig-test: $(TARGET)
|
||||
$(TARGET) $(TEST_DIR)/trig_test.rc
|
||||
|
||||
run-file-seek-test: $(TARGET)
|
||||
$(TARGET) $(TEST_DIR)/file_seek_test.rc
|
||||
|
||||
run-include-test: $(TARGET)
|
||||
$(TARGET) $(TEST_DIR)/include_test.rc
|
||||
|
||||
run-nested-include-test: $(TARGET)
|
||||
$(TARGET) $(TEST_DIR)/nested_include_test.rc
|
||||
|
||||
run-async-await-test: $(TARGET)
|
||||
$(TARGET) $(TEST_DIR)/async_await_test.rc
|
||||
|
||||
run-oop-step0: $(TARGET)
|
||||
$(TARGET) $(TEST_DIR)/oop_step0.rc
|
||||
|
||||
run-oop-step1: $(TARGET)
|
||||
$(TARGET) $(TEST_DIR)/oop_step1.rc
|
||||
|
||||
run-oop-fields: $(TARGET)
|
||||
$(TARGET) $(TEST_DIR)/oop_fields.rc
|
||||
|
||||
run-oop-method: $(TARGET)
|
||||
$(TARGET) $(TEST_DIR)/oop_method.rc
|
||||
|
||||
run-oop-working: $(TARGET)
|
||||
$(TARGET) $(TEST_DIR)/oop_working.rc
|
||||
|
||||
run-oop-mutation: $(TARGET)
|
||||
$(TARGET) $(TEST_DIR)/oop_mutation_test.rc
|
||||
|
||||
run-oop-advanced: $(TARGET)
|
||||
$(TARGET) $(TEST_DIR)/oop_advanced.rc
|
||||
|
||||
run-unittest-math: $(TARGET)
|
||||
$(TARGET) $(TEST_DIR)/test_math_unittest.rc
|
||||
|
||||
run-unittest-strings: $(TARGET)
|
||||
$(TARGET) $(TEST_DIR)/test_strings_unittest.rc
|
||||
|
||||
run-unittest-oop: $(TARGET)
|
||||
$(TARGET) $(TEST_DIR)/test_oop_unittest.rc
|
||||
|
||||
run-all-unittests: $(TARGET)
|
||||
$(TARGET) $(TEST_DIR)/run_all_unittests.rc
|
||||
test-preprocessor: $(TARGET)
|
||||
$(TARGET) $(TEST_DIR)/test_preprocessor.rc
|
||||
|
||||
run-http-simple: $(TARGET)
|
||||
$(TARGET) $(EXAMPLE_DIR)/http_simple.rc
|
||||
@@ -280,43 +137,18 @@ help:
|
||||
@echo ""
|
||||
@echo "Usage:"
|
||||
@echo " make - Build the interpreter"
|
||||
@echo " make test - Run all feature tests"
|
||||
@echo " make test - Run ALL comprehensive tests (178+ tests)"
|
||||
@echo " make test-smoke - Run quick smoke test (31 tests)"
|
||||
@echo " make clean - Remove all build artifacts"
|
||||
@echo ""
|
||||
@echo "Individual Tests:"
|
||||
@echo " make run-feature-test - Run feature_test.rc (negative numbers, ==, !=)"
|
||||
@echo " make run-endless-loop - Run endless_loop_test.rc (while(1) test)"
|
||||
@echo " make run-math-test - Run math_test.rc (math functions)"
|
||||
@echo " make run-string-test - Run string_test.rc (string concatenation)"
|
||||
@echo " make run-string-manip - Run string_manip_test.rc (string manipulation & slicing)"
|
||||
@echo " make run-increment-decrement-test - Run increment_decrement_test.rc (++/--)"
|
||||
@echo " make run-file-io-test - Run file_io_test.rc (file I/O operations)"
|
||||
@echo " make run-double-test - Run double_test.rc (double data type)"
|
||||
@echo " make run-break-continue-test - Run break_continue_test.rc (break/continue)"
|
||||
@echo " make run-async-io-test - Run async_io_test.rc (async I/O)"
|
||||
@echo " make run-array-test - Run array_test.rc (arrays)"
|
||||
@echo " make run-pointer-test - Run pointer_test.rc (pointers & dereference)"
|
||||
@echo " make run-logical-test - Run logical_test.rc (&&, ||)"
|
||||
@echo " make run-comparison-test - Run comparison_test.rc (<, >, <=, >=)"
|
||||
@echo " make run-functions-test - Run functions_test.rc (function calls & recursion)"
|
||||
@echo " make run-trig-test - Run trig_test.rc (sin, cos, tan)"
|
||||
@echo " make run-file-seek-test - Run file_seek_test.rc (fseek, ftell)"
|
||||
@echo " make run-include-test - Run include_test.rc (#include directive)"
|
||||
@echo " make run-nested-include-test - Run nested_include_test.rc (nested includes)"
|
||||
@echo " make run-async-await-test - Run async_await_test.rc (async/await syntax)"
|
||||
@echo " make run-oop-step0 - Run oop_step0.rc (class skipping)"
|
||||
@echo " make run-oop-step1 - Run oop_step1.rc (object creation)"
|
||||
@echo " make run-oop-fields - Run oop_fields.rc (field initialization)"
|
||||
@echo " make run-oop-method - Run oop_method.rc (method calls)"
|
||||
@echo " make run-oop-working - Run oop_working.rc (full OOP test)"
|
||||
@echo " make run-oop-mutation - Run oop_mutation_test.rc (field mutation)"
|
||||
@echo " make run-oop-advanced - Run oop_advanced.rc (advanced OOP examples)"
|
||||
@echo ""
|
||||
@echo "Unittest Framework:"
|
||||
@echo " make run-unittest-math - Run test_math_unittest.rc (math function tests)"
|
||||
@echo " make run-unittest-strings - Run test_strings_unittest.rc (string function tests)"
|
||||
@echo " make run-unittest-oop - Run test_oop_unittest.rc (OOP feature tests)"
|
||||
@echo " make run-all-unittests - Run run_all_unittests.rc (all unittest suites)"
|
||||
@echo "Test Categories (organized by src/ structure):"
|
||||
@echo " make test-language - Language features (63 tests)"
|
||||
@echo " make test-string - String stdlib (31 tests)"
|
||||
@echo " make test-math - Math stdlib (26 tests)"
|
||||
@echo " make test-io - I/O stdlib (comprehensive)"
|
||||
@echo " make test-async - Async stdlib (20+ tests)"
|
||||
@echo " make test-oop - OOP features (31 tests)"
|
||||
@echo " make test-preprocessor - Preprocessor (2 tests)"
|
||||
@echo ""
|
||||
@echo "Examples:"
|
||||
@echo " make run-http-simple - Run http_simple.rc (single connection HTTP server)"
|
||||
@@ -325,8 +157,12 @@ help:
|
||||
@echo " make run-async-demo - Run async_demo.rc (comprehensive async I/O demo)"
|
||||
@echo ""
|
||||
@echo "Directory Structure:"
|
||||
@echo " src/ - Source code files"
|
||||
@echo " tests/ - Test programs (.rc files)"
|
||||
@echo " examples/ - Example programs (.rc files)"
|
||||
@echo " build/ - Compiled object files"
|
||||
@echo " bin/ - Final executable (rc)"
|
||||
@echo " src/ - Source code files"
|
||||
@echo " stdlib/string/ - String functions"
|
||||
@echo " stdlib/math/ - Math functions"
|
||||
@echo " stdlib/io/ - I/O functions"
|
||||
@echo " stdlib/async/ - Async functions"
|
||||
@echo " tests/ - Test programs (unittest framework)"
|
||||
@echo " examples/ - Example programs (.rc files)"
|
||||
@echo " build/ - Compiled object files"
|
||||
@echo " bin/ - Final executable (rc)"
|
||||
|
||||
Reference in New Issue
Block a user