Skip to content

Commit 2d899f9

Browse files
authored
Merge pull request #1753 from charlespierce/const_borrows
Update cli_platform tests to use 'const' correctly
2 parents 08219c5 + c5ad999 commit 2d899f9

File tree

1 file changed

+53
-36
lines changed

1 file changed

+53
-36
lines changed

crates/volta-core/src/platform/tests.rs

Lines changed: 53 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,28 @@ mod inherit_option {
215215

216216
mod cli_platform {
217217
use node_semver::Version;
218-
use once_cell::unsync::Lazy;
219218

220-
const NODE_VERSION: Lazy<Version> = Lazy::new(|| Version::from((12, 14, 1)));
221-
const NPM_VERSION: Lazy<Version> = Lazy::new(|| Version::from((6, 13, 2)));
222-
const YARN_VERSION: Lazy<Version> = Lazy::new(|| Version::from((1, 17, 0)));
219+
const NODE_VERSION: Version = Version {
220+
major: 12,
221+
minor: 14,
222+
patch: 1,
223+
build: Vec::new(),
224+
pre_release: Vec::new(),
225+
};
226+
const NPM_VERSION: Version = Version {
227+
major: 6,
228+
minor: 13,
229+
patch: 2,
230+
build: Vec::new(),
231+
pre_release: Vec::new(),
232+
};
233+
const YARN_VERSION: Version = Version {
234+
major: 1,
235+
minor: 17,
236+
patch: 0,
237+
build: Vec::new(),
238+
pre_release: Vec::new(),
239+
};
223240

224241
mod merge {
225242
use super::super::super::*;
@@ -228,7 +245,7 @@ mod cli_platform {
228245
#[test]
229246
fn uses_node() {
230247
let test = CliPlatform {
231-
node: Some(NODE_VERSION.clone()),
248+
node: Some(NODE_VERSION),
232249
npm: InheritOption::default(),
233250
pnpm: InheritOption::default(),
234251
yarn: InheritOption::default(),
@@ -243,7 +260,7 @@ mod cli_platform {
243260

244261
let merged = test.merge(base);
245262

246-
assert_eq!(merged.node.value, NODE_VERSION.clone());
263+
assert_eq!(merged.node.value, NODE_VERSION);
247264
assert_eq!(merged.node.source, Source::CommandLine);
248265
}
249266

@@ -257,23 +274,23 @@ mod cli_platform {
257274
};
258275

259276
let base = Platform {
260-
node: Sourced::with_default(NODE_VERSION.clone()),
277+
node: Sourced::with_default(NODE_VERSION),
261278
npm: None,
262279
pnpm: None,
263280
yarn: None,
264281
};
265282

266283
let merged = test.merge(base);
267284

268-
assert_eq!(merged.node.value, NODE_VERSION.clone());
285+
assert_eq!(merged.node.value, NODE_VERSION);
269286
assert_eq!(merged.node.source, Source::Default);
270287
}
271288

272289
#[test]
273290
fn uses_npm() {
274291
let test = CliPlatform {
275-
node: Some(NODE_VERSION.clone()),
276-
npm: InheritOption::Some(NPM_VERSION.clone()),
292+
node: Some(NODE_VERSION),
293+
npm: InheritOption::Some(NPM_VERSION),
277294
pnpm: InheritOption::default(),
278295
yarn: InheritOption::default(),
279296
};
@@ -288,45 +305,45 @@ mod cli_platform {
288305
let merged = test.merge(base);
289306

290307
let merged_npm = merged.npm.unwrap();
291-
assert_eq!(merged_npm.value, NPM_VERSION.clone());
308+
assert_eq!(merged_npm.value, NPM_VERSION);
292309
assert_eq!(merged_npm.source, Source::CommandLine);
293310
}
294311

295312
#[test]
296313
fn inherits_npm() {
297314
let test = CliPlatform {
298-
node: Some(NODE_VERSION.clone()),
315+
node: Some(NODE_VERSION),
299316
npm: InheritOption::Inherit,
300317
pnpm: InheritOption::default(),
301318
yarn: InheritOption::default(),
302319
};
303320

304321
let base = Platform {
305322
node: Sourced::with_default(Version::from((10, 10, 10))),
306-
npm: Some(Sourced::with_default(NPM_VERSION.clone())),
323+
npm: Some(Sourced::with_default(NPM_VERSION)),
307324
pnpm: None,
308325
yarn: None,
309326
};
310327

311328
let merged = test.merge(base);
312329

313330
let merged_npm = merged.npm.unwrap();
314-
assert_eq!(merged_npm.value, NPM_VERSION.clone());
331+
assert_eq!(merged_npm.value, NPM_VERSION);
315332
assert_eq!(merged_npm.source, Source::Default);
316333
}
317334

318335
#[test]
319336
fn none_does_not_inherit_npm() {
320337
let test = CliPlatform {
321-
node: Some(NODE_VERSION.clone()),
338+
node: Some(NODE_VERSION),
322339
npm: InheritOption::None,
323340
pnpm: InheritOption::default(),
324341
yarn: InheritOption::default(),
325342
};
326343

327344
let base = Platform {
328345
node: Sourced::with_default(Version::from((10, 10, 10))),
329-
npm: Some(Sourced::with_default(NPM_VERSION.clone())),
346+
npm: Some(Sourced::with_default(NPM_VERSION)),
330347
pnpm: None,
331348
yarn: None,
332349
};
@@ -339,10 +356,10 @@ mod cli_platform {
339356
#[test]
340357
fn uses_yarn() {
341358
let test = CliPlatform {
342-
node: Some(NODE_VERSION.clone()),
359+
node: Some(NODE_VERSION),
343360
npm: InheritOption::default(),
344361
pnpm: InheritOption::default(),
345-
yarn: InheritOption::Some(YARN_VERSION.clone()),
362+
yarn: InheritOption::Some(YARN_VERSION),
346363
};
347364

348365
let base = Platform {
@@ -355,14 +372,14 @@ mod cli_platform {
355372
let merged = test.merge(base);
356373

357374
let merged_yarn = merged.yarn.unwrap();
358-
assert_eq!(merged_yarn.value, YARN_VERSION.clone());
375+
assert_eq!(merged_yarn.value, YARN_VERSION);
359376
assert_eq!(merged_yarn.source, Source::CommandLine);
360377
}
361378

362379
#[test]
363380
fn inherits_yarn() {
364381
let test = CliPlatform {
365-
node: Some(NODE_VERSION.clone()),
382+
node: Some(NODE_VERSION),
366383
npm: InheritOption::default(),
367384
pnpm: InheritOption::default(),
368385
yarn: InheritOption::Inherit,
@@ -372,20 +389,20 @@ mod cli_platform {
372389
node: Sourced::with_default(Version::from((10, 10, 10))),
373390
npm: None,
374391
pnpm: None,
375-
yarn: Some(Sourced::with_default(YARN_VERSION.clone())),
392+
yarn: Some(Sourced::with_default(YARN_VERSION)),
376393
};
377394

378395
let merged = test.merge(base);
379396

380397
let merged_yarn = merged.yarn.unwrap();
381-
assert_eq!(merged_yarn.value, YARN_VERSION.clone());
398+
assert_eq!(merged_yarn.value, YARN_VERSION);
382399
assert_eq!(merged_yarn.source, Source::Default);
383400
}
384401

385402
#[test]
386403
fn none_does_not_inherit_yarn() {
387404
let test = CliPlatform {
388-
node: Some(NODE_VERSION.clone()),
405+
node: Some(NODE_VERSION),
389406
npm: InheritOption::default(),
390407
pnpm: InheritOption::default(),
391408
yarn: InheritOption::None,
@@ -395,7 +412,7 @@ mod cli_platform {
395412
node: Sourced::with_default(Version::from((10, 10, 10))),
396413
npm: None,
397414
pnpm: None,
398-
yarn: Some(Sourced::with_default(YARN_VERSION.clone())),
415+
yarn: Some(Sourced::with_default(YARN_VERSION)),
399416
};
400417

401418
let merged = test.merge(base);
@@ -425,7 +442,7 @@ mod cli_platform {
425442
#[test]
426443
fn uses_cli_node() {
427444
let cli = CliPlatform {
428-
node: Some(NODE_VERSION.clone()),
445+
node: Some(NODE_VERSION),
429446
npm: InheritOption::default(),
430447
pnpm: InheritOption::default(),
431448
yarn: InheritOption::default(),
@@ -434,30 +451,30 @@ mod cli_platform {
434451
let transformed: Option<Platform> = cli.into();
435452

436453
let node = transformed.unwrap().node;
437-
assert_eq!(node.value, NODE_VERSION.clone());
454+
assert_eq!(node.value, NODE_VERSION);
438455
assert_eq!(node.source, Source::CommandLine);
439456
}
440457

441458
#[test]
442459
fn uses_cli_npm() {
443460
let cli = CliPlatform {
444-
node: Some(NODE_VERSION.clone()),
445-
npm: InheritOption::Some(NPM_VERSION.clone()),
461+
node: Some(NODE_VERSION),
462+
npm: InheritOption::Some(NPM_VERSION),
446463
pnpm: InheritOption::default(),
447464
yarn: InheritOption::default(),
448465
};
449466

450467
let transformed: Option<Platform> = cli.into();
451468

452469
let npm = transformed.unwrap().npm.unwrap();
453-
assert_eq!(npm.value, NPM_VERSION.clone());
470+
assert_eq!(npm.value, NPM_VERSION);
454471
assert_eq!(npm.source, Source::CommandLine);
455472
}
456473

457474
#[test]
458475
fn no_npm() {
459476
let cli = CliPlatform {
460-
node: Some(NODE_VERSION.clone()),
477+
node: Some(NODE_VERSION),
461478
npm: InheritOption::None,
462479
pnpm: InheritOption::default(),
463480
yarn: InheritOption::default(),
@@ -471,7 +488,7 @@ mod cli_platform {
471488
#[test]
472489
fn inherit_npm_becomes_none() {
473490
let cli = CliPlatform {
474-
node: Some(NODE_VERSION.clone()),
491+
node: Some(NODE_VERSION),
475492
npm: InheritOption::Inherit,
476493
pnpm: InheritOption::default(),
477494
yarn: InheritOption::default(),
@@ -485,23 +502,23 @@ mod cli_platform {
485502
#[test]
486503
fn uses_cli_yarn() {
487504
let cli = CliPlatform {
488-
node: Some(NODE_VERSION.clone()),
505+
node: Some(NODE_VERSION),
489506
npm: InheritOption::default(),
490507
pnpm: InheritOption::default(),
491-
yarn: InheritOption::Some(YARN_VERSION.clone()),
508+
yarn: InheritOption::Some(YARN_VERSION),
492509
};
493510

494511
let transformed: Option<Platform> = cli.into();
495512

496513
let yarn = transformed.unwrap().yarn.unwrap();
497-
assert_eq!(yarn.value, YARN_VERSION.clone());
514+
assert_eq!(yarn.value, YARN_VERSION);
498515
assert_eq!(yarn.source, Source::CommandLine);
499516
}
500517

501518
#[test]
502519
fn no_yarn() {
503520
let cli = CliPlatform {
504-
node: Some(NODE_VERSION.clone()),
521+
node: Some(NODE_VERSION),
505522
npm: InheritOption::default(),
506523
pnpm: InheritOption::default(),
507524
yarn: InheritOption::None,
@@ -515,7 +532,7 @@ mod cli_platform {
515532
#[test]
516533
fn inherit_yarn_becomes_none() {
517534
let cli = CliPlatform {
518-
node: Some(NODE_VERSION.clone()),
535+
node: Some(NODE_VERSION),
519536
npm: InheritOption::default(),
520537
pnpm: InheritOption::default(),
521538
yarn: InheritOption::Inherit,

0 commit comments

Comments
 (0)