11#![ cfg( feature = "bin" ) ]
22use chrono:: Utc ;
3- use cpp_linter:: cli :: ThreadComments ;
3+ use cpp_linter:: rest_client :: USER_OUTREACH ;
44use cpp_linter:: run:: run_main;
5+ use cpp_linter:: { cli:: ThreadComments , rest_client:: COMMENT_MARKER } ;
56use git_bot_feedback:: LinesChangedOnly ;
67use mockito:: Matcher ;
78use std:: { env, fmt:: Display , fs, io:: Write , path:: Path } ;
@@ -19,6 +20,8 @@ const MOCK_ASSETS_PATH: &str = "tests/comment_test_assets/";
1920const RESET_RATE_LIMIT_HEADER : & str = "x-ratelimit-reset" ;
2021const REMAINING_RATE_LIMIT_HEADER : & str = "x-ratelimit-remaining" ;
2122
23+ const SUMMARY_OUT_FILE_NAME : & str = "summary_output.md" ;
24+
2225#[ derive( PartialEq , Clone , Copy , Debug ) ]
2326enum EventType {
2427 Push ,
@@ -44,6 +47,7 @@ struct TestParams {
4447 pub fail_dismissal : bool ,
4548 pub fail_posting : bool ,
4649 pub bad_existing_comments : bool ,
50+ pub relative_summary_out_file : bool ,
4751}
4852
4953impl Default for TestParams {
@@ -58,6 +62,7 @@ impl Default for TestParams {
5862 fail_dismissal : false ,
5963 fail_posting : false ,
6064 bad_existing_comments : false ,
65+ relative_summary_out_file : false ,
6166 }
6267 }
6368}
@@ -242,6 +247,12 @@ async fn setup(lib_root: &Path, tmp_dir: &TempDir, test_params: &TestParams) {
242247 ) ;
243248 }
244249
250+ let summary_out_file_path = if test_params. relative_summary_out_file {
251+ std:: path:: PathBuf :: from ( SUMMARY_OUT_FILE_NAME )
252+ } else {
253+ tmp_dir. path ( ) . join ( SUMMARY_OUT_FILE_NAME )
254+ } ;
255+
245256 let mut args = vec ! [
246257 "cpp-linter" . to_string( ) ,
247258 "-v=debug" . to_string( ) ,
@@ -254,6 +265,10 @@ async fn setup(lib_root: &Path, tmp_dir: &TempDir, test_params: &TestParams) {
254265 "-p=build" . to_string( ) ,
255266 "-i=build/**" . to_string( ) ,
256267 format!( "--repo-root={}" , tmp_dir. path( ) . to_str( ) . unwrap( ) ) ,
268+ format!(
269+ "--summary-output-file={}" ,
270+ summary_out_file_path. to_str( ) . unwrap( )
271+ ) ,
257272 ] ;
258273 if test_params. force_lgtm {
259274 args. push ( "-e=c" . to_string ( ) ) ;
@@ -297,6 +312,15 @@ async fn setup(lib_root: &Path, tmp_dir: &TempDir, test_params: &TestParams) {
297312 std:: fs:: read_to_string ( patch_path) . expect ( "Failed to read generated patch file." ) ;
298313 println ! ( "Generated patch content:\n {patch_content}" ) ;
299314 }
315+
316+ let summary_out_file_abs_path = if test_params. relative_summary_out_file {
317+ tmp_dir. path ( ) . join ( SUMMARY_OUT_FILE_NAME )
318+ } else {
319+ summary_out_file_path. clone ( )
320+ } ;
321+ let summary_content = std:: fs:: read_to_string ( & summary_out_file_abs_path) . unwrap ( ) ;
322+ assert ! ( summary_content. contains( COMMENT_MARKER ) ) ;
323+ assert ! ( summary_content. contains( USER_OUTREACH ) ) ;
300324}
301325
302326async fn test_comment ( test_params : & TestParams ) {
@@ -473,3 +497,12 @@ async fn bad_existing_comments() {
473497 } )
474498 . await ;
475499}
500+
501+ #[ tokio:: test]
502+ async fn relative_summary_out_file ( ) {
503+ test_comment ( & TestParams {
504+ relative_summary_out_file : true ,
505+ ..Default :: default ( )
506+ } )
507+ . await ;
508+ }
0 commit comments