|
1 | | -import { Condition, evaluateCondition, getArchitecture, getToolset } from '@cmt/presets/preset'; |
| 1 | +import { Condition, configureArgs, evaluateCondition, getArchitecture, getToolset } from '@cmt/presets/preset'; |
2 | 2 | import { expect } from '@test/util'; |
3 | 3 | import * as os from "os"; |
4 | 4 |
|
@@ -127,4 +127,72 @@ suite('Preset tests', () => { |
127 | 127 | badCondition = { type: 'equals', lhs: 'lhs' }; |
128 | 128 | expect(() => evaluateCondition(badCondition)).to.throw(); |
129 | 129 | }); |
| 130 | + |
| 131 | + test('configureArgs skips $comment keys in cacheVariables', () => { |
| 132 | + // Test that $comment at the top level of cacheVariables is skipped |
| 133 | + const preset1: any = { |
| 134 | + name: 'test', |
| 135 | + cacheVariables: { |
| 136 | + '$comment': 'This is a comment', |
| 137 | + 'CMAKE_BUILD_TYPE': 'Debug' |
| 138 | + } |
| 139 | + }; |
| 140 | + const args1 = configureArgs(preset1); |
| 141 | + expect(args1).to.deep.eq(['-DCMAKE_BUILD_TYPE=Debug']); |
| 142 | + expect(args1.some(arg => arg.includes('$comment'))).to.eq(false); |
| 143 | + |
| 144 | + // Test that $comment as an array (multi-line) is also skipped |
| 145 | + const preset2: any = { |
| 146 | + name: 'test', |
| 147 | + cacheVariables: { |
| 148 | + '$comment': ['Line 1', 'Line 2'], |
| 149 | + 'MY_VAR': 'value' |
| 150 | + } |
| 151 | + }; |
| 152 | + const args2 = configureArgs(preset2); |
| 153 | + expect(args2).to.deep.eq(['-DMY_VAR=value']); |
| 154 | + |
| 155 | + // Test with object-style cache variable with $comment inside the object |
| 156 | + // This is the main use case from issue #4709 - $comment inside cacheVariable object |
| 157 | + const preset3: any = { |
| 158 | + name: 'test', |
| 159 | + cacheVariables: { |
| 160 | + 'CMAKE_EXE_LINKER_FLAGS': { |
| 161 | + type: 'STRING', |
| 162 | + '$comment': 'Suppress warning about free-nonheap-object', |
| 163 | + value: '-Wno-error=free-nonheap-object' |
| 164 | + } |
| 165 | + } |
| 166 | + }; |
| 167 | + const args3 = configureArgs(preset3); |
| 168 | + expect(args3).to.deep.eq(['-DCMAKE_EXE_LINKER_FLAGS:STRING=-Wno-error=free-nonheap-object']); |
| 169 | + // Verify $comment inside the object doesn't affect the output |
| 170 | + expect(args3.some(arg => arg.includes('$comment'))).to.eq(false); |
| 171 | + |
| 172 | + // Test with $comment both at top level and inside object |
| 173 | + const preset4: any = { |
| 174 | + name: 'test', |
| 175 | + cacheVariables: { |
| 176 | + '$comment': 'Top-level comment', |
| 177 | + 'CMAKE_BUILD_TYPE': { |
| 178 | + type: 'STRING', |
| 179 | + '$comment': 'Build type comment', |
| 180 | + value: 'Release' |
| 181 | + } |
| 182 | + } |
| 183 | + }; |
| 184 | + const args4 = configureArgs(preset4); |
| 185 | + expect(args4).to.deep.eq(['-DCMAKE_BUILD_TYPE:STRING=Release']); |
| 186 | + expect(args4.some(arg => arg.includes('$comment'))).to.eq(false); |
| 187 | + |
| 188 | + // Test empty cacheVariables (should produce no args) |
| 189 | + const preset5: any = { |
| 190 | + name: 'test', |
| 191 | + cacheVariables: { |
| 192 | + '$comment': 'Only comment, no vars' |
| 193 | + } |
| 194 | + }; |
| 195 | + const args5 = configureArgs(preset5); |
| 196 | + expect(args5).to.deep.eq([]); |
| 197 | + }); |
130 | 198 | }); |
0 commit comments