Skip to content

Commit e872a0b

Browse files
committed
Assert that there's only one file in config when using expand
1 parent 7b6f4a0 commit e872a0b

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,13 +609,28 @@ impl Config {
609609
/// Run the compiler, returning the macro-expanded version of the input files.
610610
///
611611
/// This is only relevant for C and C++ files.
612+
///
613+
/// # Panics
614+
/// Panics if more than one file is present in the config, as macro
615+
/// expansion only makes sense for a single file.
616+
///
617+
/// # Example
618+
/// ```no_run
619+
/// gcc::Config::new()
620+
/// .file("src/foo.c")
621+
/// .expand()
622+
/// ```
612623
pub fn expand(&self) -> Vec<u8> {
613624
let compiler = self.get_compiler();
614625
let mut cmd = compiler.to_command();
615626
for &(ref a, ref b) in self.env.iter() {
616627
cmd.env(a, b);
617628
}
618629
cmd.arg(compiler.family.expand_flag());
630+
631+
assert_eq!(self.files.len(), 1,
632+
"Expand may only be called for a single file");
633+
619634
for file in self.files.iter() {
620635
cmd.arg(file);
621636
}

0 commit comments

Comments
 (0)