@@ -243,12 +243,16 @@ pub struct ProjectBuilder {
243
243
}
244
244
245
245
impl ProjectBuilder {
246
- /// Root of the project, ex: `/path/to/cargo/target/cit/t0/foo`
246
+ /// Root of the project
247
+ ///
248
+ /// ex: `$CARGO_TARGET_TMPDIR/cit/t0/foo`
247
249
pub fn root ( & self ) -> PathBuf {
248
250
self . root . root ( )
249
251
}
250
252
251
- /// Project's debug dir, ex: `/path/to/cargo/target/cit/t0/foo/target/debug`
253
+ /// Project's debug dir
254
+ ///
255
+ /// ex: `$CARGO_TARGET_TMPDIR/cit/t0/foo/target/debug`
252
256
pub fn target_debug_dir ( & self ) -> PathBuf {
253
257
self . root . target_debug_dir ( )
254
258
}
@@ -366,54 +370,67 @@ impl Project {
366
370
Self { root : project_root }
367
371
}
368
372
369
- /// Root of the project, ex: `/path/to/cargo/target/cit/t0/foo`
373
+ /// Root of the project
374
+ ///
375
+ /// ex: `$CARGO_TARGET_TMPDIR/cit/t0/foo`
370
376
pub fn root ( & self ) -> PathBuf {
371
377
self . root . clone ( )
372
378
}
373
379
374
- /// Project's target dir, ex: `/path/to/cargo/target/cit/t0/foo/target`
380
+ /// Project's target dir
381
+ ///
382
+ /// ex: `$CARGO_TARGET_TMPDIR/cit/t0/foo/target`
375
383
pub fn build_dir ( & self ) -> PathBuf {
376
384
self . root ( ) . join ( "target" )
377
385
}
378
386
379
- /// Project's debug dir, ex: `/path/to/cargo/target/cit/t0/foo/target/debug`
387
+ /// Project's debug dir
388
+ ///
389
+ /// ex: `$CARGO_TARGET_TMPDIR/cit/t0/foo/target/debug`
380
390
pub fn target_debug_dir ( & self ) -> PathBuf {
381
391
self . build_dir ( ) . join ( "debug" )
382
392
}
383
393
384
- /// File url for root, ex: `file:///path/to/cargo/target/cit/t0/foo`
394
+ /// File url for root
395
+ ///
396
+ /// ex: `file://$CARGO_TARGET_TMPDIR/cit/t0/foo`
385
397
pub fn url ( & self ) -> Url {
386
398
use paths:: CargoPathExt ;
387
399
self . root ( ) . to_url ( )
388
400
}
389
401
390
402
/// Path to an example built as a library.
403
+ ///
391
404
/// `kind` should be one of: "lib", "rlib", "staticlib", "dylib", "proc-macro"
392
- /// ex: `/path/to/cargo/target/cit/t0/foo/target/debug/examples/libex.rlib`
405
+ ///
406
+ /// ex: `$CARGO_TARGET_TMPDIR/cit/t0/foo/target/debug/examples/libex.rlib`
393
407
pub fn example_lib ( & self , name : & str , kind : & str ) -> PathBuf {
394
408
self . target_debug_dir ( )
395
409
. join ( "examples" )
396
410
. join ( paths:: get_lib_filename ( name, kind) )
397
411
}
398
412
399
413
/// Path to a debug binary.
400
- /// ex: `/path/to/cargo/target/cit/t0/foo/target/debug/foo`
414
+ ///
415
+ /// ex: `$CARGO_TARGET_TMPDIR/cit/t0/foo/target/debug/foo`
401
416
pub fn bin ( & self , b : & str ) -> PathBuf {
402
417
self . build_dir ( )
403
418
. join ( "debug" )
404
419
. join ( & format ! ( "{}{}" , b, env:: consts:: EXE_SUFFIX ) )
405
420
}
406
421
407
422
/// Path to a release binary.
408
- /// ex: `/path/to/cargo/target/cit/t0/foo/target/release/foo`
423
+ ///
424
+ /// ex: `$CARGO_TARGET_TMPDIR/cit/t0/foo/target/release/foo`
409
425
pub fn release_bin ( & self , b : & str ) -> PathBuf {
410
426
self . build_dir ( )
411
427
. join ( "release" )
412
428
. join ( & format ! ( "{}{}" , b, env:: consts:: EXE_SUFFIX ) )
413
429
}
414
430
415
431
/// Path to a debug binary for a specific target triple.
416
- /// ex: `/path/to/cargo/target/cit/t0/foo/target/i686-apple-darwin/debug/foo`
432
+ ///
433
+ /// ex: `$CARGO_TARGET_TMPDIR/cit/t0/foo/target/i686-apple-darwin/debug/foo`
417
434
pub fn target_bin ( & self , target : & str , b : & str ) -> PathBuf {
418
435
self . build_dir ( ) . join ( target) . join ( "debug" ) . join ( & format ! (
419
436
"{}{}" ,
@@ -422,35 +439,54 @@ impl Project {
422
439
) )
423
440
}
424
441
425
- /// Returns an iterator of paths matching the glob pattern, which is
426
- /// relative to the project root.
442
+ /// Returns an iterator of paths within [`Project::root`] matching the glob pattern
427
443
pub fn glob < P : AsRef < Path > > ( & self , pattern : P ) -> glob:: Paths {
428
444
let pattern = self . root ( ) . join ( pattern) ;
429
445
glob:: glob ( pattern. to_str ( ) . expect ( "failed to convert pattern to str" ) )
430
446
. expect ( "failed to glob" )
431
447
}
432
448
433
- /// Changes the contents of an existing file.
449
+ /// Overwrite a file with new content
450
+ ///
451
+ // # Example:
452
+ ///
453
+ /// ```no_run
454
+ /// # let p = cargo_test_support::project().build();
455
+ /// p.change_file("src/lib.rs", "fn new_fn() {}");
456
+ /// ```
434
457
pub fn change_file ( & self , path : & str , body : & str ) {
435
458
FileBuilder :: new ( self . root ( ) . join ( path) , body, false ) . mk ( )
436
459
}
437
460
438
461
/// Creates a `ProcessBuilder` to run a program in the project
439
462
/// and wrap it in an Execs to assert on the execution.
440
- /// Example:
441
- /// p.process(&p.bin("foo"))
442
- /// .with_stdout("bar\n")
443
- /// .run();
463
+ ///
464
+ /// # Example:
465
+ ///
466
+ /// ```no_run
467
+ /// # let p = cargo_test_support::project().build();
468
+ /// p.process(&p.bin("foo"))
469
+ /// .with_stdout("bar\n")
470
+ /// .run();
471
+ /// ```
444
472
pub fn process < T : AsRef < OsStr > > ( & self , program : T ) -> Execs {
445
473
let mut p = process ( program) ;
446
474
p. cwd ( self . root ( ) ) ;
447
475
execs ( ) . with_process_builder ( p)
448
476
}
449
477
450
478
/// Creates a `ProcessBuilder` to run cargo.
479
+ ///
451
480
/// Arguments can be separated by spaces.
452
- /// Example:
453
- /// p.cargo("build --bin foo").run();
481
+ ///
482
+ /// For `cargo run`, see [`Project::rename_run`].
483
+ ///
484
+ /// # Example:
485
+ ///
486
+ /// ```no_run
487
+ /// # let p = cargo_test_support::project().build();
488
+ /// p.cargo("build --bin foo").run();
489
+ /// ```
454
490
pub fn cargo ( & self , cmd : & str ) -> Execs {
455
491
let cargo = cargo_exe ( ) ;
456
492
let mut execs = self . process ( & cargo) ;
0 commit comments