@@ -3569,13 +3569,41 @@ impl Group {
3569
3569
///
3570
3570
/// # Examples
3571
3571
///
3572
+ // Disable this test on all OS except BSD as wheel group may not exist.
3573
+ #[ cfg_attr( not( bsd) , doc = " ```no_run" ) ]
3574
+ #[ cfg_attr( bsd, doc = " ```" ) ]
3575
+ /// use nix::unistd::Group;
3576
+ /// // Returns an Result<Option<Group>>, thus the double unwrap.
3577
+ /// let group = Group::from_name("wheel").unwrap().unwrap();
3578
+ /// assert!(group.name == "wheel");
3579
+ /// let group_id = group.gid;
3580
+ /// let group = Group::from_gid(group_id).unwrap().unwrap();
3581
+ /// assert_eq!(group.gid, group_id);
3582
+ /// assert_eq!(group.name, "wheel");
3583
+ /// ```
3584
+ // Disable this test on all OS except Apple as everyone group may not exist.
3585
+ #[ cfg_attr( not( apple_targets) , doc = " ```no_run" ) ]
3586
+ #[ cfg_attr( apple_targets, doc = " ```" ) ]
3587
+ /// use nix::unistd::Group;
3588
+ /// // Returns an Result<Option<Group>>, thus the double unwrap.
3589
+ /// let group = Group::from_name("everyone").unwrap().unwrap();
3590
+ /// assert!(group.name == "everyone");
3591
+ /// let group_id = group.gid;
3592
+ /// let group = Group::from_gid(group_id).unwrap().unwrap();
3593
+ /// assert_eq!(group.gid, group_id);
3594
+ /// assert_eq!(group.name, "everyone");
3595
+ /// ```
3572
3596
// Disable this test on all OS except Linux as root group may not exist.
3573
3597
#[ cfg_attr( not( target_os = "linux" ) , doc = " ```no_run" ) ]
3574
3598
#[ cfg_attr( target_os = "linux" , doc = " ```" ) ]
3575
3599
/// use nix::unistd::Group;
3576
3600
/// // Returns an Result<Option<Group>>, thus the double unwrap.
3577
- /// let res = Group::from_name("root").unwrap().unwrap();
3578
- /// assert!(res.name == "root");
3601
+ /// let group = Group::from_name("root").unwrap().unwrap();
3602
+ /// assert!(group.name == "root");
3603
+ /// let group_id = group.gid;
3604
+ /// let group = Group::from_gid(group_id).unwrap().unwrap();
3605
+ /// assert_eq!(group.gid, group_id);
3606
+ /// assert_eq!(group.name, "root");
3579
3607
/// ```
3580
3608
pub fn from_name( name: & str ) -> Result <Option <Self >> {
3581
3609
let name = match CString :: new( name) {
0 commit comments