diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5ed2eeab0..4e68a9f7d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -108,3 +108,11 @@ jobs: cache-dependency-path: website/package-lock.json - run: npm ci - run: npm run fmt:check + + snforge-init: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + - uses: foundry-rs/setup-snfoundry@v3 + - run: cargo test --profile=ci --package scarb --test snforge_init new_simple -- --ignored diff --git a/scarb/src/ops/new.rs b/scarb/src/ops/new.rs index 5aaa404ea..8589bf67b 100644 --- a/scarb/src/ops/new.rs +++ b/scarb/src/ops/new.rs @@ -217,12 +217,12 @@ fn mk( Ok(()) } -fn init_snforge(name: PackageName, target_dir: Utf8PathBuf, config: &Config) -> Result<()> { - let target_dir = target_dir.parent().context("package must have a parent")?; +fn init_snforge(name: PackageName, root_dir: Utf8PathBuf, config: &Config) -> Result<()> { let mut process = Command::new("snforge") - .arg("init") - .arg(name.as_str()) - .current_dir(target_dir) + .arg("new") + .args(["--name", name.as_str()]) + .arg("--overwrite") + .arg(root_dir.as_str()) .envs(get_env_vars(config, None)?) .stderr(Stdio::inherit()) .stdout(Stdio::inherit()) diff --git a/scarb/tests/snforge_init.rs b/scarb/tests/snforge_init.rs index 8e19310a3..5cf93b117 100644 --- a/scarb/tests/snforge_init.rs +++ b/scarb/tests/snforge_init.rs @@ -3,14 +3,23 @@ use assert_fs::TempDir; use scarb::core::TomlManifest; use scarb_test_support::command::Scarb; use scarb_test_support::fsx::AssertFsUtf8Ext; +use test_case::test_case; -#[test] +#[test_case(None)] +#[test_case(Some("simple_project"))] #[ignore = "run this test by name"] -fn new_simple() { +fn new_simple(package_name: Option<&str>) { let pt = TempDir::new().unwrap(); + let name_args = if let Some(package_name) = package_name { + vec!["--name", package_name] + } else { + vec![] + }; + Scarb::quick_snapbox() .arg("new") + .args(name_args) .arg("hello") .args(["--test-runner", "starknet-foundry"]) .current_dir(&pt) @@ -27,7 +36,10 @@ fn new_simple() { assert!(t.child(".git").is_dir()); let toml_manifest = TomlManifest::read_from_path(t.child("Scarb.toml").utf8_path()).unwrap(); - assert_eq!(toml_manifest.package.unwrap().name.as_str(), "hello"); + assert_eq!( + toml_manifest.package.unwrap().name.as_str(), + package_name.unwrap_or("hello") + ); let deps = toml_manifest.dependencies.unwrap(); assert_eq!(deps.len(), 1); assert!(deps.contains_key("starknet"));