@@ -13,11 +13,23 @@ use uutests::util::TestScenario;
1313use uutests:: util:: log_info;
1414use uutests:: util_name;
1515
16- const ALGOS : [ & str ; 11 ] = [
17- "sysv" , "bsd" , "crc" , "md5" , "sha1" , "sha224" , "sha256" , "sha384" , "sha512" , "blake2b" , "sm3" ,
18- ] ;
1916const SHA_LENGTHS : [ u32 ; 4 ] = [ 224 , 256 , 384 , 512 ] ;
2017
18+ #[ template]
19+ #[ rstest]
20+ #[ case:: sysv( "sysv" ) ]
21+ #[ case:: bsd( "bsd" ) ]
22+ #[ case:: crc( "crc" ) ]
23+ #[ case:: md5( "md5" ) ]
24+ #[ case:: sha1( "sha1" ) ]
25+ #[ case:: sha224( "sha224" ) ]
26+ #[ case:: sha256( "sha256" ) ]
27+ #[ case:: sha384( "sha384" ) ]
28+ #[ case:: sha512( "sha512" ) ]
29+ #[ case:: blake2b( "blake2b" ) ]
30+ #[ case:: sm3( "sm3" ) ]
31+ fn test_all_algos ( #[ case] algo : & str ) { }
32+
2133#[ test]
2234fn test_invalid_arg ( ) {
2335 new_ucmd ! ( ) . arg ( "--definitely-invalid" ) . fails_with_code ( 1 ) ;
@@ -170,43 +182,37 @@ fn test_tag_after_untagged() {
170182 . stdout_is_fixture ( "md5_single_file.expected" ) ;
171183}
172184
173- #[ test]
174- fn test_algorithm_single_file ( ) {
175- for algo in ALGOS {
176- for option in [ "-a" , "--algorithm" ] {
177- new_ucmd ! ( )
178- . arg ( format ! ( "{option}={algo}" ) )
179- . arg ( "lorem_ipsum.txt" )
180- . succeeds ( )
181- . stdout_is_fixture ( format ! ( "{algo}_single_file.expected" ) ) ;
182- }
185+ #[ apply( test_all_algos) ]
186+ fn test_algorithm_single_file ( #[ case] algo : & str ) {
187+ for option in [ "-a" , "--algorithm" ] {
188+ new_ucmd ! ( )
189+ . arg ( format ! ( "{option}={algo}" ) )
190+ . arg ( "lorem_ipsum.txt" )
191+ . succeeds ( )
192+ . stdout_is_fixture ( format ! ( "{algo}_single_file.expected" ) ) ;
183193 }
184194}
185195
186- #[ test]
187- fn test_algorithm_multiple_files ( ) {
188- for algo in ALGOS {
189- for option in [ "-a" , "--algorithm" ] {
190- new_ucmd ! ( )
191- . arg ( format ! ( "{option}={algo}" ) )
192- . arg ( "lorem_ipsum.txt" )
193- . arg ( "alice_in_wonderland.txt" )
194- . succeeds ( )
195- . stdout_is_fixture ( format ! ( "{algo}_multiple_files.expected" ) ) ;
196- }
196+ #[ apply( test_all_algos) ]
197+ fn test_algorithm_multiple_files ( #[ case] algo : & str ) {
198+ for option in [ "-a" , "--algorithm" ] {
199+ new_ucmd ! ( )
200+ . arg ( format ! ( "{option}={algo}" ) )
201+ . arg ( "lorem_ipsum.txt" )
202+ . arg ( "alice_in_wonderland.txt" )
203+ . succeeds ( )
204+ . stdout_is_fixture ( format ! ( "{algo}_multiple_files.expected" ) ) ;
197205 }
198206}
199207
200- #[ test]
201- fn test_algorithm_stdin ( ) {
202- for algo in ALGOS {
203- for option in [ "-a" , "--algorithm" ] {
204- new_ucmd ! ( )
205- . arg ( format ! ( "{option}={algo}" ) )
206- . pipe_in_fixture ( "lorem_ipsum.txt" )
207- . succeeds ( )
208- . stdout_is_fixture ( format ! ( "{algo}_stdin.expected" ) ) ;
209- }
208+ #[ apply( test_all_algos) ]
209+ fn test_algorithm_stdin ( #[ case] algo : & str ) {
210+ for option in [ "-a" , "--algorithm" ] {
211+ new_ucmd ! ( )
212+ . arg ( format ! ( "{option}={algo}" ) )
213+ . pipe_in_fixture ( "lorem_ipsum.txt" )
214+ . succeeds ( )
215+ . stdout_is_fixture ( format ! ( "{algo}_stdin.expected" ) ) ;
210216 }
211217}
212218
@@ -238,16 +244,14 @@ fn test_untagged_stdin() {
238244 . stdout_is_fixture ( "untagged/crc_stdin.expected" ) ;
239245}
240246
241- #[ test]
242- fn test_untagged_algorithm_single_file ( ) {
243- for algo in ALGOS {
244- new_ucmd ! ( )
245- . arg ( "--untagged" )
246- . arg ( format ! ( "--algorithm={algo}" ) )
247- . arg ( "lorem_ipsum.txt" )
248- . succeeds ( )
249- . stdout_is_fixture ( format ! ( "untagged/{algo}_single_file.expected" ) ) ;
250- }
247+ #[ apply( test_all_algos) ]
248+ fn test_untagged_algorithm_single_file ( #[ case] algo : & str ) {
249+ new_ucmd ! ( )
250+ . arg ( "--untagged" )
251+ . arg ( format ! ( "--algorithm={algo}" ) )
252+ . arg ( "lorem_ipsum.txt" )
253+ . succeeds ( )
254+ . stdout_is_fixture ( format ! ( "untagged/{algo}_single_file.expected" ) ) ;
251255}
252256
253257#[ test]
@@ -272,29 +276,25 @@ fn test_untagged_algorithm_after_tag() {
272276 . stdout_is_fixture ( "untagged/md5_single_file.expected" ) ;
273277}
274278
275- #[ test]
276- fn test_untagged_algorithm_multiple_files ( ) {
277- for algo in ALGOS {
278- new_ucmd ! ( )
279- . arg ( "--untagged" )
280- . arg ( format ! ( "--algorithm={algo}" ) )
281- . arg ( "lorem_ipsum.txt" )
282- . arg ( "alice_in_wonderland.txt" )
283- . succeeds ( )
284- . stdout_is_fixture ( format ! ( "untagged/{algo}_multiple_files.expected" ) ) ;
285- }
279+ #[ apply( test_all_algos) ]
280+ fn test_untagged_algorithm_multiple_files ( #[ case] algo : & str ) {
281+ new_ucmd ! ( )
282+ . arg ( "--untagged" )
283+ . arg ( format ! ( "--algorithm={algo}" ) )
284+ . arg ( "lorem_ipsum.txt" )
285+ . arg ( "alice_in_wonderland.txt" )
286+ . succeeds ( )
287+ . stdout_is_fixture ( format ! ( "untagged/{algo}_multiple_files.expected" ) ) ;
286288}
287289
288- #[ test]
289- fn test_untagged_algorithm_stdin ( ) {
290- for algo in ALGOS {
291- new_ucmd ! ( )
292- . arg ( "--untagged" )
293- . arg ( format ! ( "--algorithm={algo}" ) )
294- . pipe_in_fixture ( "lorem_ipsum.txt" )
295- . succeeds ( )
296- . stdout_is_fixture ( format ! ( "untagged/{algo}_stdin.expected" ) ) ;
297- }
290+ #[ apply( test_all_algos) ]
291+ fn test_untagged_algorithm_stdin ( #[ case] algo : & str ) {
292+ new_ucmd ! ( )
293+ . arg ( "--untagged" )
294+ . arg ( format ! ( "--algorithm={algo}" ) )
295+ . pipe_in_fixture ( "lorem_ipsum.txt" )
296+ . succeeds ( )
297+ . stdout_is_fixture ( format ! ( "untagged/{algo}_stdin.expected" ) ) ;
298298}
299299
300300#[ test]
@@ -846,18 +846,17 @@ fn test_blake2b_length_invalid() {
846846 }
847847}
848848
849- #[ test]
850- fn test_raw_single_file ( ) {
851- for algo in ALGOS {
852- new_ucmd ! ( )
853- . arg ( "--raw" )
854- . arg ( "lorem_ipsum.txt" )
855- . arg ( format ! ( "--algorithm={algo}" ) )
856- . succeeds ( )
857- . no_stderr ( )
858- . stdout_is_fixture_bytes ( format ! ( "raw/{algo}_single_file.expected" ) ) ;
859- }
849+ #[ apply( test_all_algos) ]
850+ fn test_raw_single_file ( #[ case] algo : & str ) {
851+ new_ucmd ! ( )
852+ . arg ( "--raw" )
853+ . arg ( "lorem_ipsum.txt" )
854+ . arg ( format ! ( "--algorithm={algo}" ) )
855+ . succeeds ( )
856+ . no_stderr ( )
857+ . stdout_is_fixture_bytes ( format ! ( "raw/{algo}_single_file.expected" ) ) ;
860858}
859+
861860#[ test]
862861fn test_raw_multiple_files ( ) {
863862 new_ucmd ! ( )
@@ -882,18 +881,17 @@ fn test_base64_raw_conflicts() {
882881 . stderr_contains ( "--raw" ) ;
883882}
884883
885- #[ test]
886- fn test_base64_single_file ( ) {
887- for algo in ALGOS {
888- new_ucmd ! ( )
889- . arg ( "--base64" )
890- . arg ( "lorem_ipsum.txt" )
891- . arg ( format ! ( "--algorithm={algo}" ) )
892- . succeeds ( )
893- . no_stderr ( )
894- . stdout_is_fixture_bytes ( format ! ( "base64/{algo}_single_file.expected" ) ) ;
895- }
884+ #[ apply( test_all_algos) ]
885+ fn test_base64_single_file ( #[ case] algo : & str ) {
886+ new_ucmd ! ( )
887+ . arg ( "--base64" )
888+ . arg ( "lorem_ipsum.txt" )
889+ . arg ( format ! ( "--algorithm={algo}" ) )
890+ . succeeds ( )
891+ . no_stderr ( )
892+ . stdout_is_fixture_bytes ( format ! ( "base64/{algo}_single_file.expected" ) ) ;
896893}
894+
897895#[ test]
898896fn test_base64_multiple_files ( ) {
899897 new_ucmd ! ( )
@@ -919,24 +917,22 @@ fn test_fail_on_folder() {
919917 . stderr_contains ( format ! ( "cksum: {folder_name}: Is a directory" ) ) ;
920918}
921919
922- #[ test ]
923- fn test_all_algorithms_fail_on_folder ( ) {
920+ #[ apply ( test_all_algos ) ]
921+ fn test_all_algorithms_fail_on_folder ( # [ case ] algo : & str ) {
924922 let scene = TestScenario :: new ( util_name ! ( ) ) ;
925923
926924 let at = & scene. fixtures ;
927925
928926 let folder_name = "a_folder" ;
929927 at. mkdir ( folder_name) ;
930928
931- for algo in ALGOS {
932- scene
933- . ucmd ( )
934- . arg ( format ! ( "--algorithm={algo}" ) )
935- . arg ( folder_name)
936- . fails ( )
937- . no_stdout ( )
938- . stderr_contains ( format ! ( "cksum: {folder_name}: Is a directory" ) ) ;
939- }
929+ scene
930+ . ucmd ( )
931+ . arg ( format ! ( "--algorithm={algo}" ) )
932+ . arg ( folder_name)
933+ . fails ( )
934+ . no_stdout ( )
935+ . stderr_contains ( format ! ( "cksum: {folder_name}: Is a directory" ) ) ;
940936}
941937
942938#[ cfg( unix) ]
0 commit comments