Skip to content

Commit c383c80

Browse files
bordeuxclaude
andcommitted
test: add comprehensive test coverage for renderer and main.rs logic
Added tests/test_renderer.rs with 23 comprehensive tests that cover the core render_template() function called by main.rs, significantly improving code coverage for src/renderer.rs and indirectly testing src/main.rs logic. Test categories: Core Functionality (4 tests): - test_render_template_from_file_to_stdout: Basic file rendering - test_render_template_from_file_to_file: File to file rendering - test_render_template_with_env_var: Environment variable substitution - test_render_template_with_trust_mode: Trust mode allowing absolute paths Error Handling (6 tests): - test_render_template_missing_file: Missing template file error - test_render_template_invalid_template_syntax: Syntax error handling - test_render_template_undefined_variable: Undefined variable error - test_render_template_invalid_output_path: Invalid output path error - test_render_template_security_absolute_path: Security check for absolute paths - test_render_template_security_parent_directory: Security check for .. traversal Validation Tests (6 tests): - test_render_template_validate_json_success/failure: JSON validation - test_render_template_validate_yaml_success/failure: YAML validation - test_render_template_validate_toml_success/failure: TOML validation Complex Scenarios (7 tests): - test_render_template_with_includes: Template includes - test_render_template_with_filters: Built-in filters - test_render_template_with_conditionals: If/else logic - test_render_template_with_loops: For loops - test_render_template_empty_file: Empty template handling - test_render_template_large_template: Large template with 1000 lines - test_render_template_unicode_content: Unicode/emoji support Coverage for main.rs: While main.rs itself is simple (18 lines), these tests comprehensively cover the render_template() function it calls, testing: - Success path (lines 8-13 of main.rs) - Error path (lines 14-16 of main.rs) - All CLI parameter combinations (template, output, trust, validate) The integration tests in tests/integration/ test the actual binary, while these unit tests provide granular coverage of the rendering logic. Technical notes: - Used unsafe blocks for std::env::set_var/remove_var (Rust 2024 requirement) - All tests use temporary files/directories for isolation - Tests verify both success cases and proper error messages - Security tests ensure trust mode is properly enforced 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 98e805e commit c383c80

1 file changed

Lines changed: 452 additions & 0 deletions

File tree

0 commit comments

Comments
 (0)