Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 crates/core/src/manifest/read/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ fn consumer_only_manifest_parses_without_identity() {
profile: None,
}]
);
assert!(parsed.warnings.is_empty());
assert_eq!(parsed.warnings.len(), 0);
assert!(parse(r#"{ "pak": 1 }"#).is_ok());
}

Expand Down Expand Up @@ -368,7 +368,7 @@ fn files_entries_parse_as_strings_objects_and_alternatives() {
]),
])
);
assert!(parsed.warnings.is_empty());
assert_eq!(parsed.warnings.len(), 0);
}

#[test]
Expand Down Expand Up @@ -771,7 +771,7 @@ fn other_fields_parse_with_their_stated_types() {
);
assert_eq!(manifest.homepage.as_deref(), Some("https://example.com"));
assert_eq!(manifest.readme.as_deref(), Some("README.md"));
assert!(parsed.warnings.is_empty());
assert_eq!(parsed.warnings.len(), 0);
}

#[test]
Expand Down Expand Up @@ -922,7 +922,7 @@ fn spec_examples_parse() {
}
}"#,
);
assert!(libnes.warnings.is_empty());
assert_eq!(libnes.warnings.len(), 0);
assert_eq!(libnes.manifest.profiles.len(), 6);

let project = read(
Expand All @@ -935,7 +935,7 @@ fn spec_examples_parse() {
}
}"#,
);
assert!(project.warnings.is_empty());
assert_eq!(project.warnings.len(), 0);
assert_eq!(project.manifest.dependencies.len(), 2);
}

Expand Down
16 changes: 8 additions & 8 deletions crates/core/src/resolve/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ fn the_newest_version_a_requirement_accepts_is_chosen() {
)
.expect("libnes 0.2 exists");
assert_eq!(chosen(&choice), ["@manybyte/libnes 0.2.1"]);
assert!(choice.warnings.is_empty());
assert_eq!(choice.warnings.len(), 0);
}

#[test]
Expand Down Expand Up @@ -366,7 +366,7 @@ fn a_locked_version_is_kept_while_its_requirement_still_accepts_it() {
)
.expect("0.2.0 still fits");
assert_eq!(chosen(&kept), ["@manybyte/libnes 0.2.0"]);
assert!(kept.warnings.is_empty());
assert_eq!(kept.warnings.len(), 0);

let moved = run(
r#"{ "pak": 1, "dependencies": { "@manybyte/libnes": "0.1" } }"#,
Expand Down Expand Up @@ -814,7 +814,7 @@ fn every_version_pak_lock_pins_is_kept_even_once_yanked() {
)
.expect("the pinned version fits");
assert_eq!(chosen(&choice), [format!("@manybyte/libnes {kept}")]);
assert!(choice.warnings.is_empty());
assert_eq!(choice.warnings.len(), 0);
}
}

Expand Down Expand Up @@ -905,7 +905,7 @@ fn a_dependency_wanting_a_package_from_another_source_than_use_lists_takes_the_l
chosen(&choice),
["@manybyte/libnes 0.2.0", "@manybyte/libgfx 0.1.0"]
);
assert!(choice.warnings.is_empty());
assert_eq!(choice.warnings.len(), 0);
}
}

Expand All @@ -926,7 +926,7 @@ fn a_version_pak_lock_pins_that_its_source_no_longer_lists_is_not_tried() {
)
.expect("0.2.1 is tagged");
assert_eq!(chosen(&choice), ["@manybyte/libnes 0.2.1"]);
assert!(choice.warnings.is_empty());
assert_eq!(choice.warnings.len(), 0);
}

#[test]
Expand All @@ -938,7 +938,7 @@ fn a_yanked_version_pak_lock_does_not_pin_is_skipped() {
)
.expect("0.2.0 is not yanked");
assert_eq!(chosen(&choice), ["@manybyte/libnes 0.2.0"]);
assert!(choice.warnings.is_empty());
assert_eq!(choice.warnings.len(), 0);
}

#[test]
Expand Down Expand Up @@ -1014,7 +1014,7 @@ fn a_version_that_requires_another_version_of_itself_gives_way_to_one_that_fits(
)
.expect("1.0.0 requires only itself");
assert_eq!(chosen(&choice), ["@t/a 1.0.0"]);
assert!(choice.warnings.is_empty());
assert_eq!(choice.warnings.len(), 0);
}

#[test]
Expand Down Expand Up @@ -1384,7 +1384,7 @@ fn an_override_keeps_candidates_aliases_and_checks_their_written_requirements()
keys(&choice),
["a github:acme/fix 2.0.0", "b github:acme/fix 2.0.0"]
);
assert!(choice.beside.is_empty());
assert_eq!(choice.beside.len(), 0);
assert_eq!(
project.allow_conflicts,
[PackageName::parse("@acme/fix").unwrap()]
Expand Down
2 changes: 1 addition & 1 deletion src/github/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.

use std::io::{Read as _, Write as _};
use std::io::Write as _;
use std::net::TcpListener;
use std::thread;

Expand Down
3 changes: 2 additions & 1 deletion tests/manifest_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ fn schema_accepts_story_and_example_manifests_and_rejects_invalid_shapes() {
let Some((header, body)) = block.split_once('\n') else {
continue;
};
let header = header.trim_end_matches('\r');
if header.starts_with("json ") && header.ends_with(".pak.json") {
check_manifest(&schema, body, &format!("{}: {header}", path.display()));
count += 1;
Expand Down Expand Up @@ -421,7 +422,7 @@ fn schema_limitations_are_explicit_and_reader_checked() {
),
];
for (rule, reason, text) in cannot_check {
assert!(!reason.is_empty());
assert_ne!(reason, "");
reader_rejects(text, rule);
if let Ok(value) = serde_json::from_str::<Value>(text) {
assert!(
Expand Down
50 changes: 48 additions & 2 deletions tests/stories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,8 @@ fn accepted_conflicts_persist_for_candidates_add_update_and_remove() {
assert!(sandbox.join(".paks/@manybyte/libnes@0.1.4").is_dir());
assert!(sandbox.join(".paks/@manybyte/libnes@0.2.1").is_dir());
assert_eq!(
fs::read_link(sandbox.join(".paks/@manybyte/libnes")).unwrap(),
PathBuf::from("libnes@0.2.1/inc")
fs::canonicalize(sandbox.join(".paks/@manybyte/libnes")).unwrap(),
fs::canonicalize(sandbox.join(".paks/@manybyte/libnes@0.2.1/inc")).unwrap()
);
for command in [
"pak install",
Expand Down Expand Up @@ -644,6 +644,7 @@ fn parse(text: &str) -> Vec<Block> {
}

fn copy_folder(from: &Path, to: &Path) {
fs::create_dir_all(to).expect("fixture folder created");
for entry in fs::read_dir(from).unwrap_or_else(|_| panic!("fixture {} exists", from.display()))
{
let entry = entry.expect("readable entry");
Expand Down Expand Up @@ -718,6 +719,16 @@ fn folders_at_depth(folder: &Path, depth: usize) -> Vec<PathBuf> {
}

fn shell(sandbox: &Path, cwd: &Path, command: &str) -> (i32, String) {
#[cfg(windows)]
if let Some(path) = command.strip_prefix("readlink ") {
let link = cwd.join(path);
let target = fs::read_link(&link).expect("link readable");
let relative = link_target_for_story(&link, &target);
return (
0,
format!("{}\n", relative.display().to_string().replace('\\', "/")),
);
}
let pak = Path::new(env!("CARGO_BIN_EXE_pak"));
let path = format!(
"{}:{}",
Expand All @@ -736,6 +747,7 @@ fn shell(sandbox: &Path, cwd: &Path, command: &str) -> (i32, String) {
.env("PAK_TEST_GITHUB", sandbox.join("github"))
.env("NO_COLOR", "1")
.env("LC_ALL", "C")
.env("MSYS", "winsymlinks:nativestrict")
.output()
.expect("sh runs");
(
Expand All @@ -744,6 +756,40 @@ fn shell(sandbox: &Path, cwd: &Path, command: &str) -> (i32, String) {
)
}

#[cfg(any(windows, test))]
fn link_target_for_story(link: &Path, target: &Path) -> PathBuf {
if target.is_absolute() {
if let (Ok(parent), Ok(target)) = (
fs::canonicalize(link.parent().unwrap()),
fs::canonicalize(target),
) {
if let Ok(relative) = target.strip_prefix(parent) {
return relative.to_path_buf();
}
}
}
target.to_path_buf()
}

#[test]
fn absolute_link_target_is_relative_to_the_resolved_parent() {
let root = std::env::temp_dir().join(format!("pak-link-target-{}", std::process::id()));
let parent = root.join("project/.paks/@manybyte");
fs::create_dir_all(parent.join("libnes@0.2.1/inc")).unwrap();
fs::create_dir_all(root.join("old")).unwrap();
let link = root.join("old/../project/.paks/@manybyte/libnes");
let target = parent.join("libnes@0.2.1/inc");
assert_eq!(
link_target_for_story(&link, &target),
PathBuf::from("libnes@0.2.1/inc")
);
assert_eq!(
link_target_for_story(&link, &root.join("old")),
root.join("old")
);
fs::remove_dir_all(root).unwrap();
}

fn run_console(sandbox: &Path, cwd: &mut PathBuf, session: &str) {
let mut steps: Vec<(String, Vec<String>)> = Vec::new();
for line in session.lines() {
Expand Down
Loading