2023-10-18 21:06:48 -04:00
|
|
|
|
use std::process::Command;
|
|
|
|
|
|
|
|
|
|
|
|
use anyhow::Result;
|
|
|
|
|
|
use assert_fs::prelude::*;
|
|
|
|
|
|
use insta_cmd::{assert_cmd_snapshot, get_cargo_bin};
|
|
|
|
|
|
|
2023-11-02 16:42:59 +01:00
|
|
|
|
use common::BIN_NAME;
|
|
|
|
|
|
|
|
|
|
|
|
mod common;
|
2023-10-18 21:06:48 -04:00
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn missing_pyproject_toml() -> Result<()> {
|
2023-11-16 13:04:10 -08:00
|
|
|
|
let temp_dir = assert_fs::TempDir::new()?;
|
|
|
|
|
|
let pyproject_toml = temp_dir.child("pyproject.toml");
|
2023-10-18 21:06:48 -04:00
|
|
|
|
|
|
|
|
|
|
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
|
|
|
|
|
|
.arg("remove")
|
|
|
|
|
|
.arg("flask")
|
2023-12-13 19:35:38 -05:00
|
|
|
|
.current_dir(&temp_dir), @r###"
|
|
|
|
|
|
success: false
|
|
|
|
|
|
exit_code: 1
|
|
|
|
|
|
----- stdout -----
|
|
|
|
|
|
|
|
|
|
|
|
----- stderr -----
|
|
|
|
|
|
puffin::remove::workspace_not_found
|
|
|
|
|
|
|
|
|
|
|
|
× Could not find a `pyproject.toml` file in the current directory or any of
|
|
|
|
|
|
│ its parents
|
|
|
|
|
|
"###);
|
2023-10-18 21:06:48 -04:00
|
|
|
|
|
|
|
|
|
|
pyproject_toml.assert(predicates::path::missing());
|
|
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn missing_project_table() -> Result<()> {
|
2023-11-16 13:04:10 -08:00
|
|
|
|
let temp_dir = assert_fs::TempDir::new()?;
|
|
|
|
|
|
let pyproject_toml = temp_dir.child("pyproject.toml");
|
2023-10-18 21:06:48 -04:00
|
|
|
|
pyproject_toml.touch()?;
|
|
|
|
|
|
|
|
|
|
|
|
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
|
|
|
|
|
|
.arg("remove")
|
|
|
|
|
|
.arg("flask")
|
2023-12-13 19:35:38 -05:00
|
|
|
|
.current_dir(&temp_dir), @r###"
|
|
|
|
|
|
success: false
|
|
|
|
|
|
exit_code: 1
|
|
|
|
|
|
----- stdout -----
|
|
|
|
|
|
|
|
|
|
|
|
----- stderr -----
|
|
|
|
|
|
puffin::remove::parse
|
|
|
|
|
|
|
|
|
|
|
|
× Failed to remove `flask` from `pyproject.toml`
|
|
|
|
|
|
╰─▶ no `[project]` table found in `pyproject.toml`
|
|
|
|
|
|
"###);
|
2023-10-18 21:06:48 -04:00
|
|
|
|
|
|
|
|
|
|
pyproject_toml.assert(predicates::str::is_empty());
|
|
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn missing_dependencies_array() -> Result<()> {
|
2023-11-16 13:04:10 -08:00
|
|
|
|
let temp_dir = assert_fs::TempDir::new()?;
|
|
|
|
|
|
let pyproject_toml = temp_dir.child("pyproject.toml");
|
2023-10-18 21:06:48 -04:00
|
|
|
|
pyproject_toml.touch()?;
|
|
|
|
|
|
pyproject_toml.write_str(
|
|
|
|
|
|
r#"[project]
|
|
|
|
|
|
name = "project"
|
|
|
|
|
|
"#,
|
|
|
|
|
|
)?;
|
|
|
|
|
|
|
|
|
|
|
|
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
|
|
|
|
|
|
.arg("remove")
|
|
|
|
|
|
.arg("flask")
|
2023-12-13 19:35:38 -05:00
|
|
|
|
.current_dir(&temp_dir), @r###"
|
|
|
|
|
|
success: false
|
|
|
|
|
|
exit_code: 1
|
|
|
|
|
|
----- stdout -----
|
|
|
|
|
|
|
|
|
|
|
|
----- stderr -----
|
|
|
|
|
|
puffin::remove::parse
|
|
|
|
|
|
|
|
|
|
|
|
× Failed to remove `flask` from `pyproject.toml`
|
|
|
|
|
|
╰─▶ no `[project.dependencies]` array found in `pyproject.toml`
|
|
|
|
|
|
"###);
|
2023-10-18 21:06:48 -04:00
|
|
|
|
|
|
|
|
|
|
pyproject_toml.assert(
|
|
|
|
|
|
r#"[project]
|
|
|
|
|
|
name = "project"
|
|
|
|
|
|
"#,
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn missing_dependency() -> Result<()> {
|
2023-11-16 13:04:10 -08:00
|
|
|
|
let temp_dir = assert_fs::TempDir::new()?;
|
|
|
|
|
|
let pyproject_toml = temp_dir.child("pyproject.toml");
|
2023-10-18 21:06:48 -04:00
|
|
|
|
pyproject_toml.touch()?;
|
|
|
|
|
|
pyproject_toml.write_str(
|
|
|
|
|
|
r#"[project]
|
|
|
|
|
|
name = "project"
|
|
|
|
|
|
dependencies = [
|
|
|
|
|
|
"flask==1.0.0",
|
|
|
|
|
|
]
|
|
|
|
|
|
"#,
|
|
|
|
|
|
)?;
|
|
|
|
|
|
|
|
|
|
|
|
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
|
|
|
|
|
|
.arg("remove")
|
|
|
|
|
|
.arg("requests")
|
2023-12-13 19:35:38 -05:00
|
|
|
|
.current_dir(&temp_dir), @r###"
|
|
|
|
|
|
success: false
|
|
|
|
|
|
exit_code: 1
|
|
|
|
|
|
----- stdout -----
|
|
|
|
|
|
|
|
|
|
|
|
----- stderr -----
|
|
|
|
|
|
puffin::remove::parse
|
|
|
|
|
|
|
|
|
|
|
|
× Failed to remove `requests` from `pyproject.toml`
|
|
|
|
|
|
╰─▶ unable to find package: `requests`
|
|
|
|
|
|
"###);
|
2023-10-18 21:06:48 -04:00
|
|
|
|
|
|
|
|
|
|
pyproject_toml.assert(
|
|
|
|
|
|
r#"[project]
|
|
|
|
|
|
name = "project"
|
|
|
|
|
|
dependencies = [
|
|
|
|
|
|
"flask==1.0.0",
|
|
|
|
|
|
]
|
|
|
|
|
|
"#,
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn remove_dependency() -> Result<()> {
|
2023-11-16 13:04:10 -08:00
|
|
|
|
let temp_dir = assert_fs::TempDir::new()?;
|
|
|
|
|
|
let pyproject_toml = temp_dir.child("pyproject.toml");
|
2023-10-18 21:06:48 -04:00
|
|
|
|
pyproject_toml.touch()?;
|
|
|
|
|
|
pyproject_toml.write_str(
|
|
|
|
|
|
r#"[project]
|
|
|
|
|
|
name = "project"
|
|
|
|
|
|
dependencies = [
|
|
|
|
|
|
"flask==1.0.0",
|
|
|
|
|
|
"requests",
|
|
|
|
|
|
]
|
|
|
|
|
|
"#,
|
|
|
|
|
|
)?;
|
|
|
|
|
|
|
|
|
|
|
|
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
|
|
|
|
|
|
.arg("remove")
|
|
|
|
|
|
.arg("flask")
|
2023-12-13 19:35:38 -05:00
|
|
|
|
.current_dir(&temp_dir), @r###"
|
|
|
|
|
|
success: true
|
|
|
|
|
|
exit_code: 0
|
|
|
|
|
|
----- stdout -----
|
|
|
|
|
|
|
|
|
|
|
|
----- stderr -----
|
|
|
|
|
|
"###);
|
2023-10-18 21:06:48 -04:00
|
|
|
|
|
|
|
|
|
|
pyproject_toml.assert(
|
|
|
|
|
|
r#"[project]
|
|
|
|
|
|
name = "project"
|
|
|
|
|
|
dependencies = [
|
|
|
|
|
|
"requests",
|
|
|
|
|
|
]
|
|
|
|
|
|
"#,
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn empty_array() -> Result<()> {
|
2023-11-16 13:04:10 -08:00
|
|
|
|
let temp_dir = assert_fs::TempDir::new()?;
|
|
|
|
|
|
let pyproject_toml = temp_dir.child("pyproject.toml");
|
2023-10-18 21:06:48 -04:00
|
|
|
|
pyproject_toml.touch()?;
|
|
|
|
|
|
pyproject_toml.write_str(
|
|
|
|
|
|
r#"[project]
|
|
|
|
|
|
name = "project"
|
|
|
|
|
|
dependencies = [
|
|
|
|
|
|
"requests",
|
|
|
|
|
|
]
|
|
|
|
|
|
"#,
|
|
|
|
|
|
)?;
|
|
|
|
|
|
|
|
|
|
|
|
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
|
|
|
|
|
|
.arg("remove")
|
|
|
|
|
|
.arg("requests")
|
2023-12-13 19:35:38 -05:00
|
|
|
|
.current_dir(&temp_dir), @r###"
|
|
|
|
|
|
success: true
|
|
|
|
|
|
exit_code: 0
|
|
|
|
|
|
----- stdout -----
|
|
|
|
|
|
|
|
|
|
|
|
----- stderr -----
|
|
|
|
|
|
"###);
|
2023-10-18 21:06:48 -04:00
|
|
|
|
|
|
|
|
|
|
pyproject_toml.assert(
|
|
|
|
|
|
r#"[project]
|
|
|
|
|
|
name = "project"
|
|
|
|
|
|
dependencies = []
|
|
|
|
|
|
"#,
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn normalize_name() -> Result<()> {
|
2023-11-16 13:04:10 -08:00
|
|
|
|
let temp_dir = assert_fs::TempDir::new()?;
|
|
|
|
|
|
let pyproject_toml = temp_dir.child("pyproject.toml");
|
2023-10-18 21:06:48 -04:00
|
|
|
|
pyproject_toml.touch()?;
|
|
|
|
|
|
pyproject_toml.write_str(
|
|
|
|
|
|
r#"[project]
|
|
|
|
|
|
name = "project"
|
|
|
|
|
|
dependencies = [
|
|
|
|
|
|
"flask==1.0.0",
|
|
|
|
|
|
"requests",
|
|
|
|
|
|
]
|
|
|
|
|
|
"#,
|
|
|
|
|
|
)?;
|
|
|
|
|
|
|
|
|
|
|
|
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
|
|
|
|
|
|
.arg("remove")
|
|
|
|
|
|
.arg("Flask")
|
2023-12-13 19:35:38 -05:00
|
|
|
|
.current_dir(&temp_dir), @r###"
|
|
|
|
|
|
success: true
|
|
|
|
|
|
exit_code: 0
|
|
|
|
|
|
----- stdout -----
|
|
|
|
|
|
|
|
|
|
|
|
----- stderr -----
|
|
|
|
|
|
"###);
|
2023-10-18 21:06:48 -04:00
|
|
|
|
|
|
|
|
|
|
pyproject_toml.assert(
|
|
|
|
|
|
r#"[project]
|
|
|
|
|
|
name = "project"
|
|
|
|
|
|
dependencies = [
|
|
|
|
|
|
"requests",
|
|
|
|
|
|
]
|
|
|
|
|
|
"#,
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn reformat_array() -> Result<()> {
|
2023-11-16 13:04:10 -08:00
|
|
|
|
let temp_dir = assert_fs::TempDir::new()?;
|
|
|
|
|
|
let pyproject_toml = temp_dir.child("pyproject.toml");
|
2023-10-18 21:06:48 -04:00
|
|
|
|
pyproject_toml.touch()?;
|
|
|
|
|
|
pyproject_toml.write_str(
|
|
|
|
|
|
r#"[project]
|
|
|
|
|
|
name = "project"
|
|
|
|
|
|
dependencies = ["flask==1.0.0", "requests"]
|
|
|
|
|
|
"#,
|
|
|
|
|
|
)?;
|
|
|
|
|
|
|
|
|
|
|
|
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
|
|
|
|
|
|
.arg("remove")
|
|
|
|
|
|
.arg("requests")
|
2023-12-13 19:35:38 -05:00
|
|
|
|
.current_dir(&temp_dir), @r###"
|
|
|
|
|
|
success: true
|
|
|
|
|
|
exit_code: 0
|
|
|
|
|
|
----- stdout -----
|
|
|
|
|
|
|
|
|
|
|
|
----- stderr -----
|
|
|
|
|
|
"###);
|
2023-10-18 21:06:48 -04:00
|
|
|
|
|
|
|
|
|
|
pyproject_toml.assert(
|
|
|
|
|
|
r#"[project]
|
|
|
|
|
|
name = "project"
|
|
|
|
|
|
dependencies = [
|
|
|
|
|
|
"flask==1.0.0",
|
|
|
|
|
|
]
|
|
|
|
|
|
"#,
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
|
}
|