diff options
| author | Bernard Xiong <[email protected]> | 2025-06-25 15:06:45 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-06-25 15:06:45 +0800 |
| commit | 5a2352eb64f5a1039b37368f2a9c199db32957a0 (patch) | |
| tree | f2153efa40eaef9ee4b3c66ad2eb74ea7d29b8d0 /tools/testcases/test_preprocessor.py | |
| parent | 8e9872a55456b38d28b0d7d076905be84d0af7a2 (diff) | |
[scons] code cleanup for scons script. (#10429)
* [scons] move project_generation to targets; code clean for building.py.
Diffstat (limited to 'tools/testcases/test_preprocessor.py')
| -rw-r--r-- | tools/testcases/test_preprocessor.py | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/tools/testcases/test_preprocessor.py b/tools/testcases/test_preprocessor.py new file mode 100644 index 0000000000..11121dbda9 --- /dev/null +++ b/tools/testcases/test_preprocessor.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# File : test_preprocessor_patch.py +# This file is part of RT-Thread RTOS +# COPYRIGHT (C) 2006 - 2025, RT-Thread Development Team +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Change Logs: +# Date Author Notes +# 2025-01-05 Assistant Test file for SCons PreProcessor patch + +import sys +import os + +# Add current directory to path for imports +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) + +def test_preprocessor_patch(): + """Test the SCons PreProcessor patch functionality""" + try: + from scons_preprocessor_patch import SConsPreProcessorPatch, create_preprocessor_instance + + print("Testing SCons PreProcessor patch...") + + # Test creating patch instance + patch = SConsPreProcessorPatch() + print("✓ SConsPreProcessorPatch instance created successfully") + + # Test getting patched preprocessor + patched_class = patch.get_patched_preprocessor() + print("✓ Patched PreProcessor class retrieved successfully") + + # Test creating preprocessor instance + preprocessor = create_preprocessor_instance() + print("✓ PreProcessor instance created successfully") + + # Test basic functionality + test_content = """ + #define TEST_MACRO 1 + #ifdef TEST_MACRO + #define ENABLED_FEATURE 1 + #else + #define DISABLED_FEATURE 1 + #endif + """ + + preprocessor.process_contents(test_content) + namespace = preprocessor.cpp_namespace + + print("✓ PreProcessor processed test content successfully") + print(f" - TEST_MACRO: {namespace.get('TEST_MACRO', 'Not found')}") + print(f" - ENABLED_FEATURE: {namespace.get('ENABLED_FEATURE', 'Not found')}") + print(f" - DISABLED_FEATURE: {namespace.get('DISABLED_FEATURE', 'Not found')}") + + print("\n✓ All tests passed! SCons PreProcessor patch is working correctly.") + return True + + except ImportError as e: + print(f"✗ Import error: {e}") + print("Make sure SCons is available in the environment") + return False + except Exception as e: + print(f"✗ Test failed: {e}") + return False + +def test_building_integration(): + """Test integration with building.py""" + try: + # Test that the function is available from the patch module + from scons_preprocessor_patch import create_preprocessor_instance + + print("\nTesting scons_preprocessor_patch integration...") + + # Test that the function is available + preprocessor = create_preprocessor_instance() + print("✓ create_preprocessor_instance function works from scons_preprocessor_patch") + + # Test basic processing + test_content = "#define BUILD_TEST 1" + preprocessor.process_contents(test_content) + namespace = preprocessor.cpp_namespace + + print(f"✓ Integration test passed: BUILD_TEST = {namespace.get('BUILD_TEST', 'Not found')}") + return True + + except Exception as e: + print(f"✗ Integration test failed: {e}") + return False + +if __name__ == "__main__": + print("SCons PreProcessor Patch Test Suite") + print("=" * 40) + + success1 = test_preprocessor_patch() + success2 = test_building_integration() + + if success1 and success2: + print("\n🎉 All tests passed! The refactoring was successful.") + sys.exit(0) + else: + print("\n❌ Some tests failed. Please check the implementation.") + sys.exit(1)
\ No newline at end of file |
