@@ -5,6 +5,7 @@ use ghrepo::GHRepo;
55use repomaker:: RepoMaker ;
66use std:: process:: Command ;
77use std:: str;
8+ use tempfile:: tempdir;
89use which:: which;
910
1011#[ test]
@@ -43,6 +44,68 @@ fn test_run_json() {
4344 assert_eq ! ( out, expected) ;
4445}
4546
47+ #[ test]
48+ fn test_run_empty ( ) {
49+ if which ( "git" ) . is_err ( ) {
50+ return ;
51+ }
52+ let tmp_path = tempdir ( ) . unwrap ( ) ;
53+ let out = Command :: new ( env ! ( "CARGO_BIN_EXE_ghrepo" ) )
54+ . arg ( tmp_path. path ( ) )
55+ . output ( )
56+ . unwrap ( ) ;
57+ assert_eq ! ( str :: from_utf8( & out. stdout) . unwrap( ) , "" ) ;
58+ assert_eq ! (
59+ str :: from_utf8( & out. stderr) . unwrap( ) . trim( ) ,
60+ "fatal: not a git repository (or any of the parent directories): .git"
61+ ) ;
62+ assert ! ( !out. status. success( ) ) ;
63+ }
64+
65+ #[ test]
66+ fn test_run_no_such_remote ( ) {
67+ if which ( "git" ) . is_err ( ) {
68+ return ;
69+ }
70+ let maker = RepoMaker :: new ( ) ;
71+ maker. init ( "trunk" ) ;
72+ let out = Command :: new ( env ! ( "CARGO_BIN_EXE_ghrepo" ) )
73+ . arg ( maker. path ( ) )
74+ . output ( )
75+ . unwrap ( ) ;
76+ assert_eq ! ( str :: from_utf8( & out. stdout) . unwrap( ) , "" ) ;
77+ assert_eq ! (
78+ str :: from_utf8( & out. stderr) . unwrap( ) . trim( ) ,
79+ "error: No such remote 'origin'"
80+ ) ;
81+ assert_eq ! ( out. status. code( ) , Some ( 2 ) ) ;
82+ }
83+
84+ #[ test]
85+ fn test_run_invalid_url ( ) {
86+ if which ( "git" ) . is_err ( ) {
87+ return ;
88+ }
89+ let maker = RepoMaker :: new ( ) ;
90+ maker. init ( "trunk" ) ;
91+ maker. add_remote ( "upstream" , "https://git.example.com/repo.git" ) ;
92+ let out = Command :: new ( env ! ( "CARGO_BIN_EXE_ghrepo" ) )
93+ . arg ( "-rupstream" )
94+ . arg ( maker. path ( ) )
95+ . output ( )
96+ . unwrap ( ) ;
97+ assert_eq ! ( str :: from_utf8( & out. stdout) . unwrap( ) , "" ) ;
98+ assert_eq ! (
99+ str :: from_utf8( & out. stderr) . unwrap( ) . trim( ) ,
100+ concat!(
101+ "ghrepo: Repository remote URL is not a GitHub URL:" ,
102+ " Invalid GitHub repository spec:" ,
103+ " \" https://git.example.com/repo.git\" " ,
104+ ) ,
105+ ) ;
106+ assert_eq ! ( out. status. code( ) , Some ( 1 ) ) ;
107+ }
108+
46109fn readcmd ( args : & [ & str ] ) -> String {
47110 let out = Command :: new ( env ! ( "CARGO_BIN_EXE_ghrepo" ) )
48111 . args ( args)
0 commit comments