Skip to content

Commit 9dcf58b

Browse files
committed
Added automated testing
1 parent b7ec6c4 commit 9dcf58b

File tree

13 files changed

+486
-7
lines changed

13 files changed

+486
-7
lines changed

Cargo.lock

Lines changed: 81 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/cli/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ notify.workspace = true
8686

8787
[dev-dependencies]
8888
pretty_assertions.workspace = true
89+
fs_extra.workspace = true
90+
assert_cmd = "2"
91+
predicates = "3"
92+
portpicker = "0.1"
93+
reqwest = { version = "0.12", features = ["blocking", "json"] }
8994

9095
[target.'cfg(not(target_env = "msvc"))'.dependencies]
9196
tikv-jemallocator = { workspace = true }

crates/cli/src/subcommands/build.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ pub fn cli() -> clap::Command {
2222
.default_value("src")
2323
.help("The directory to lint for nonfunctional print statements. If set to the empty string, skips linting.")
2424
)
25+
.arg(
26+
Arg::new("features")
27+
.long("features")
28+
.value_parser(clap::value_parser!(OsString))
29+
.required(false)
30+
.help("Additional features to pass to the build process (e.g. `--features feature1,feature2` for Rust modules).")
31+
)
2532
.arg(
2633
Arg::new("debug")
2734
.long("debug")
@@ -33,6 +40,7 @@ pub fn cli() -> clap::Command {
3340

3441
pub async fn exec(_config: Config, args: &ArgMatches) -> Result<(PathBuf, &'static str), anyhow::Error> {
3542
let project_path = args.get_one::<PathBuf>("project_path").unwrap();
43+
let features = args.get_one::<OsString>("features");
3644
let lint_dir = args.get_one::<OsString>("lint_dir").unwrap();
3745
let lint_dir = if lint_dir.is_empty() {
3846
None
@@ -56,7 +64,7 @@ pub async fn exec(_config: Config, args: &ArgMatches) -> Result<(PathBuf, &'stat
5664
));
5765
}
5866

59-
let result = crate::tasks::build(project_path, lint_dir.as_deref(), build_debug)?;
67+
let result = crate::tasks::build(project_path, lint_dir.as_deref(), build_debug, features)?;
6068
println!("Build finished successfully.");
6169

6270
Ok(result)

crates/cli/src/subcommands/dev.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ async fn generate_build_and_publish(
388388

389389
println!("{}", "Building...".cyan());
390390
let (_path_to_program, _host_type) =
391-
tasks::build(spacetimedb_dir, Some(Path::new("src")), false).context("Failed to build project")?;
391+
tasks::build(spacetimedb_dir, Some(Path::new("src")), false, None).context("Failed to build project")?;
392392
println!("{}", "Build complete!".green());
393393

394394
println!("{}", "Generating module bindings...".cyan());

crates/cli/src/subcommands/publish.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ pub fn cli() -> clap::Command {
6767
.arg(
6868
Arg::new("break_clients")
6969
.long("break-clients")
70+
.alias("yes-break-clients")
7071
.action(SetTrue)
7172
.help("Allow breaking changes when publishing to an existing database identity. This will force publish even if it will break existing clients, but will NOT force publish if it would cause deletion of any data in the database. See --yes and --delete-data for details.")
7273
)
@@ -361,9 +362,22 @@ async fn apply_pre_publish_if_needed(
361362
builder = builder.query(&[("clear", true)]);
362363
}
363364
PrePublishResult::AutoMigrate(auto) => {
365+
if clear_database == ClearMode::Always {
366+
println!("Auto-migration, does NOT require clearing the database, but proceeding with database clear due to --delete-data=always.");
367+
println!(
368+
"This will DESTROY the current {} module, and ALL corresponding data.",
369+
name_or_identity
370+
);
371+
if !y_or_n(
372+
force,
373+
format!("Are you sure you want to proceed? [deleting {}]", name_or_identity).as_str(),
374+
)? {
375+
anyhow::bail!("Aborting");
376+
}
377+
builder = builder.query(&[("clear", true)]);
378+
return Ok(builder);
379+
}
364380
println!("{}", auto.migrate_plan);
365-
// We only arrive here if you have not specified ClearMode::Always AND there was no
366-
// conflict that required manual migration.
367381
if auto.break_clients
368382
&& !y_or_n(
369383
force_break_clients || force,

crates/cli/src/tasks/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@ pub fn build(
1313
project_path: &Path,
1414
lint_dir: Option<&Path>,
1515
build_debug: bool,
16+
features: Option<&std::ffi::OsString>,
1617
) -> anyhow::Result<(PathBuf, &'static str)> {
1718
let lang = util::detect_module_language(project_path)?;
19+
if features.is_some() && lang != ModuleLanguage::Rust {
20+
anyhow::bail!("The --features option is only supported for Rust modules.");
21+
}
1822
let output_path = match lang {
19-
ModuleLanguage::Rust => build_rust(project_path, lint_dir, build_debug),
23+
ModuleLanguage::Rust => build_rust(project_path, features, lint_dir, build_debug),
2024
ModuleLanguage::Csharp => build_csharp(project_path, build_debug),
2125
ModuleLanguage::Javascript => build_javascript(project_path, build_debug),
2226
}?;

crates/cli/src/tasks/rust.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn cargo_cmd(subcommand: &str, build_debug: bool, args: &[&str]) -> duct::Expres
2323
)
2424
}
2525

26-
pub(crate) fn build_rust(project_path: &Path, lint_dir: Option<&Path>, build_debug: bool) -> anyhow::Result<PathBuf> {
26+
pub(crate) fn build_rust(project_path: &Path, features: Option<&std::ffi::OsString>, lint_dir: Option<&Path>, build_debug: bool) -> anyhow::Result<PathBuf> {
2727
// Make sure that we have the wasm target installed
2828
if !has_wasm32_target() {
2929
if has_rust_up() {
@@ -75,7 +75,17 @@ pub(crate) fn build_rust(project_path: &Path, lint_dir: Option<&Path>, build_deb
7575
);
7676
}
7777

78-
let reader = cargo_cmd("build", build_debug, &["--message-format=json-render-diagnostics"])
78+
let mut args = if let Some(features) = features {
79+
vec![format!("--features={}", features.to_string_lossy())]
80+
} else {
81+
vec![]
82+
};
83+
args.push("--message-format=json-render-diagnostics".to_string());
84+
85+
// Convert Vec<String> to Vec<&str>
86+
let args_str: Vec<&str> = args.iter().map(|s| s.as_str()).collect();
87+
88+
let reader = cargo_cmd("build", build_debug, &args_str)
7989
.dir(project_path)
8090
.reader()?;
8191

0 commit comments

Comments
 (0)