@@ -10,7 +10,7 @@ use thiserror::Error;
10
10
use crate :: ffi_items:: FfiItems ;
11
11
use crate :: template:: { CTestTemplate , RustTestTemplate } ;
12
12
use crate :: {
13
- expand , Const , Field , MapInput , Parameter , Result , Static , Struct , Type , VolatileItemKind ,
13
+ Const , Field , MapInput , Parameter , Result , Static , Struct , Type , VolatileItemKind , expand ,
14
14
} ;
15
15
16
16
/// A function that takes a mappable input and returns its mapping as Some, otherwise
@@ -600,33 +600,34 @@ impl TestGenerator {
600
600
. unwrap_or_else ( || env:: var ( "OUT_DIR" ) . unwrap ( ) . into ( ) ) ;
601
601
let output_file_path = output_directory. join ( output_file_path) ;
602
602
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
+
603
614
// Generate the Rust side of the tests.
604
615
File :: create ( output_file_path. with_extension ( "rs" ) )
605
616
. 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 ( ) )
617
618
. map_err ( GenerationError :: OsError ) ?;
618
619
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
+
619
626
// Generate the C/Cxx side of the tests.
620
627
let c_output_path = output_file_path. with_extension ( "c" ) ;
621
628
File :: create ( & c_output_path)
622
629
. 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 ( ) )
630
631
. map_err ( GenerationError :: OsError ) ?;
631
632
632
633
Ok ( output_file_path)
0 commit comments