Skip to content

Conversation

@alexgarzao
Copy link
Collaborator

@alexgarzao alexgarzao commented Nov 1, 2025

This PR refactors the test generation code to simplify and standardize file generation logic, improve error handling, and reduce code duplication. The main changes include extracting template execution into a reusable function, updating all test generation functions to return errors, and ensuring errors are properly surfaced to the main entrypoint. Additionally, verbose logging is replaced with standard output, and custom file generation methods are removed in favor of a shared utility.

Refactoring and code simplification:

  • Introduced a new ExecTemplate function in execute_template.go to handle reading, parsing, executing, formatting, and writing template-based code generation; this eliminates repeated logic across test generators.
  • Removed per-type GenerateFile methods and replaced their usage with the new ExecTemplate utility in all test generation files (generate_validation_types_tests.go, generate_validation_code_tests.go, generate_function_code_tests.go, generate_cmp_perf_tests.go). [1] [2] [3] [4]

Error handling improvements:

  • Updated all test generation functions (generateValidationTypesEndToEndTests, generateValidationCodeUnitTests, generateFunctionCodeUnitTests, generateComparativePerformanceTests) to return errors instead of panicking or logging fatally; errors are now checked and handled in main(), which exits with a non-zero status on failure. [1] [2] [3] [4] [5]
  • Replaced all log.Fatalf and log.Printf calls with fmt.Printf and error returns, ensuring that errors are consistently propagated and logged in a uniform way. [1] [2] [3] [4] [5] [6] [7]

General cleanup:

  • Removed unused imports (log, os, bytes, text/template, go/format) from generator files since this logic is now encapsulated in ExecTemplate. [1] [2] [3] [4]

These changes make the codebase easier to maintain, reduce duplication, and provide more predictable error handling during test code generation.

@alexgarzao alexgarzao self-assigned this Nov 1, 2025
@alexgarzao alexgarzao requested a review from Copilot November 1, 2025 19:27
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the benchmark test infrastructure by removing a template-based generation approach and replacing it with a large, directly committed pointer-based benchmark test file. The changes include:

  • Removal of template files (types.tpl, validgen_vs_validator_test.tpl) and the template generator main file
  • Deletion of generated test files that used the old template system
  • Addition of a comprehensive 9097-line benchmark test file covering pointer types
  • Minor whitespace cleanup in existing test files

Reviewed Changes

Copilot reviewed 13 out of 16 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/endtoend/generated_numeric_int_tests.go Removed trailing whitespace on line 19
tests/cmpbenchtests/validgen_vs_validator_test.tpl Deleted template file for generating benchmark tests
tests/cmpbenchtests/validator__.go Removed 10 generated string validation functions (email, eq, len, etc.)
tests/cmpbenchtests/types.tpl Deleted template file for generating test types
tests/cmpbenchtests/generated_tests/validgen_vs_validator_test.go Deleted 279-line generated benchmark test file
tests/cmpbenchtests/generated_tests/types.go Deleted 83-line generated type definitions file
tests/cmpbenchtests/generated_cmp_perf_pointer_test.go Added comprehensive 9097-line pointer-based benchmark tests
tests/cmpbenchtests/generate_cmp_benchtests_main.go Deleted 134-line template generation utility

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 6 out of 7 changed files in this pull request and generated 4 comments.

@alexgarzao alexgarzao merged commit 4fd63b7 into main Nov 4, 2025
4 checks passed
@alexgarzao alexgarzao deleted the 93-refactor-testgen branch November 4, 2025 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants