()
| 10 | |
| 11 | #[test] |
| 12 | fn init_subcommand() { |
| 13 | let repo_name = "init_subcommand"; |
| 14 | let repo = setup_git_repo(repo_name); |
| 15 | let path_to_repo = generate_path_to_repo(repo_name); |
| 16 | |
| 17 | { |
| 18 | // create new file |
| 19 | create_new_file(&path_to_repo, "hello_world.txt", "Hello, world!"); |
| 20 | |
| 21 | // add first commit to master |
| 22 | first_commit_all(&repo, "first commit"); |
| 23 | }; |
| 24 | |
| 25 | assert_eq!(&get_current_branch_name(&repo), "master"); |
| 26 | |
| 27 | // init subcommand with no arguments |
| 28 | let args: Vec<&str> = vec!["init"]; |
| 29 | let output = run_test_bin_expect_err(&path_to_repo, args); |
| 30 | |
| 31 | assert!(String::from_utf8_lossy(&output.stdout).is_empty()); |
| 32 | assert!(String::from_utf8_lossy(&output.stderr) |
| 33 | .contains("The following required arguments were not provided")); |
| 34 | assert!(String::from_utf8_lossy(&output.stderr).contains("<chain_name>")); |
| 35 | |
| 36 | // init subcommand with chain name, but no root branch |
| 37 | let args: Vec<&str> = vec!["init", "chain_name"]; |
| 38 | let output = run_test_bin_expect_err(&path_to_repo, args); |
| 39 | |
| 40 | assert!(String::from_utf8_lossy(&output.stdout).is_empty()); |
| 41 | assert!(String::from_utf8_lossy(&output.stderr).contains("Please provide the root branch.")); |
| 42 | |
| 43 | // init subcommand with chain name, and use current branch as the root branch |
| 44 | assert_eq!(&get_current_branch_name(&repo), "master"); |
| 45 | |
| 46 | let args: Vec<&str> = vec!["init", "chain_name", "master"]; |
| 47 | let output = run_test_bin_expect_err(&path_to_repo, args); |
| 48 | |
| 49 | assert!(String::from_utf8_lossy(&output.stdout).is_empty()); |
| 50 | assert!(String::from_utf8_lossy(&output.stderr) |
| 51 | .contains("Current branch cannot be the root branch: master")); |
| 52 | |
| 53 | // create and checkout new branch named some_branch_1 |
| 54 | { |
| 55 | let branch_name = "some_branch_1"; |
| 56 | create_branch(&repo, branch_name); |
| 57 | checkout_branch(&repo, branch_name); |
| 58 | }; |
| 59 | |
| 60 | { |
| 61 | // create new file |
| 62 | create_new_file(&path_to_repo, "file_1.txt", "contents 1"); |
| 63 | |
| 64 | // add commit to branch some_branch_1 |
| 65 | commit_all(&repo, "message"); |
| 66 | }; |
| 67 | |
| 68 | // init subcommand with chain name, and use master as the root branch |
| 69 | assert_eq!(&get_current_branch_name(&repo), "some_branch_1"); |
nothing calls this directly
no test coverage detected