Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub struct BundleArgs {
pub file: PathBuf,

/// Extra options passed through to the compiler
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
#[arg(last = true)]
pub options: Vec<String>,
Comment thread
TwoSquirrels marked this conversation as resolved.
Outdated
}

Expand Down Expand Up @@ -90,3 +90,28 @@ pub enum LibraryCommand {
verbose: bool,
},
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn options_after_file_are_parsed_as_risundle_flags() {
let args = BundleArgs::try_parse_from(["risundle", "main.cpp", "-e"]).unwrap();
assert!(args.embed);
assert!(args.options.is_empty());
}

#[test]
fn double_dash_separates_compiler_options() {
let args =
BundleArgs::try_parse_from(["risundle", "main.cpp", "--", "-std=gnu++20", "-O2"])
.unwrap();
assert_eq!(args.options, ["-std=gnu++20", "-O2"]);
}

#[test]
fn hyphen_arguments_before_double_dash_are_rejected() {
assert!(BundleArgs::try_parse_from(["risundle", "main.cpp", "-O2"]).is_err());
}
}
23 changes: 23 additions & 0 deletions tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,29 @@ fn bundle_ignores_identifiers_in_comments_and_strings() {
assert_eq!(compile_and_run(&sandbox, &bundled).trim(), "5");
}

#[test]
fn bundle_passes_options_after_double_dash_to_compiler() {
let sandbox = Sandbox::new();
sandbox.write(
"main.cpp",
"#ifdef RISUNDLE_TEST_ANSWER\nint main() { return RISUNDLE_TEST_ANSWER; }\n\
#else\n#error RISUNDLE_TEST_ANSWER is not defined\n#endif\n",
);

// -D が届かなければ #error でプリプロセスごと失敗するので、成功 = 受け渡しの証明。
let output = sandbox
.risundle()
.args(["-k", STD, "main.cpp", "--", "-DRISUNDLE_TEST_ANSWER=0"])
.output()
.expect("run bundle");
assert!(output.status.success(), "bundle failed");
let bundled = String::from_utf8(output.stdout).expect("utf-8");
Comment thread
TwoSquirrels marked this conversation as resolved.
assert!(
bundled.contains("return 0"),
"-D で定義したマクロが展開されるべき"
);
}

#[test]
fn embed_includes_original_source_as_comment() {
let sandbox = Sandbox::new();
Expand Down
Loading