Skip to content

Commit cffec40

Browse files
committed
uutests: add some more examples
1 parent 3ec48d4 commit cffec40

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

tests/uutests/src/lib/util.rs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,13 @@ impl CmdResult {
417417
self.exit_status().code().unwrap()
418418
}
419419

420+
/// Verify the exit code of the program
421+
///
422+
/// # Examples
423+
///
424+
/// ```rust,ignore
425+
/// new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
426+
/// ```
420427
#[track_caller]
421428
pub fn code_is(&self, expected_code: i32) -> &Self {
422429
let fails = self.code() != expected_code;
@@ -475,6 +482,12 @@ impl CmdResult {
475482
/// but you might find yourself using this function if
476483
/// 1. you can not know exactly what stdout will be or
477484
/// 2. you know that stdout will also be empty
485+
///
486+
/// # Examples
487+
///
488+
/// ```rust,ignore
489+
/// scene.ucmd().fails().no_stderr();
490+
/// ```
478491
#[track_caller]
479492
pub fn no_stderr(&self) -> &Self {
480493
assert!(
@@ -491,6 +504,13 @@ impl CmdResult {
491504
/// but you might find yourself using this function if
492505
/// 1. you can not know exactly what stderr will be or
493506
/// 2. you know that stderr will also be empty
507+
/// new_ucmd!()
508+
///
509+
/// # Examples
510+
///
511+
/// ```rust,ignore
512+
/// scene.ucmd().fails().no_stdout();
513+
/// ```
494514
#[track_caller]
495515
pub fn no_stdout(&self) -> &Self {
496516
assert!(
@@ -711,6 +731,16 @@ impl CmdResult {
711731
))
712732
}
713733

734+
/// Verify if stdout contains a specific string
735+
///
736+
/// # Examples
737+
///
738+
/// ```rust,ignore
739+
/// new_ucmd!()
740+
/// .arg("--help")
741+
/// .succeeds()
742+
/// .stdout_contains("Options:");
743+
/// ```
714744
#[track_caller]
715745
pub fn stdout_contains<T: AsRef<str>>(&self, cmp: T) -> &Self {
716746
assert!(
@@ -722,6 +752,16 @@ impl CmdResult {
722752
self
723753
}
724754

755+
/// Verify if stdout contains a specific line
756+
///
757+
/// # Examples
758+
///
759+
/// ```rust,ignore
760+
/// new_ucmd!()
761+
/// .arg("--help")
762+
/// .succeeds()
763+
/// .stdout_contains_line("Options:");
764+
/// ```
725765
#[track_caller]
726766
pub fn stdout_contains_line<T: AsRef<str>>(&self, cmp: T) -> &Self {
727767
assert!(
@@ -733,6 +773,17 @@ impl CmdResult {
733773
self
734774
}
735775

776+
/// Verify if stderr contains a specific string
777+
///
778+
/// # Examples
779+
///
780+
/// ```rust,ignore
781+
/// new_ucmd!()
782+
/// .arg("-l")
783+
/// .arg("IaMnOtAsIgNaL")
784+
/// .fails()
785+
/// .stderr_contains("IaMnOtAsIgNaL");
786+
/// ```
736787
#[track_caller]
737788
pub fn stderr_contains<T: AsRef<str>>(&self, cmp: T) -> &Self {
738789
assert!(
@@ -744,6 +795,17 @@ impl CmdResult {
744795
self
745796
}
746797

798+
/// Verify if stdout does not contain a specific string
799+
///
800+
/// # Examples
801+
///
802+
/// ```rust,ignore
803+
/// new_ucmd!()
804+
/// .arg("-l")
805+
/// .arg("IaMnOtAsIgNaL")
806+
/// .fails()
807+
/// .stdout_does_not_contain("Valid-signal");
808+
/// ```
747809
#[track_caller]
748810
pub fn stdout_does_not_contain<T: AsRef<str>>(&self, cmp: T) -> &Self {
749811
assert!(
@@ -755,6 +817,17 @@ impl CmdResult {
755817
self
756818
}
757819

820+
/// Verify if st stderr does not contain a specific string
821+
///
822+
/// # Examples
823+
///
824+
/// ```rust,ignore
825+
/// new_ucmd!()
826+
/// .arg("-l")
827+
/// .arg("IaMnOtAsIgNaL")
828+
/// .fails()
829+
/// .stderr_does_not_contain("Valid-signal");
830+
/// ```
758831
#[track_caller]
759832
pub fn stderr_does_not_contain<T: AsRef<str>>(&self, cmp: T) -> &Self {
760833
assert!(!self.stderr_str().contains(cmp.as_ref()));

0 commit comments

Comments
 (0)