-
-
Notifications
You must be signed in to change notification settings - Fork 0
Comparing changes
Open a pull request
base repository: Testably/Mockolate
base: v3.0.0
head repository: Testably/Mockolate
compare: v3.1.0
- 18 commits
- 122 files changed
- 1 contributor
Commits on Apr 30, 2026
-
refactor: fix sonar issues (#737)
This pull request includes several improvements and fixes across both the source generator code and the test suite. The most significant changes enhance the robustness of equality checks for the `Class` entity, improve handling of nested type names, and update test code to support cancellation tokens for better compatibility and reliability. **Entities and Equality Improvements:** * Refactored the `Class` entity's equality logic to ensure equality is based on both the class's full name and a content-derived hash of its member surface, making incremental builds more reliable and preventing stale cache issues. The `Equals(Class? other)` method is now more robust and includes detailed documentation. * Moved the declaration of key `Class` properties (like `Methods`, `Properties`, etc.) to a more logical location in the file for clarity and maintainability. **Nested Type Name Handling:** * Improved the logic for constructing `ClassName` for nested types by building the name using a list and a `StringBuilder`, ensuring correct ordering and formatting for deeply nested types. **Code Quality and Style:** * Added and restored a pragma directive to suppress the "too many parameters" warning for the `Class` constructor, clarifying intentional design and suppressing unnecessary linter noise. **Test Suite Enhancements:** * Updated test code to consistently use `TestContext.Current.CancellationToken` when working with Roslyn APIs and multithreading primitives, improving test reliability and compatibility across frameworks (notably for .NET 4.8). * Clarified the type signature in test setup lambdas for `MockBehavior.Initialize`, improving readability and type safety.
Configuration menu - View commit details
-
Copy full SHA for 88fcffa - Browse repository at this point
Copy the full SHA 88fcffaView commit details
Commits on May 1, 2026
-
perf: defer per-mock allocations in ChunkedSlotStorage and MockScenar…
…ioSetup (#738) Mock construction eagerly allocated infrastructure that an unused mock never touches. Two cuts: - `ChunkedSlotStorage` no longer field-initializes `Chunks` and `VerifiedChunks`. They get allocated by `EnsureChunk` on the first `SlotForWrite`. Saves two arrays per `FastMethodNBuffer` for buffers that never record an interaction. `Clear` short-circuits when no slots were ever published. - `MockScenarioSetup` no longer eagerly instantiates the four collection wrappers (`Events`, `Indexers`, `Methods`, `Properties`). Each is created lazily via `Interlocked.CompareExchange` on first read; the wrappers' internal storage was already lazy. `ToString` now reads the backing fields directly so debugger display stays allocation-free for empty buckets. Public API and behavior unchanged. Construction allocation drops by ~300 B for a 3-method interface; per-invocation paths are unchanged once the wrappers are warmed up.
Configuration menu - View commit details
-
Copy full SHA for 57d4df8 - Browse repository at this point
Copy the full SHA 57d4df8View commit details -
perf: defer diagnostic formatting of by-value setup matchers (#739)
The source generator emitted `IFormattable.ToString(null, InvariantCulture)` on every by-value setup arg to capture a diagnostic representation that is only ever read by failure messages. The success path paid a fresh ~24-byte string allocation per primitive arg for nothing. Add `It.IsValue<T>(T)` — public + `EditorBrowsable.Never` because the generator emits it from consumer assemblies — that stores only the value. `ParameterEqualsMatch<T>` formats lazily on first `ToString()` and reproduces the existing four-branch shape (null, string, IFormattable, fallback). Update `AppendNamedValueParameter` to emit the lazy overload, collapsing the four eager-formatting branches into a single call site. Measured on a new `CombinedWorkflowBenchmarks` (mirrors the TUnit combined- workflow benchmark — 2 mocks, 3 setups, 4 invokes, 4 verifies): Pre 9648 B/iter Post 9600 B/iter (-48 B = 2 × 24 B, exact match for the prediction) Time impact is below this benchmark's noise floor on this workflow (each iteration allocates ~9.6 KB; GC variance dominates a ~100-200 ns saving), but the win compounds linearly with the number of by-value setup args per test, so larger suites benefit more.Configuration menu - View commit details
-
Copy full SHA for 9e45e57 - Browse repository at this point
Copy the full SHA 9e45e57View commit details -
feat: enhance benchmark reporting by filtering out specified columns (#…
…742) Updates the Nuke benchmark-comment generation to drop selected BenchmarkDotNet markdown table columns before posting results to PRs, and expands the PR CI benchmark matrix to run the new mock-creation benchmark suite. **Changes:** - Filter out specific BenchmarkDotNet table columns (e.g., `RatioSD`, `Gen0`, `Gen1`) when generating the PR benchmark comment body. - Add `MockCreationBenchmarks` to the benchmark matrix in the PR CI workflow.
Configuration menu - View commit details
-
Copy full SHA for 99c558f - Browse repository at this point
Copy the full SHA 99c558fView commit details -
refactor: improve table row parsing by introducing SplitTableRow meth…
…od (#743) This pull request refactors how table rows are split and parsed in the benchmark comment generation logic. The main change is the introduction of a new helper method to consistently handle table row splitting, improving code clarity and reducing duplication. **Refactoring and code quality improvements:** * Introduced a new helper method `SplitTableRow` to standardize how table rows are split and parsed, ensuring consistent handling of table formatting. (`Pipeline/Build.Benchmarks.cs`) * Updated `DetermineDroppedColumnIndices` and `RemoveColumns` to use the new `SplitTableRow` method instead of directly splitting on the `|` character, which simplifies the logic and makes it more robust.
Configuration menu - View commit details
-
Copy full SHA for b8e56d9 - Browse repository at this point
Copy the full SHA b8e56d9View commit details -
fix: also remove "Gen2" from benchmark tables (#745)
This pull request makes improvements to the benchmark suite and its reporting. The main changes include standardizing benchmark method names for clarity and updating the benchmark report to exclude an additional column. **Benchmark code cleanup and consistency:** * Renamed benchmark methods in `MockCreationBenchmarks.cs` to follow a consistent `CreateMock_*` naming convention, and removed the `Description` parameter from `[Benchmark]` attributes for cleaner output. **Benchmark report formatting:** * Updated the `CreateBenchmarkCommentBody` method in `Build.Benchmarks.cs` to also remove the `Gen2` column from benchmark reports, in addition to the previously removed columns.
Configuration menu - View commit details
-
Copy full SHA for 19ef16f - Browse repository at this point
Copy the full SHA 19ef16fView commit details -
feat: add baseline benchmark comparison to reporting (#744)
This pull request enhances the benchmark reporting workflow by enabling comparison with previous main-branch benchmark results and refactoring artifact download utilities. The main focus is to automatically fetch and inject baseline benchmark results into pull request comments, making regression detection easier. Several utility methods for downloading and parsing artifacts from GitHub Actions have been added or improved. **Benchmark baseline comparison and reporting:** * The benchmark reporting logic in `Build.Benchmarks.cs` was updated to download benchmark artifacts from recent successful main branch runs and inject corresponding baseline results into the PR comment, allowing for regression comparisons. Baseline rows are clearly marked and explained in the comment. * Introduced the `BenchmarkTableParser` helper class to robustly parse and process markdown benchmark tables, supporting the new baseline injection logic. **Artifact download and GitHub Actions integration:** * Added new utility methods in `BuildExtensions.cs` to find recent successful workflow run IDs, and to download artifacts from specific runs or based on name prefixes. These methods use the GitHub API and improve error handling and logging. * Refactored artifact download logic to use a constant for the repository API base URL and to support both environment-based and explicit run ID selection. **CI workflow improvements:** * Updated `.github/workflows/build.yml` to always upload benchmark artifacts after running benchmarks, ensuring that results are available for baseline comparison in future PRs. **General code improvements:** * Added missing `using` statements for required namespaces in both `Build.Benchmarks.cs` and `BuildExtensions.cs`.
Configuration menu - View commit details
-
Copy full SHA for 3eb0d03 - Browse repository at this point
Copy the full SHA 3eb0d03View commit details -
refactor: enhance benchmark table display names (#746)
This pull request refactors and improves the logic for generating benchmark comparison comments in `Pipeline/Build.Benchmarks.cs`. The main focus is on restructuring how benchmark tables are parsed, buffered, and rendered, especially to support clearer baseline injection and improved table formatting. **Benchmark table processing and formatting improvements:** * Introduced a `TableRow` record and a table buffer to accumulate table rows before rendering, allowing for more flexible processing and baseline injection. The logic for flushing the buffer and injecting baselines has been moved to a new `FlushTableBuffer` method. * Added logic to detect and strip common prefixes from benchmark row names, improving table readability. This is handled by the new `FindCommonRowPrefix` and `ApplyHeaderAndPrefixStripping` helper methods. * The summary comment now includes an explanatory note about `baseline*` rows only if a baseline was actually injected, making the output more relevant and less cluttered. * Improved the logic for identifying and bolding Mockolate rows, ensuring only relevant rows are highlighted and displayed in the correct format. These changes collectively make the benchmark result comments more accurate, easier to read, and better structured for regression comparison.
Configuration menu - View commit details
-
Copy full SHA for 381840a - Browse repository at this point
Copy the full SHA 381840aView commit details -
coverage: add build tests (#747)
This pull request introduces a significant refactor to how benchmark report markdown is generated and processed, as well as some project/solution configuration improvements. The main change is the extraction of all the logic for parsing and formatting BenchmarkDotNet markdown tables into a new dedicated file (`BenchmarkReport.cs`). This makes the codebase cleaner, more modular, and easier to test and maintain. Additionally, the setup for unit testing and project visibility has been improved. **Key changes include:** ### Benchmark Report Refactor and Improvements - Extracted all logic for parsing, transforming, and formatting BenchmarkDotNet markdown tables from `Build.Benchmarks.cs` into a new file, `BenchmarkReport.cs`, encapsulating the logic in the new `BenchmarkReport` class and related types. This includes table parsing, column removal, baseline injection, and markdown formatting. (`Pipeline/BenchmarkReport.cs`) - Simplified `CreateBenchmarkCommentBody` in `Build.Benchmarks.cs` to delegate all report processing to the new `BenchmarkReport.BuildBody` method, improving clarity and separation of concerns. (`Pipeline/Build.Benchmarks.cs`) - Removed now-unneeded using directives from `Build.Benchmarks.cs` after refactoring. (`Pipeline/Build.Benchmarks.cs`) ### Project and Solution Configuration - Added the `Build.Tests` project to the solution file and included it in the `UnitTestProjects` array, ensuring it is built and tested as part of the solution. (`Mockolate.slnx`, `Pipeline/Build.UnitTest.cs`) - Added an `InternalsVisibleTo` entry for `Build.Tests` in `Build.csproj`, allowing the test project to access internal members for better test coverage. (`Pipeline/Build.csproj`) ### Build Schema Update - Added a new `BenchmarkFilter` property to the build schema, allowing filtering of benchmarks via configuration. (`.nuke/build.schema.json`)
Configuration menu - View commit details
-
Copy full SHA for ace2d4a - Browse repository at this point
Copy the full SHA ace2d4aView commit details -
perf: optimize generator-emitted setups by skipping dual registration (…
…#741) This pull request makes significant improvements to how mock setups (methods, indexers, and events) are registered, stored, and enumerated in the Mockolate mocking framework. The changes focus on optimizing storage for generator-emitted setups, ensuring fast-path dispatch, and improving diagnostics and verification, especially for unused setups. The most important changes are grouped below: ### Storage and Registration Optimizations * **Generator-emitted setups now bypass string-keyed lists for default-scope registrations:** Instead, they are stored only in memberId-keyed snapshot tables, making snapshot storage authoritative for fast dispatch and reducing unnecessary allocations. This affects `SetupMethod`, `SetupIndexer`, and `SetupEvent` registration logic. * **Scenario-scoped setups remain in scenario buckets; default-scope setups use snapshots:** Registration methods now clearly separate scenario and default-scope behaviors, ensuring correct storage and lookup. ### Fast-path Dispatch and Enumeration * **New enumeration logic for method, indexer, and event setups:** Methods like `GetMethodSetups<T>`, `GetMatchingIndexerSetupFromSnapshot`, and `GetEventSetupsByName` now walk snapshot tables for default-scope setups, ensuring generator-emitted setups are found efficiently and without unnecessary allocations. * **Empty-storage fast paths return `Array.Empty<T>`:** This prevents iterator state machine allocations on hot paths when no setups are registered, improving performance. ### Diagnostics and Verification Improvements * **Unused setup enumeration now includes snapshot tables:** The verification logic for unused setups now checks both string-keyed lists and snapshot tables, ensuring that generator-emitted setups are included in diagnostic reports. * **Improved documentation and remarks:** XML comments have been updated to clarify the new storage and dispatch behaviors, making the codebase easier to understand and maintain.
Configuration menu - View commit details
-
Copy full SHA for aac7d35 - Browse repository at this point
Copy the full SHA aac7d35View commit details -
feat: implement baseline ratio computation and unit normalization in …
…benchmark reporting (#748) This pull request enhances the `BenchmarkReport` functionality to improve the handling and comparison of benchmark data, especially when working with baselines that may use different units for time and memory. The main changes include normalizing units for accurate ratio calculations, recomputing ratios for baseline rows, and ensuring empty rows are formatted consistently with the table header. Comprehensive tests have been added to verify these behaviors. **Enhancements to Baseline Handling and Ratio Computation:** * Added logic to normalize time and memory units (e.g., ns, μs, ms, KB, MB) to a common base (nanoseconds for time, bytes for memory) for accurate ratio calculations between baseline and current benchmark results. * Implemented the `RecomputeBaselineRatio` method to recompute the "Ratio" and "Alloc Ratio" values for baseline rows relative to the current benchmark, ensuring unit differences are handled and results are accurate. **Table Formatting Improvements:** * Modified the table rendering logic to emit empty rows that match the header's column count when separating parameter groups, improving the readability and consistency of the generated tables. **Utility and Helper Improvements:** * Introduced `FindColumnIndex` for case-insensitive column name lookup, improving robustness when handling table headers. **Testing Enhancements:** * Added and extended tests to verify unit normalization, baseline ratio recomputation, empty row formatting, and column index lookup, ensuring reliability and correctness of new features.
Configuration menu - View commit details
-
Copy full SHA for 29efc63 - Browse repository at this point
Copy the full SHA 29efc63View commit details -
This pull requests fixes a build error accidentally introduced in #748 that caused the build pipeline to not compile.
Configuration menu - View commit details
-
Copy full SHA for c5047af - Browse repository at this point
Copy the full SHA c5047afView commit details -
perf: lazy-allocate per-member fast buffers on first record (#740)
## Summary Lazy-allocates per-member `FastMockInteractions` buffers on first record instead of installing all of them up-front in the generator-emitted `CreateFastInteractions(behavior)`. Wide interfaces with many members but few exercised paths now skip the up-front allocation cost. The generated `CreateFastInteractions` collapses from a body that loops over every method/property/indexer/event and calls `Install*` to a one-line expression body that returns a fresh `FastMockInteractions(MemberCount, ...)`. Buffers materialize on first call to `GetOrCreateBuffer`, which uses a CAS for thread-safety and a `static`-lambda factory so the lazy path stays closure-free. A second `GetOrCreateBuffer<TBuffer, TState>(int, Func<FastMockInteractions, TState, TBuffer>, TState)` overload exists for buffers that need a construction parameter (e.g. `FastPropertyGetterBuffer` needs the shared `PropertyGetterAccess` singleton) without forcing a closure allocation. ## Breaking changes The `Source/Mockolate/Interactions/` public surface that supported eager installation has been removed. These were public solely to be callable from generator-emitted code; the source generator no longer emits any reference to them. Removed: - `FastEventBufferFactory` (+ `InstallEventSubscribe`, `InstallEventUnsubscribe`) - `FastIndexerBufferFactory` (+ `InstallIndexerGetter<…>`, `InstallIndexerSetter<…>`) - `FastMethodBufferFactory` (+ `InstallMethod<…>`) - `FastPropertyBufferFactory` (+ `InstallPropertyGetter`, `InstallPropertySetter<T>`) - `FastMockInteractions.InstallBuffer(int, IFastMemberBuffer)` - `MockRegistry.GetPropertyFast<TResult>(int, string, …)` — the `string` propertyName overload; the `PropertyGetterAccess` overload remains and is the only path the generator now emits - `FastPropertyGetterBuffer.Append(string name)` — paired with the removed string-name `GetPropertyFast` overload; the parameterless `Append()` uses the buffer's pre-seeded `PropertyGetterAccess` singleton Added: - `FastMockInteractions.GetOrCreateBuffer<TBuffer>(int, Func<FastMockInteractions, TBuffer>)` - `FastMockInteractions.GetOrCreateBuffer<TBuffer, TState>(int, Func<FastMockInteractions, TState, TBuffer>, TState)` - Public constructors on `FastEventBuffer`, `FastIndexerGetterBuffer<…>`, `FastIndexerSetterBuffer<…>`, `FastMethod{0..4}Buffer<…>`, `FastPropertyGetterBuffer`, `FastPropertySetterBuffer<T>` (previously only constructable through the removed factories) ### Migration Regenerate sources — the source generator has been updated and emits the new lazy pattern. Hand-written code against the removed factories must move to `GetOrCreateBuffer`: ```csharp // before FastMethod0Buffer buffer = fast.InstallMethod(memberId); // after FastMethod0Buffer buffer = fast.GetOrCreateBuffer<FastMethod0Buffer>( memberId, static f => new FastMethod0Buffer(f)); ``` For `FastPropertyGetterBuffer`, use the state-passing overload to forward the access singleton without a closure: ```csharp FastPropertyGetterBuffer buffer = fast.GetOrCreateBuffer<FastPropertyGetterBuffer, PropertyGetterAccess>( memberId, static (f, a) => new FastPropertyGetterBuffer(f, a), access); ``` API snapshots in `Tests/Mockolate.Api.Tests/Expected/` have been updated to reflect the new surface.Configuration menu - View commit details
-
Copy full SHA for 7f5a215 - Browse repository at this point
Copy the full SHA 7f5a215View commit details -
feat: bind
Method(default, …)to the by-values overload (#750)Promote the all-values setup/verify overload to `OverloadResolutionPriority(int.MaxValue)` so untyped `default` arguments resolve to it instead of the matcher (`IParameter<T>?`) overload. Callers can now chain `.AnyParameters()` on those calls — matching NSubstitute's `ReturnsForAnyArgs` ergonomics for migration. Adjust the rest of the priority hierarchy to keep ordering unambiguous: - all-values : int.MaxValue - IParameters : int.MaxValue - 1 - pure IParameter<T>?: parameterCount - mixed : count of non-value (matcher) params Skip the all-values bump when any value-flag-true parameter is `object` — `IParameter<object?>?` is itself an object reference, so the bump would silently capture matcher instances passed to `Equals(object?)` and similar. Those signatures keep the historical behavior; callers continue to use `Match.AnyParameters()`. Snapshot fixtures updated; the public API surface is unchanged because the by-values return types (`IReturnMethodSetupParameterIgnorer`, `VerificationResult<>.IgnoreParameters`) are subtypes of the previously bound types.
Configuration menu - View commit details
-
Copy full SHA for c28709e - Browse repository at this point
Copy the full SHA c28709eView commit details -
docs: update migration package description to include NSubstitute sup…
…port (#751) Updates the project’s public-facing docs to reflect that the companion `Mockolate.Migration` package supports migrating from NSubstitute in addition to Moq.
Configuration menu - View commit details
-
Copy full SHA for 200d0bb - Browse repository at this point
Copy the full SHA 200d0bbView commit details
Commits on May 2, 2026
-
refactor: move source-generated mock to top of file (#752)
This pull request refactors the code generation logic in `Sources.MockDelegate.cs` to improve code readability and maintainability by consolidating and simplifying string building operations. The changes primarily focus on flattening multi-line string concatenations into single lines where possible, removing redundant regions, and streamlining the structure of generated code for mock delegates. **Refactoring and Code Simplification:** * Consolidated multi-line string concatenations into single-line statements throughout the `MockDelegate` method, making the code easier to read and maintain. **Structural and Organizational Improvements:** * Removed the `MockForXXXExtensions` region and merged its logic into the main `Mock` class, reducing unnecessary indirection and clarifying the generated class structure. **Consistency and Formatting:** * Standardized formatting for method and property generation, including XML summaries, attribute annotations, and method bodies, to ensure consistent output from the source generator. **Parameter Handling:** * Simplified logic for handling delegate method parameters, especially in scenarios involving `ref` and `out` parameters, by flattening conditional and loop structures. **Mock Setup and Verification:** * Streamlined the generation of setup and verification methods by consolidating method calls and reducing code duplication for different parameter combinations.
Configuration menu - View commit details
-
Copy full SHA for 6415600 - Browse repository at this point
Copy the full SHA 6415600View commit details -
fix: make source generator snapshot build configuration invariant (#753)
This pull request removes the `[DebuggerNonUserCode]` attribute from several classes and methods in multiple generated test files. The change is consistently applied across different snapshot files related to mock behavior extensions, aiming to simplify the generated code and avoid suppressing debugger stepping for these code sections. The most important changes are: **Attribute Removal (Code Simplification):** * Removed the `[DebuggerNonUserCode]` attribute from internal classes such as `TypedDefaultValueFactory<T>`, `DefaultValueGenerator`, `CancellableTaskFactory`, `CancellableValueTaskFactory`, and `HttpResponseMessageFactory` in all affected snapshot files. This makes the generated code more transparent during debugging. **Consistency Across Snapshots:** * Ensured that the removal of `[DebuggerNonUserCode]` is applied consistently in all snapshot files for different test scenarios (BaseClass_WithMultipleAdditionalInterfaces, ComprehensiveAbstractClass, ComprehensiveDelegate, ComprehensiveInterface, HttpClient). **Debugging Experience:** * By removing this attribute, the generated code will no longer be hidden from the debugger, which can help developers step through and diagnose issues more effectively in test scenarios. No functional logic is altered; this is a code generation and debugging experience improvement.
Configuration menu - View commit details
-
Copy full SHA for 681a2cf - Browse repository at this point
Copy the full SHA 681a2cfView commit details -
refactor: enable nullable reference types in BenchmarkReport (#754)
This pull request refactors the `Pipeline/BenchmarkReport.cs` file to modernize and simplify the code, making it more idiomatic and concise. The changes focus on improving code readability, reducing redundancy, and leveraging newer C# features such as target-typed `new`, nullable reference types, and pattern-based null checks. **Key improvements include:** ### Code Modernization & Simplification * Replaced explicit type declarations with `var` where appropriate, streamlined null checks, and used target-typed `new` for object initialization, resulting in more concise and readable code throughout the file. * Replaced multi-line `if` statements with single-line expressions where possible, and simplified method bodies by removing unnecessary braces and lines. ### Nullable Reference Types & Type Safety * Updated methods and parameters to use nullable reference types (e.g., `string[]?`) and added `[NotNullWhen(true)]` attributes to improve type safety and nullability awareness. ### Access Modifiers & Redundant Code * Removed the `internal` access modifier from classes and records that did not require it, making them package-private and simplifying the file. * Removed redundant using directives and unnecessary comments, and suppressed certain ReSharper warnings for clarity.
Configuration menu - View commit details
-
Copy full SHA for 812a93f - Browse repository at this point
Copy the full SHA 812a93fView commit details
This comparison is taking too long to generate.
Unfortunately it looks like we can’t render this comparison for you right now. It might be too big, or there might be something weird with your repository.
You can try running this command locally to see the comparison on your machine:
git diff v3.0.0...v3.1.0