33
44/// Is this command enabled for the current target?
55pub const enabled : bool = switch (shared .target_os ) {
6- .linux = > true ,
7- .macos = > true ,
6+ .linux , .macos = > true ,
87 .windows = > false ,
98};
109
@@ -46,54 +45,53 @@ const impl = struct {
4645 const z : tracy.Zone = .begin (.{ .src = @src (), .name = command .name });
4746 defer z .end ();
4847
49- _ = system ;
50-
5148 const options = try parseArguments (allocator , io , args , exe_path );
5249 log .debug ("{}" , .{options });
5350
54- return performUname (allocator , io , options );
51+ return performUname (allocator , io , system , options );
5552 }
5653
5754 fn performUname (
5855 allocator : std.mem.Allocator ,
5956 io : IO ,
57+ system : System ,
6058 options : UnameOptions ,
6159 ) ! void {
6260 const z : tracy.Zone = .begin (.{ .src = @src (), .name = "perform uname" });
6361 defer z .end ();
6462
6563 _ = allocator ;
6664
67- const utsname = std . posix .uname ();
65+ const uname = system .uname ();
6866
6967 var any_printed = false ;
7068
7169 if (options .kernel_name ) {
72- try io .stdoutWriteAll (& utsname .sysname );
70+ try io .stdoutWriteAll (std . mem . sliceTo ( & uname .sysname , 0 ) );
7371 any_printed = true ;
7472 }
7573
7674 if (options .node_name ) {
7775 if (any_printed ) try io .stdoutWriteByte (' ' );
78- try io .stdoutWriteAll (& utsname .nodename );
76+ try io .stdoutWriteAll (std . mem . sliceTo ( & uname .nodename , 0 ) );
7977 any_printed = true ;
8078 }
8179
8280 if (options .kernel_release ) {
8381 if (any_printed ) try io .stdoutWriteByte (' ' );
84- try io .stdoutWriteAll (& utsname .release );
82+ try io .stdoutWriteAll (std . mem . sliceTo ( & uname .release , 0 ) );
8583 any_printed = true ;
8684 }
8785
8886 if (options .kernel_version ) {
8987 if (any_printed ) try io .stdoutWriteByte (' ' );
90- try io .stdoutWriteAll (& utsname .version );
88+ try io .stdoutWriteAll (std . mem . sliceTo ( & uname .version , 0 ) );
9189 any_printed = true ;
9290 }
9391
9492 if (options .machine ) {
9593 if (any_printed ) try io .stdoutWriteByte (' ' );
96- try io .stdoutWriteAll (& utsname .machine );
94+ try io .stdoutWriteAll (std . mem . sliceTo ( & uname .machine , 0 ) );
9795 any_printed = true ;
9896 }
9997
@@ -117,13 +115,13 @@ const impl = struct {
117115
118116 if (options .os ) {
119117 if (any_printed ) try io .stdoutWriteByte (' ' );
120- try io .stdoutWriteAll (& utsname .sysname );
118+ try io .stdoutWriteAll (std . mem . sliceTo ( & uname .sysname , 0 ) );
121119 any_printed = true ;
122120 }
123121
124122 if (target_has_domainname and options .domainname ) {
125123 if (any_printed ) try io .stdoutWriteByte (' ' );
126- try io .stdoutWriteAll (& utsname .domainname );
124+ try io .stdoutWriteAll (std . mem . sliceTo ( & uname .domainname , 0 ) );
127125 any_printed = true ;
128126 }
129127
@@ -389,8 +387,29 @@ const impl = struct {
389387 try command .testVersion ();
390388 }
391389
392- // TODO: How do we test this without introducing the amount of complexity that https://github.com/leecannon/zsw does?
393- // https://github.com/leecannon/zig-coreutils/issues/7
390+ test "uname" {
391+ var stdout = std .ArrayList (u8 ).init (std .testing .allocator );
392+ defer stdout .deinit ();
393+
394+ try command .testExecute (&.{"-a" }, .{
395+ .stdout = stdout .writer ().any (),
396+ .system_description = .{
397+ .uname = .{
398+ .sysname = "Linux" ,
399+ .nodename = "node" ,
400+ .release = "5.15.0-100-generic" ,
401+ .version = "Some version" ,
402+ .machine = "x86_64" ,
403+ .domainname = null ,
404+ },
405+ },
406+ });
407+
408+ try std .testing .expectEqualStrings (
409+ "Linux node 5.15.0-100-generic Some version x86_64 Linux (none)\n " ,
410+ stdout .items ,
411+ );
412+ }
394413};
395414
396415const Arg = @import ("../Arg.zig" );
0 commit comments