1
+ use std:: fs:: read_to_string;
2
+ use std:: path:: PathBuf ;
3
+
1
4
use crate :: cli:: cmd:: mdbook_cmd;
2
5
use crate :: dummy_book:: DummyBook ;
3
6
@@ -6,21 +9,32 @@ use mdbook::config::Config;
6
9
/// Run `mdbook init` with `--force` to skip the confirmation prompts
7
10
#[ test]
8
11
fn base_mdbook_init_can_skip_confirmation_prompts ( ) {
9
- let temp = DummyBook :: new ( ) . build ( ) . unwrap ( ) ;
12
+ let temp = DummyBook :: new ( ) . empty ( ) . unwrap ( ) ;
10
13
11
- // doesn't exist before
12
- assert ! ( ! temp. path( ) . join ( "book" ) . exists ( ) ) ;
14
+ // empty folder
15
+ assert_eq ! ( temp. path( ) . read_dir ( ) . unwrap ( ) . count ( ) , 0 ) ;
13
16
14
17
let mut cmd = mdbook_cmd ( ) ;
15
18
cmd. args ( [ "init" , "--force" ] ) . current_dir ( temp. path ( ) ) ;
16
19
cmd. assert ( )
17
20
. success ( )
18
- . stdout ( predicates:: str:: contains ( "\n All done, no errors...\n " ) ) ;
21
+ . stdout ( predicates:: str:: contains ( "\n All done, no errors...\n " ) )
22
+ . stderr ( predicates:: str:: contains (
23
+ "Creating a new book with stub content" ,
24
+ ) ) ;
19
25
20
26
let config = Config :: from_disk ( temp. path ( ) . join ( "book.toml" ) ) . unwrap ( ) ;
21
27
assert_eq ! ( config. book. title, None ) ;
28
+ assert_eq ! ( config. book. language, Some ( String :: from( "en" ) ) ) ;
29
+ assert_eq ! ( config. book. multilingual, false ) ;
30
+ assert_eq ! ( config. book. src, PathBuf :: from( "src" ) ) ;
22
31
23
32
assert ! ( !temp. path( ) . join( ".gitignore" ) . exists( ) ) ;
33
+ let summary = read_to_string ( temp. path ( ) . join ( "src" ) . join ( "SUMMARY.md" ) ) . unwrap ( ) ;
34
+ assert_eq ! ( summary, "# Summary\n \n - [Chapter 1](./chapter_1.md)\n " ) ;
35
+ let chapter_1 = read_to_string ( temp. path ( ) . join ( "src" ) . join ( "chapter_1.md" ) ) . unwrap ( ) ;
36
+ assert_eq ! ( chapter_1, "# Chapter 1\n " ) ;
37
+ assert ! ( temp. path( ) . join( "book" ) . exists( ) ) ;
24
38
}
25
39
26
40
/// Run `mdbook init` with `--title` without git config.
0 commit comments