check_environment.pyā¢8.35 kB
#!/usr/bin/env python3
"""
Basic functionality test for Doxygen MCP Server
Run this script to verify core functionality before MCP integration
"""
import subprocess
import sys
from pathlib import Path
import json
def test_doxygen_installation():
"""Test if Doxygen is installed and accessible"""
print("š Testing Doxygen installation...")
try:
result = subprocess.run(["doxygen", "--version"], capture_output=True, text=True)
if result.returncode == 0:
version = result.stdout.strip()
print(f"ā
Doxygen {version} is installed and working!")
return True
else:
print("ā Doxygen is not working properly")
print(f"Error: {result.stderr}")
return False
except FileNotFoundError:
print("ā Doxygen is not installed or not in PATH")
print("Please install Doxygen from: https://www.doxygen.nl/download.html")
return False
def test_graphviz_installation():
"""Test if Graphviz (dot) is installed"""
print("\nš Testing Graphviz (dot) installation...")
try:
result = subprocess.run(["dot", "-V"], capture_output=True, text=True)
if result.returncode == 0:
# Graphviz outputs version to stderr
version_info = result.stderr.strip()
print(f"ā
Graphviz found: {version_info}")
return True
else:
print("ā Graphviz dot command failed")
return False
except FileNotFoundError:
print("ā ļø Graphviz (dot) not found - diagrams will not be generated")
print("Install from: https://graphviz.org/download/")
return False
def test_python_dependencies():
"""Test if required Python packages are available"""
print("\nš Testing Python dependencies...")
required_packages = ['mcp', 'pydantic']
missing_packages = []
for package in required_packages:
try:
__import__(package)
print(f"ā
{package} is available")
except ImportError:
print(f"ā {package} is missing")
missing_packages.append(package)
if missing_packages:
print(f"\nā ļø Missing packages: {', '.join(missing_packages)}")
print("Install with: pip install -r requirements.txt")
return False
return True
def test_project_structure():
"""Test if all required project files are present"""
print("\nš Testing project structure...")
project_root = Path(__file__).parent
required_files = [
'server.py',
'requirements.txt',
'package.json',
'README.md',
'templates/minimal.doxyfile',
'templates/standard.doxyfile',
'templates/comprehensive.doxyfile',
'examples/cpp_sample/calculator.h',
'examples/cpp_sample/calculator.cpp'
]
missing_files = []
for file_path in required_files:
full_path = project_root / file_path
if full_path.exists():
print(f"ā
{file_path}")
else:
print(f"ā {file_path}")
missing_files.append(file_path)
if missing_files:
print(f"\nā ļø Missing files: {', '.join(missing_files)}")
return False
return True
def test_example_project():
"""Test the example C++ project"""
print("\nš Testing example C++ project...")
project_root = Path(__file__).parent
example_path = project_root / "examples" / "cpp_sample"
# Count source files
cpp_files = list(example_path.glob("*.cpp"))
h_files = list(example_path.glob("*.h"))
print(f"š Found {len(cpp_files)} .cpp files")
print(f"š Found {len(h_files)} .h files")
# Check if files have Doxygen comments
documented_files = 0
for file_path in cpp_files + h_files:
content = file_path.read_text(encoding='utf-8')
if '/**' in content or '///' in content or '@brief' in content:
documented_files += 1
print(f"ā
{file_path.name} has Doxygen comments")
else:
print(f"ā ļø {file_path.name} lacks Doxygen comments")
total_files = len(cpp_files) + len(h_files)
if total_files > 0:
print(f"š Documentation coverage: {documented_files}/{total_files} files")
return documented_files > 0
else:
print("ā No source files found in example project")
return False
def test_manual_doxygen_run():
"""Test running Doxygen manually on the example project"""
print("\nš Testing manual Doxygen run...")
project_root = Path(__file__).parent
example_path = project_root / "examples" / "cpp_sample"
# Sanitize the project path
safe_example_path = Path(os.path.abspath(os.path.realpath(example_path)))
if not safe_example_path.is_dir():
print(f"ā Invalid example project path: {example_path}")
return False
if not str(safe_example_path).startswith(os.getcwd()):
print(f"ā Example project path is not within the current working directory: {example_path}")
return False
# Create a simple Doxyfile for testing
doxyfile_content = f"""
PROJECT_NAME = "Calculator Example Test"
OUTPUT_DIRECTORY = "{example_path}/test_docs"
INPUT = {example_path}
FILE_PATTERNS = *.h *.cpp
RECURSIVE = NO
GENERATE_HTML = YES
GENERATE_LATEX = NO
EXTRACT_ALL = YES
SOURCE_BROWSER = YES
"""
doxyfile_path = example_path / "Doxyfile.test"
doxyfile_path.write_text(doxyfile_content)
try:
print(f"š Created test Doxyfile: {doxyfile_path}")
# Run Doxygen
result = subprocess.run(
["doxygen", str(doxyfile_path)],
cwd=example_path,
capture_output=True,
text=True
)
if result.returncode == 0:
print("ā
Doxygen ran successfully!")
# Check if HTML output was created
html_index = example_path / "test_docs" / "html" / "index.html"
if html_index.exists():
print(f"ā
HTML documentation created: {html_index}")
print(f"š Documentation size: {html_index.stat().st_size} bytes")
return True
else:
print("ā HTML documentation not found")
return False
else:
print("ā Doxygen failed to run")
print(f"Error output: {result.stderr}")
return False
except Exception as e:
print(f"ā Error running Doxygen test: {e}")
return False
finally:
# Clean up
if doxyfile_path.exists():
doxyfile_path.unlink()
def main():
"""Run all tests"""
print("š Doxygen MCP Server - Basic Functionality Tests")
print("=" * 60)
tests = [
("Doxygen Installation", test_doxygen_installation),
("Graphviz Installation", test_graphviz_installation),
("Python Dependencies", test_python_dependencies),
("Project Structure", test_project_structure),
("Example Project", test_example_project),
("Manual Doxygen Run", test_manual_doxygen_run)
]
results = []
for test_name, test_func in tests:
try:
success = test_func()
results.append((test_name, success))
except Exception as e:
print(f"ā {test_name} failed with exception: {e}")
results.append((test_name, False))
# Summary
print("\n" + "=" * 60)
print("š Test Results Summary:")
print("=" * 60)
passed = 0
for test_name, success in results:
status = "ā
PASS" if success else "ā FAIL"
print(f"{status} {test_name}")
if success:
passed += 1
print(f"\nšÆ Overall: {passed}/{len(results)} tests passed")
if passed == len(results):
print("\nš All tests passed! Ready for MCP integration testing.")
return True
else:
print(f"\nā ļø {len(results) - passed} tests failed. Please address issues before proceeding.")
return False
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)