Skip to content

Commit

Permalink
Fix creating package with snfoundry test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
ddoktorski committed Dec 11, 2024
1 parent 766ad0e commit 04d07e1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
10 changes: 5 additions & 5 deletions scarb/src/ops/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
18 changes: 15 additions & 3 deletions scarb/tests/snforge_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"));
Expand Down

0 comments on commit 04d07e1

Please sign in to comment.