Skip to content

v1.2.0

Choose a tag to compare

@maxgreen01 maxgreen01 released this 05 Aug 02:39
· 43 commits to main since this release

This version introduces the ability to refactor test cases as part of the Analyze command! The only refactoring strategy available in this version is to add t.Run() subtests to table-driven tests that don't have it already, but a framework has been established to allow additional strategies in the future!

image

What's Changed

✨ New Features

  • Implement "subtest" refactoring strategy in Analyze command
    • Execute all tests before and after refactoring to verify success without modifying behavior
    • Output clearly differentiates between errors in the refactor generation and execution phases using various new struct types
    • Save refactoring changes on disk for manual analysis using keep-refactored-files option, or revert files to their original state by default
    • Avoids compilation errors by modifying the scenario runner if needed:
      • Replaces some continue statements with return to indicate that the test should pass without performing more logic
      • Modifies the scenario runner's "loop key" variable if scenario names are stored as a map key, instead of trying to access a scenario struct field
      • Detects the *testing.T parameter name dynamically as opposed to hardcoding it
    • Example output: ollama_api_TestMessage_UnmarshalJSON.json
  • Clone helper functions internally during refactoring to avoid interference with multiple test cases
  • Completely expand package-local helper function calls within test cases
    • This opens the door for more detailed analysis when helper functions are used to extract test logic
  • Minor scenario field detection improvements
    • Prioritize detecting scenario name field from the first t.Run() argument
    • Enforce that scenario name field must be a string
    • Update scenario runner field to store entire loop statement instead of just the body
    • Require scenario runner to be detected directly in the test function to reduce table-driven test false positives
  • Remove timer option, leaving it enabled permanently

🐛 Bug Fixes

  • Fix nil pointer dereference for empty or non-analyzed test cases
  • Scenario fields of user-defined type with underlying string type are no longer considered a valid scenario name
  • Table-driven tests using a map like map[string]bool now properly detect the use of t.Run()

🛠️ Internal Improvements

  • Completely restructure testcase package structure (see b9fa7c1)
  • Create internal/asttools package to hold AST-related util functions

Full Changelog: v1.1.1...v1.2.0