Commit 591e23d
Detect injected properties in base classes (#3081)
* Fix InheritsTests source location to show actual test method location
Resolves issue #3055 where tests using [InheritsTests] attribute
reported source location at the attribute location instead of the
actual test method location.
Changes:
- Added GetMethodLocation helper to extract actual method source location
- Modified GenerateInheritedTestSources to use method location when available
- Falls back to class location if method location unavailable
- Updated snapshot tests to reflect correct line numbers
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
* Simplify fix to use TestAttribute's CallerFilePath and CallerLineNumber
Improved the source location fix by leveraging the existing CallerFilePath
and CallerLineNumber parameters in TestAttribute constructor arguments,
which are automatically captured when the [Test] attribute is applied.
This approach is:
- Simpler and more reliable than parsing syntax trees
- Uses the built-in compiler-provided location information
- Removes the need for the GetMethodLocation helper method
- More consistent with how regular test methods get their source location
The TestAttribute already captures the exact file and line number via
[CallerFilePath] and [CallerLineNumber] attributes, making this the
preferred approach for getting accurate source locations.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
* Remove redundant comments
* Fix InheritsTests line numbers to reflect correct test method locations
* Refactor PropertyInjectionSourceGenerator and RequiredPropertyHelper for clarity and efficiency; add tests for bug 3072
* Enhance PropertyInjectionSourceGenerator to skip non-public and unbound generic types; deduplicate class sources for improved efficiency
* Fix line numbers in verified test files for accurate test method locations
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 348c5cc commit 591e23d
File tree
4 files changed
+125
-69
lines changed- TUnit.Core.SourceGenerator
- CodeGenerators/Helpers
- Generators
- TUnit.TestProject/Bugs/3072
4 files changed
+125
-69
lines changedLines changed: 10 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
57 | 60 | | |
58 | 61 | | |
59 | 62 | | |
| |||
85 | 88 | | |
86 | 89 | | |
87 | 90 | | |
88 | | - | |
| 91 | + | |
Lines changed: 76 additions & 61 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | 1 | | |
3 | | - | |
4 | 2 | | |
5 | 3 | | |
6 | 4 | | |
| |||
27 | 25 | | |
28 | 26 | | |
29 | 27 | | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
| 28 | + | |
47 | 29 | | |
48 | 30 | | |
49 | 31 | | |
| |||
56 | 38 | | |
57 | 39 | | |
58 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
59 | 54 | | |
60 | 55 | | |
61 | 56 | | |
| |||
67 | 62 | | |
68 | 63 | | |
69 | 64 | | |
70 | | - | |
71 | 65 | | |
72 | 66 | | |
73 | | - | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
74 | 72 | | |
75 | | - | |
| 73 | + | |
76 | 74 | | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
| 75 | + | |
99 | 76 | | |
100 | 77 | | |
101 | | - | |
102 | | - | |
103 | | - | |
| 78 | + | |
104 | 79 | | |
105 | | - | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
106 | 90 | | |
107 | 91 | | |
108 | 92 | | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | 93 | | |
116 | 94 | | |
117 | 95 | | |
| |||
124 | 102 | | |
125 | 103 | | |
126 | 104 | | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
127 | 135 | | |
128 | 136 | | |
129 | 137 | | |
| |||
135 | 143 | | |
136 | 144 | | |
137 | 145 | | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
138 | 152 | | |
139 | 153 | | |
140 | | - | |
| 154 | + | |
141 | 155 | | |
142 | 156 | | |
143 | 157 | | |
144 | 158 | | |
145 | 159 | | |
146 | | - | |
| 160 | + | |
147 | 161 | | |
148 | | - | |
| 162 | + | |
149 | 163 | | |
150 | 164 | | |
151 | 165 | | |
| |||
218 | 232 | | |
219 | 233 | | |
220 | 234 | | |
221 | | - | |
| 235 | + | |
222 | 236 | | |
223 | 237 | | |
224 | 238 | | |
| |||
344 | 358 | | |
345 | 359 | | |
346 | 360 | | |
347 | | - | |
348 | | - | |
349 | | - | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
350 | 365 | | |
351 | 366 | | |
352 | 367 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | 10 | | |
12 | 11 | | |
13 | 12 | | |
| |||
0 commit comments