@@ -142,3 +142,57 @@ fn test_incremental_indexing() {
142142 let new_hash = index. get_file_hash ( "a.rs" ) . unwrap ( ) ;
143143 assert_eq ! ( new_hash, Some ( "hash_a_v2" . to_string( ) ) ) ;
144144}
145+
146+ // --- CLI flag tests using the binary ---
147+
148+ #[ test]
149+ fn test_show_root_at_git_root ( ) {
150+ let dir = tempfile:: TempDir :: new ( ) . unwrap ( ) ;
151+ std:: fs:: create_dir ( dir. path ( ) . join ( ".git" ) ) . unwrap ( ) ;
152+
153+ let output = std:: process:: Command :: new ( env ! ( "CARGO_BIN_EXE_vecgrep" ) )
154+ . arg ( "--show-root" )
155+ . current_dir ( dir. path ( ) )
156+ . output ( )
157+ . unwrap ( ) ;
158+
159+ assert ! ( output. status. success( ) ) ;
160+ let stdout = String :: from_utf8 ( output. stdout ) . unwrap ( ) ;
161+ let expected = dir. path ( ) . canonicalize ( ) . unwrap ( ) ;
162+ assert_eq ! ( stdout. trim( ) , expected. display( ) . to_string( ) ) ;
163+ }
164+
165+ #[ test]
166+ fn test_show_root_from_subdirectory ( ) {
167+ let dir = tempfile:: TempDir :: new ( ) . unwrap ( ) ;
168+ std:: fs:: create_dir ( dir. path ( ) . join ( ".git" ) ) . unwrap ( ) ;
169+ std:: fs:: create_dir_all ( dir. path ( ) . join ( "src/deep" ) ) . unwrap ( ) ;
170+
171+ let output = std:: process:: Command :: new ( env ! ( "CARGO_BIN_EXE_vecgrep" ) )
172+ . arg ( "--show-root" )
173+ . current_dir ( dir. path ( ) . join ( "src/deep" ) )
174+ . output ( )
175+ . unwrap ( ) ;
176+
177+ assert ! ( output. status. success( ) ) ;
178+ let stdout = String :: from_utf8 ( output. stdout ) . unwrap ( ) ;
179+ let expected = dir. path ( ) . canonicalize ( ) . unwrap ( ) ;
180+ assert_eq ! ( stdout. trim( ) , expected. display( ) . to_string( ) ) ;
181+ }
182+
183+ #[ test]
184+ fn test_show_root_no_marker_falls_back_to_cwd ( ) {
185+ let dir = tempfile:: TempDir :: new ( ) . unwrap ( ) ;
186+ // No .git, .hg, .jj, or .vecgrep — falls back to cwd
187+
188+ let output = std:: process:: Command :: new ( env ! ( "CARGO_BIN_EXE_vecgrep" ) )
189+ . arg ( "--show-root" )
190+ . current_dir ( dir. path ( ) )
191+ . output ( )
192+ . unwrap ( ) ;
193+
194+ assert ! ( output. status. success( ) ) ;
195+ let stdout = String :: from_utf8 ( output. stdout ) . unwrap ( ) ;
196+ let expected = dir. path ( ) . canonicalize ( ) . unwrap ( ) ;
197+ assert_eq ! ( stdout. trim( ) , expected. display( ) . to_string( ) ) ;
198+ }
0 commit comments