Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix creating package with snfoundry test runner #1843

Merged
merged 4 commits into from
Jan 16, 2025
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
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>) {
ddoktorski marked this conversation as resolved.
Show resolved Hide resolved
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
Loading