@@ -10,7 +10,7 @@ use thiserror::Error;
1010use crate :: ffi_items:: FfiItems ;
1111use crate :: template:: { CTestTemplate , RustTestTemplate } ;
1212use crate :: {
13- expand , Const , Field , MapInput , Parameter , Result , Static , Struct , Type , VolatileItemKind ,
13+ Const , Field , MapInput , Parameter , Result , Static , Struct , Type , VolatileItemKind , expand ,
1414} ;
1515
1616/// A function that takes a mappable input and returns its mapping as Some, otherwise
@@ -600,33 +600,34 @@ impl TestGenerator {
600600 . unwrap_or_else ( || env:: var ( "OUT_DIR" ) . unwrap ( ) . into ( ) ) ;
601601 let output_file_path = output_directory. join ( output_file_path) ;
602602
603+ let ensure_trailing_newline = |s : & mut String | {
604+ s. truncate ( s. trim_end ( ) . len ( ) ) ;
605+ s. push ( '\n' ) ;
606+ } ;
607+
608+ let mut rust_file = RustTestTemplate :: new ( & ffi_items, self )
609+ . map_err ( |e| GenerationError :: TemplateRender ( "Rust" . to_string ( ) , e. to_string ( ) ) ) ?
610+ . render ( )
611+ . map_err ( |e| GenerationError :: TemplateRender ( "Rust" . to_string ( ) , e. to_string ( ) ) ) ?;
612+ ensure_trailing_newline ( & mut rust_file) ;
613+
603614 // Generate the Rust side of the tests.
604615 File :: create ( output_file_path. with_extension ( "rs" ) )
605616 . map_err ( GenerationError :: OsError ) ?
606- . write_all (
607- RustTestTemplate :: new ( & ffi_items, self )
608- . map_err ( |e| {
609- GenerationError :: TemplateRender ( "Rust" . to_string ( ) , e. to_string ( ) )
610- } ) ?
611- . render ( )
612- . map_err ( |e| {
613- GenerationError :: TemplateRender ( "Rust" . to_string ( ) , e. to_string ( ) )
614- } ) ?
615- . as_bytes ( ) ,
616- )
617+ . write_all ( rust_file. as_bytes ( ) )
617618 . map_err ( GenerationError :: OsError ) ?;
618619
620+ let mut c_file = CTestTemplate :: new ( & ffi_items, self )
621+ . map_err ( |e| GenerationError :: TemplateRender ( "C" . to_string ( ) , e. to_string ( ) ) ) ?
622+ . render ( )
623+ . map_err ( |e| GenerationError :: TemplateRender ( "C" . to_string ( ) , e. to_string ( ) ) ) ?;
624+ ensure_trailing_newline ( & mut c_file) ;
625+
619626 // Generate the C/Cxx side of the tests.
620627 let c_output_path = output_file_path. with_extension ( "c" ) ;
621628 File :: create ( & c_output_path)
622629 . map_err ( GenerationError :: OsError ) ?
623- . write_all (
624- CTestTemplate :: new ( & ffi_items, self )
625- . map_err ( |e| GenerationError :: TemplateRender ( "C" . to_string ( ) , e. to_string ( ) ) ) ?
626- . render ( )
627- . map_err ( |e| GenerationError :: TemplateRender ( "C" . to_string ( ) , e. to_string ( ) ) ) ?
628- . as_bytes ( ) ,
629- )
630+ . write_all ( c_file. as_bytes ( ) )
630631 . map_err ( GenerationError :: OsError ) ?;
631632
632633 Ok ( output_file_path)
0 commit comments