1- //! The tutorial, how-tos, reference, and explanation pages are commands
2- //! a checkout can run.
1+ //! The get-started page, the tutorial, how-tos, reference, and explanation
2+ //! pages are commands a checkout can run.
33//!
44//! Bash blocks must not point at a path this repository does not have.
5- //! The report commands are executed, and the page must quote their output.
5+ //! The report commands and the get-started blocks are executed, and the
6+ //! page must quote their output.
67
78use std:: path:: { Path , PathBuf } ;
89use std:: process:: Command ;
@@ -12,7 +13,10 @@ fn root() -> PathBuf {
1213}
1314
1415fn org_files ( ) -> Vec < PathBuf > {
15- let mut files = vec ! [ root( ) . join( "docs/orgmode/tutorial.org" ) ] ;
16+ let mut files = vec ! [
17+ root( ) . join( "docs/orgmode/get-started.org" ) ,
18+ root( ) . join( "docs/orgmode/tutorial.org" ) ,
19+ ] ;
1620 for dir in [ "howto" , "reference" , "explanation" ] {
1721 let path = root ( ) . join ( "docs/orgmode" ) . join ( dir) ;
1822 let mut names: Vec < _ > = std:: fs:: read_dir ( & path)
@@ -27,11 +31,21 @@ fn org_files() -> Vec<PathBuf> {
2731}
2832
2933fn bash_blocks ( text : & str ) -> Vec < String > {
34+ org_blocks ( text, "#+begin_src bash\n " , "#+end_src" )
35+ }
36+
37+ fn example_blocks ( text : & str ) -> Vec < String > {
38+ org_blocks ( text, "#+begin_example\n " , "#+end_example" )
39+ }
40+
41+ fn org_blocks ( text : & str , open : & str , close : & str ) -> Vec < String > {
3042 let mut blocks = Vec :: new ( ) ;
3143 let mut rest = text;
32- while let Some ( start) = rest. find ( "#+begin_src bash\n " ) {
33- rest = & rest[ start + "#+begin_src bash\n " . len ( ) ..] ;
34- let end = rest. find ( "#+end_src" ) . expect ( "bash block closed" ) ;
44+ while let Some ( start) = rest. find ( open) {
45+ rest = & rest[ start + open. len ( ) ..] ;
46+ let end = rest
47+ . find ( close)
48+ . unwrap_or_else ( || panic ! ( "{close} missing" ) ) ;
3549 blocks. push ( rest[ ..end] . to_string ( ) ) ;
3650 rest = & rest[ end..] ;
3751 }
@@ -94,6 +108,48 @@ fn howto_bash_blocks_name_files_in_this_checkout() {
94108 }
95109}
96110
111+ #[ test]
112+ fn get_started_blocks_print_what_the_page_quotes ( ) {
113+ let page = std:: fs:: read_to_string ( root ( ) . join ( "docs/orgmode/get-started.org" ) ) . unwrap ( ) ;
114+ let commands = bash_blocks ( & page) ;
115+ let quoted = example_blocks ( & page) ;
116+ assert_eq ! ( commands. len( ) , quoted. len( ) , "one quoted output per block" ) ;
117+ // The page writes under /tmp; each run gets its own directory instead.
118+ let tmp = tempfile:: tempdir ( ) . expect ( "temp" ) ;
119+ let scratch = format ! ( "{}/" , tmp. path( ) . display( ) ) ;
120+ let bin = Path :: new ( env ! ( "CARGO_BIN_EXE_eb-stack" ) ) . parent ( ) . unwrap ( ) ;
121+ let path = format ! (
122+ "{}:{}" ,
123+ bin. display( ) ,
124+ std:: env:: var( "PATH" ) . unwrap_or_default( )
125+ ) ;
126+ for ( command, expected) in commands. iter ( ) . zip ( & quoted) {
127+ let output = Command :: new ( "bash" )
128+ . current_dir ( root ( ) )
129+ . env ( "PATH" , & path)
130+ . args ( [ "-euo" , "pipefail" , "-c" ] )
131+ . arg ( command. replace ( "/tmp/" , & scratch) )
132+ . output ( )
133+ . expect ( "spawn bash" ) ;
134+ let stdout = String :: from_utf8_lossy ( & output. stdout ) . replace ( & scratch, "/tmp/" ) ;
135+ assert_eq ! (
136+ & stdout,
137+ expected,
138+ "{command}\n stderr:\n {}" ,
139+ String :: from_utf8_lossy( & output. stderr)
140+ ) ;
141+ let status = if command. contains ( "eb-stack stack admit" ) {
142+ 78
143+ } else {
144+ 0
145+ } ;
146+ assert_eq ! ( output. status. code( ) , Some ( status) , "{command}" ) ;
147+ }
148+ assert ! ( page. contains( "The exit status is 78." ) ) ;
149+ let reservations = tmp. path ( ) . join ( "eb-stack-docs/admit-no" ) ;
150+ assert_eq ! ( std:: fs:: read_dir( reservations) . unwrap( ) . count( ) , 0 ) ;
151+ }
152+
97153#[ test]
98154fn report_howtos_quote_the_fixture_commands ( ) {
99155 let tmp = tempfile:: tempdir ( ) . expect ( "temp" ) ;
0 commit comments