File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 1+ use std:: collections:: BTreeSet ;
2+
13#[ test]
24fn custom_error ( ) {
35 let target = "custom_error" ;
@@ -63,3 +65,40 @@ fn assert_example(target: &str, expected: snapbox::Data) {
6365 . success ( )
6466 . stdout_eq ( expected. raw ( ) ) ;
6567}
68+
69+ #[ test]
70+ fn ensure_all_examples_have_tests ( ) {
71+ let path = snapbox:: utils:: current_rs!( ) ;
72+ let actual = std:: fs:: read_to_string ( & path) . unwrap ( ) ;
73+ let actual = actual
74+ . lines ( )
75+ . filter_map ( |l| {
76+ if l. starts_with ( "fn " )
77+ && !l. starts_with ( "fn all_examples_have_tests" )
78+ && !l. starts_with ( "fn assert_example" )
79+ {
80+ Some ( l[ 3 ..l. len ( ) - 4 ] . to_string ( ) )
81+ } else {
82+ None
83+ }
84+ } )
85+ . collect :: < BTreeSet < _ > > ( ) ;
86+
87+ let expected = std:: fs:: read_dir ( "examples" )
88+ . unwrap ( )
89+ . map ( |res| res. map ( |e| e. path ( ) . file_stem ( ) . unwrap ( ) . display ( ) . to_string ( ) ) )
90+ . collect :: < Result < BTreeSet < _ > , std:: io:: Error > > ( )
91+ . unwrap ( ) ;
92+
93+ let mut diff = expected. difference ( & actual) . collect :: < Vec < _ > > ( ) ;
94+ diff. sort ( ) ;
95+
96+ let mut need_added = String :: new ( ) ;
97+ for name in & diff {
98+ need_added. push_str ( & format ! ( "{name}\n " ) ) ;
99+ }
100+ assert ! (
101+ diff. is_empty( ) ,
102+ "\n `Please add a test for the following examples to `tests/examples.rs`:\n {need_added}" ,
103+ ) ;
104+ }
You can’t perform that action at this time.
0 commit comments