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
5 changes: 2 additions & 3 deletions src/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::{env, fs, process};
use anyhow::Context;
use relative_path::RelativePathBuf;
use serde::Deserialize;
use tempfile::Builder;

use crate::nix_file::CallPackageArgumentInfo;
use crate::problem::{
Expand Down Expand Up @@ -155,9 +154,9 @@ fn mutate_nix_instatiate_arguments_based_on_cfg(
pub fn check_values(
nixpkgs_path: &Path,
nix_file_store: &mut NixFileStore,
package_names: Vec<String>,
package_names: &[String],
) -> validation::Result<ratchet::Nixpkgs> {
let work_dir = Builder::new()
let work_dir = tempfile::Builder::new()
.prefix("nixpkgs-vet")
.tempdir()
.with_context(|| "Failed to create a working directory")?;
Expand Down
3 changes: 1 addition & 2 deletions src/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ impl LineIndex {
pub fn line(&self, index: usize) -> usize {
match self.newlines.binary_search(&index) {
// +1 because lines are 1-indexed
Ok(x) => x + 1,
Err(x) => x + 1,
Ok(x) | Err(x) => x + 1,
}
}

Expand Down
22 changes: 14 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
// #![warn(clippy::pedantic)]
// #![allow(clippy::uninlined_format_args)]
// #![allow(clippy::enum_glob_use)]
// #![allow(clippy::module_name_repetitions)]
// #![allow(clippy::doc_markdown)]
// #![allow(clippy::if_not_else)]
// #![allow(clippy::ignored_unit_patterns)]
Comment thread
philiptaron marked this conversation as resolved.
mod eval;
mod location;
mod nix_file;
Expand Down Expand Up @@ -112,7 +119,7 @@ fn check_nixpkgs(nixpkgs_path: &Path) -> validation::Result<ratchet::Nixpkgs> {

// Only if we could successfully parse the structure, we do the evaluation checks
let result = structure.result_map(|package_names| {
eval::check_values(&nixpkgs_path, &mut nix_file_store, package_names)
eval::check_values(&nixpkgs_path, &mut nix_file_store, package_names.as_slice())
})?;

Ok(result)
Expand Down Expand Up @@ -209,7 +216,7 @@ mod tests {
"symlinked_tmpdir",
Path::new("tests/success"),
"Validated successfully\n",
)
);
});
Ok(())
}
Expand Down Expand Up @@ -245,12 +252,11 @@ mod tests {

let actual_errors = format!("{status}\n");

if !expected_errors_regex.is_match(&actual_errors) {
panic!(
"Failed test case {name}: {}",
StrComparison::new(expected_errors, &actual_errors)
);
}
assert!(
expected_errors_regex.is_match(&actual_errors),
"Failed test case {name}: {}",
StrComparison::new(expected_errors, &actual_errors)
);
}

/// Check whether a path is in a case-insensitive filesystem
Expand Down
6 changes: 3 additions & 3 deletions src/nix_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ mod tests {
(
Position { line, column },
result
.map(|node| node.to_string())
.map(ToString::to_string)
.map_right(|node| node.to_string()),
)
}));
Expand All @@ -589,7 +589,7 @@ mod tests {
fn detects_call_package() -> anyhow::Result<()> {
let temp_dir = tests::tempdir()?;
let file = temp_dir.path().join("file.nix");
let contents = indoc! {r#"
let contents = indoc! {r"
self: with self; {
a.sub = null;
b = null;
Expand All @@ -601,7 +601,7 @@ mod tests {
h = callPackage ./file.nix { x = 0; };
i = callPackage ({ }: { }) (let in { });
}
"#};
"};

std::fs::write(&file, contents)?;

Expand Down
2 changes: 1 addition & 1 deletion src/structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn read_dir_sorted(base_dir: &Path) -> anyhow::Result<Vec<DirEntry>> {

process_results(listing, |listing| {
use itertools::Itertools;
Itertools::collect_vec(listing.sorted_by_key(|entry| entry.file_name()))
Itertools::collect_vec(listing.sorted_by_key(DirEntry::file_name))
})
.with_context(ctx)
}
Expand Down
3 changes: 1 addition & 2 deletions src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ impl Validation<()> {
pub fn and<A>(self, other: Validation<A>) -> Validation<A> {
match (self, other) {
(Success(_), Success(right_value)) => Success(right_value),
(Failure(errors), Success(_)) => Failure(errors),
(Success(_), Failure(errors)) => Failure(errors),
(Failure(errors_l), Failure(errors_r)) => Failure(concat([errors_l, errors_r])),
(Failure(errors), Success(_)) | (Success(_), Failure(errors)) => Failure(errors),
}
}
}
Expand Down