|
1 | | -import { Condition, configureArgs, evaluateCondition, getArchitecture, getToolset } from '@cmt/presets/preset'; |
| 1 | +import { buildArgs, 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 |
|
@@ -195,4 +195,83 @@ suite('Preset tests', () => { |
195 | 195 | const args5 = configureArgs(preset5); |
196 | 196 | expect(args5).to.deep.eq([]); |
197 | 197 | }); |
| 198 | + |
| 199 | + test('buildArgs handles jobs: 0 correctly', () => { |
| 200 | + const preset: any = { |
| 201 | + name: 'test', |
| 202 | + __binaryDir: '/path/to/build', |
| 203 | + jobs: 0 |
| 204 | + }; |
| 205 | + const args = buildArgs(preset); |
| 206 | + expect(args).to.include('-j'); |
| 207 | + // -j should be bare (no value) — next arg should NOT be '0' |
| 208 | + const idx = args.indexOf('-j'); |
| 209 | + expect(args[idx + 1]).to.not.eq('0'); |
| 210 | + }); |
| 211 | + |
| 212 | + test('buildArgs handles jobs: positive number', () => { |
| 213 | + const preset: any = { |
| 214 | + name: 'test', |
| 215 | + __binaryDir: '/path/to/build', |
| 216 | + jobs: 8 |
| 217 | + }; |
| 218 | + const args = buildArgs(preset); |
| 219 | + const idx = args.indexOf('--parallel'); |
| 220 | + expect(idx).to.be.greaterThan(-1); |
| 221 | + expect(args[idx + 1]).to.eq('8'); |
| 222 | + }); |
| 223 | + |
| 224 | + test('buildArgs omits -j and --parallel when jobs is undefined and no fallback', () => { |
| 225 | + const preset: any = { |
| 226 | + name: 'test', |
| 227 | + __binaryDir: '/path/to/build' |
| 228 | + }; |
| 229 | + const args = buildArgs(preset); |
| 230 | + expect(args).to.not.include('-j'); |
| 231 | + expect(args).to.not.include('--parallel'); |
| 232 | + }); |
| 233 | + |
| 234 | + test('buildArgs uses fallbackJobs when jobs is undefined', () => { |
| 235 | + const preset: any = { |
| 236 | + name: 'test', |
| 237 | + __binaryDir: '/path/to/build' |
| 238 | + }; |
| 239 | + const args = buildArgs(preset, undefined, undefined, 4); |
| 240 | + const idx = args.indexOf('--parallel'); |
| 241 | + expect(idx).to.be.greaterThan(-1); |
| 242 | + expect(args[idx + 1]).to.eq('4'); |
| 243 | + }); |
| 244 | + |
| 245 | + test('buildArgs prefers preset jobs over fallbackJobs', () => { |
| 246 | + const preset: any = { |
| 247 | + name: 'test', |
| 248 | + __binaryDir: '/path/to/build', |
| 249 | + jobs: 2 |
| 250 | + }; |
| 251 | + const args = buildArgs(preset, undefined, undefined, 8); |
| 252 | + const idx = args.indexOf('--parallel'); |
| 253 | + expect(idx).to.be.greaterThan(-1); |
| 254 | + expect(args[idx + 1]).to.eq('2'); |
| 255 | + }); |
| 256 | + |
| 257 | + test('buildArgs preset jobs: 0 takes precedence over fallbackJobs', () => { |
| 258 | + const preset: any = { |
| 259 | + name: 'test', |
| 260 | + __binaryDir: '/path/to/build', |
| 261 | + jobs: 0 |
| 262 | + }; |
| 263 | + const args = buildArgs(preset, undefined, undefined, 8); |
| 264 | + expect(args).to.include('-j'); |
| 265 | + expect(args).to.not.include('--parallel'); |
| 266 | + }); |
| 267 | + |
| 268 | + test('buildArgs uses fallbackJobs: 0 to pass bare -j', () => { |
| 269 | + const preset: any = { |
| 270 | + name: 'test', |
| 271 | + __binaryDir: '/path/to/build' |
| 272 | + }; |
| 273 | + const args = buildArgs(preset, undefined, undefined, 0); |
| 274 | + expect(args).to.include('-j'); |
| 275 | + expect(args).to.not.include('--parallel'); |
| 276 | + }); |
198 | 277 | }); |
0 commit comments