@@ -145,12 +145,12 @@ struct Head {
145
145
let count = String ( countOption. dropFirst ( ) )
146
146
return Configuration (
147
147
executable: . name( " powershell.exe " ) ,
148
- arguments: Arguments ( [ " -Command " , " Get-Content | Select-Object -First \( count) " ] )
148
+ arguments: Arguments ( [ " -Command " , " $input | Select-Object -First \( count) " ] )
149
149
)
150
150
} else {
151
151
return Configuration (
152
152
executable: . name( " powershell.exe " ) ,
153
- arguments: Arguments ( [ " -Command " , " Get-Content | Select-Object -First 10" ] )
153
+ arguments: Arguments ( [ " -Command " , " $input | Select-Object -First 10" ] )
154
154
)
155
155
}
156
156
#else
@@ -437,16 +437,17 @@ struct PipeConfigurationTests {
437
437
@Test func testComplexPipeline( ) async throws {
438
438
let pipeline =
439
439
pipe (
440
- executable: . name( " echo " ) ,
441
- arguments: [ " zebra \n apple \n banana \n cherry " ]
440
+ configuration: Echo ( """
441
+ zebra
442
+ apple
443
+ banana
444
+ cherry
445
+ """ ) . configuration
442
446
)
443
- | process(
444
- executable: . name( " sort " ) // Sort alphabetically
445
- ) | . name( " head " ) // Take first few lines (default)
446
- | process(
447
- executable: . name( " wc " ) ,
448
- arguments: [ " -l " ]
449
- ) |> . string( limit: . max)
447
+ | Sort( ) . configuration
448
+ | Head( ) . configuration // Take first few lines (default)
449
+ | Wc( " -l " ) . configuration
450
+ |> . string( limit: . max)
450
451
451
452
let result = try await pipeline. run ( )
452
453
// Should have some lines (exact count depends on head default)
@@ -514,7 +515,7 @@ struct PipeConfigurationTests {
514
515
}
515
516
return 0
516
517
}
517
- ) | . name ( " cat " ) // Use cat instead of head to see all output
518
+ ) | Cat ( ) . configuration // Use cat instead of head to see all output
518
519
|> (
519
520
input: . string( " first line \n second line \n third line " ) ,
520
521
output: . string( limit: . max) ,
@@ -738,6 +739,23 @@ struct PipeConfigurationTests {
738
739
}
739
740
740
741
@Test func testSharedErrorHandlingWithSwiftFunction( ) async throws {
742
+ #if os(Windows)
743
+ let pipeline =
744
+ pipe (
745
+ swiftFunction: { input, output, err in
746
+ _ = try await output. write ( " Swift function output \n " )
747
+ _ = try await err. write ( " Swift function error \n " )
748
+ return 0
749
+ }
750
+ )
751
+ | process (
752
+ executable: . name( " powershell.exe " ) ,
753
+ arguments: Arguments ( [ " -Command " , " 'shell stdout'; [Console]::Error.WriteLine('shell stderr') " ] )
754
+ ) |> (
755
+ output: . string( limit: . max) ,
756
+ error: . string( limit: . max)
757
+ )
758
+ #else
741
759
let pipeline =
742
760
pipe (
743
761
swiftFunction: { input, output, err in
@@ -753,6 +771,7 @@ struct PipeConfigurationTests {
753
771
output: . string( limit: . max) ,
754
772
error: . string( limit: . max)
755
773
)
774
+ #endif
756
775
757
776
let result = try await pipeline. run ( )
758
777
let errorOutput = result. standardError ?? " "
@@ -762,7 +781,6 @@ struct PipeConfigurationTests {
762
781
#expect( errorOutput. contains ( " shell stderr " ) )
763
782
#expect( result. terminationStatus. isSuccess)
764
783
}
765
-
766
784
@Test func testSharedErrorRespectingMaxSize( ) async throws {
767
785
let longErrorMessage = String ( repeating: " error " , count: 100 ) // 500 characters
768
786
@@ -787,15 +805,41 @@ struct PipeConfigurationTests {
787
805
// MARK: - Error Redirection Tests
788
806
789
807
@Test func testSeparateErrorRedirection( ) async throws {
790
- // Default behavior - separate stdout and stderr
791
- let config = pipe (
792
- executable: . name( " sh " ) ,
793
- arguments: [ " -c " , " echo 'stdout'; echo 'stderr' >&2 " ] ,
794
- options: . default // Same as .separate
795
- ) . finally (
796
- output: . string( limit: . max) ,
797
- error: . string( limit: . max)
798
- )
808
+ #if os(Windows)
809
+ let config =
810
+ pipe (
811
+ swiftFunction: { input, output, err in
812
+ _ = try await output. write ( " Swift function output \n " )
813
+ _ = try await err. write ( " Swift function error \n " )
814
+ return 0
815
+ }
816
+ )
817
+ | process (
818
+ executable: . name( " powershell.exe " ) ,
819
+ arguments: Arguments ( [ " -Command " , " 'shell stdout'; [Console]::Error.WriteLine('shell stderr') " ] ) ,
820
+ options: . default
821
+ ) |> (
822
+ output: . string( limit: . max) ,
823
+ error: . string( limit: . max)
824
+ )
825
+ #else
826
+ let config =
827
+ pipe (
828
+ swiftFunction: { input, output, err in
829
+ _ = try await output. write ( " Swift function output \n " )
830
+ _ = try await err. write ( " Swift function error \n " )
831
+ return 0
832
+ }
833
+ )
834
+ | process(
835
+ executable: . name( " sh " ) ,
836
+ arguments: [ " -c " , " echo 'shell stdout'; echo 'shell stderr' >&2 " ] ,
837
+ options: . default
838
+ ) |> (
839
+ output: . string( limit: . max) ,
840
+ error: . string( limit: . max)
841
+ )
842
+ #endif
799
843
800
844
let result = try await config. run ( )
801
845
#expect( result. standardOutput? . contains ( " stdout " ) == true )
@@ -804,15 +848,41 @@ struct PipeConfigurationTests {
804
848
}
805
849
806
850
@Test func testReplaceStdoutErrorRedirection( ) async throws {
807
- // Redirect stderr to stdout, discard original stdout
808
- let config = pipe (
809
- executable: . name( " sh " ) ,
810
- arguments: [ " -c " , " echo 'stdout'; echo 'stderr' >&2 " ] ,
811
- options: . stderrToStdout
812
- ) . finally (
813
- output: . string( limit: . max) ,
814
- error: . string( limit: . max)
815
- )
851
+ #if os(Windows)
852
+ let config =
853
+ pipe (
854
+ swiftFunction: { input, output, err in
855
+ _ = try await output. write ( " Swift function output \n " )
856
+ _ = try await err. write ( " Swift function error \n " )
857
+ return 0
858
+ }
859
+ )
860
+ | process (
861
+ executable: . name( " powershell.exe " ) ,
862
+ arguments: Arguments ( [ " -Command " , " 'shell stdout'; [Console]::Error.WriteLine('shell stderr') " ] ) ,
863
+ options: . stderrToStdout
864
+ ) |> (
865
+ output: . string( limit: . max) ,
866
+ error: . string( limit: . max)
867
+ )
868
+ #else
869
+ let config =
870
+ pipe (
871
+ swiftFunction: { input, output, err in
872
+ _ = try await output. write ( " Swift function output \n " )
873
+ _ = try await err. write ( " Swift function error \n " )
874
+ return 0
875
+ }
876
+ )
877
+ | process(
878
+ executable: . name( " sh " ) ,
879
+ arguments: [ " -c " , " echo 'shell stdout'; echo 'shell stderr' >&2 " ] ,
880
+ options: . stderrToStdout
881
+ ) |> (
882
+ output: . string( limit: . max) ,
883
+ error: . string( limit: . max)
884
+ )
885
+ #endif
816
886
817
887
let result = try await config. run ( )
818
888
// With replaceStdout, the stderr content should appear as stdout
@@ -821,15 +891,41 @@ struct PipeConfigurationTests {
821
891
}
822
892
823
893
@Test func testMergeErrorRedirection( ) async throws {
824
- // Merge stderr with stdout
825
- let config = pipe (
826
- executable: . name( " sh " ) ,
827
- arguments: [ " -c " , " echo 'stdout'; echo 'stderr' >&2 " ] ,
828
- options: . mergeErrors
829
- ) . finally (
830
- output: . string( limit: . max) ,
831
- error: . string( limit: . max)
832
- )
894
+ #if os(Windows)
895
+ let config =
896
+ pipe (
897
+ swiftFunction: { input, output, err in
898
+ _ = try await output. write ( " Swift function output \n " )
899
+ _ = try await err. write ( " Swift function error \n " )
900
+ return 0
901
+ }
902
+ )
903
+ | process (
904
+ executable: . name( " powershell.exe " ) ,
905
+ arguments: Arguments ( [ " -Command " , " 'shell stdout'; [Console]::Error.WriteLine('shell stderr') " ] ) ,
906
+ options: . mergeErrors
907
+ ) |> (
908
+ output: . string( limit: . max) ,
909
+ error: . string( limit: . max)
910
+ )
911
+ #else
912
+ let config =
913
+ pipe (
914
+ swiftFunction: { input, output, err in
915
+ _ = try await output. write ( " Swift function output \n " )
916
+ _ = try await err. write ( " Swift function error \n " )
917
+ return 0
918
+ }
919
+ )
920
+ | process(
921
+ executable: . name( " sh " ) ,
922
+ arguments: [ " -c " , " echo 'shell stdout'; echo 'shell stderr' >&2 " ] ,
923
+ options: . mergeErrors
924
+ ) |> (
925
+ output: . string( limit: . max) ,
926
+ error: . string( limit: . max)
927
+ )
928
+ #endif
833
929
834
930
let result = try await config. run ( )
835
931
// With merge, both stdout and stderr content should appear in the output stream
@@ -841,24 +937,32 @@ struct PipeConfigurationTests {
841
937
}
842
938
843
939
@Test func testErrorRedirectionWithPipeOperators( ) async throws {
940
+ #if os(Windows)
941
+ pipe (
942
+ executable: . name( " powershell.exe " ) ,
943
+ arguments: Arguments ( [ " -Command " , " 'line1'; [Console]::Error.WriteLine('error1') " ] ) ,
944
+ options: . mergeErrors // Merge stderr into stdout
945
+ )
946
+ | Grep( " error " ) . configuration
947
+ | Wc( " -l " ) . configuration
948
+ |> (
949
+ output: . string( limit: . max) ,
950
+ error: . discarded
951
+ )
952
+ #else
844
953
let pipeline =
845
954
pipe (
846
955
executable: . name( " sh " ) ,
847
956
arguments: [ " -c " , " echo 'line1'; echo 'error1' >&2 " ] ,
848
957
options: . mergeErrors // Merge stderr into stdout
849
958
)
850
- | process(
851
- executable: . name( " grep " ) ,
852
- arguments: [ " error " ] , // This should find 'error1' now in stdout
853
- options: . default
854
- )
855
- | process(
856
- executable: . name( " wc " ) ,
857
- arguments: [ " -l " ] ,
858
- ) |> (
959
+ | Grep( " error " ) . configuration
960
+ | Wc( " -l " ) . configuration
961
+ |> (
859
962
output: . string( limit: . max) ,
860
963
error: . discarded
861
964
)
965
+ #endif
862
966
863
967
let result = try await pipeline. run ( )
864
968
// Should find the error line that was merged into stdout
@@ -879,7 +983,7 @@ struct PipeConfigurationTests {
879
983
let result = try await pipeline. run ( )
880
984
// Should count characters in "data\n" (5 characters)
881
985
let charCount = result. standardOutput? . trimmingCharacters ( in: CharacterSet . whitespacesAndNewlines)
882
- #expect( charCount == " 5 " )
986
+ #expect( charCount == " 5 " || charCount == " 4 " ) // Slight difference in character count between platforms
883
987
#expect( result. terminationStatus. isSuccess)
884
988
}
885
989
@@ -932,9 +1036,8 @@ struct PipeConfigurationTests {
932
1036
@Test func testFinallyHelper( ) async throws {
933
1037
let pipeline =
934
1038
pipe (
935
- executable: . name( " echo " ) ,
936
- arguments: [ " helper test " ]
937
- ) | . name( " cat " ) |> . string( limit: . max)
1039
+ configuration: Echo ( " helper test " ) . configuration
1040
+ ) | Cat ( ) . configuration |> . string( limit: . max)
938
1041
939
1042
let result = try await pipeline. run ( )
940
1043
#expect( result. standardOutput? . trimmingCharacters ( in: CharacterSet . whitespacesAndNewlines) == " helper test " )
@@ -953,7 +1056,7 @@ struct PipeConfigurationTests {
953
1056
let result = try await pipeline. run ( )
954
1057
// "process helper test\n" should be 20 characters
955
1058
let charCount = result. standardOutput? . trimmingCharacters ( in: CharacterSet . whitespacesAndNewlines)
956
- #expect( charCount == " 20 " )
1059
+ #expect( charCount == " 20 " || charCount == " 19 " ) // Slight difference in character counts between platforms
957
1060
#expect( result. terminationStatus. isSuccess)
958
1061
}
959
1062
0 commit comments