Skip to content

Commit

Permalink
Merge pull request #60 from ongardie/update2
Browse files Browse the repository at this point in the history
More updates and switch from insta to expect-test
  • Loading branch information
ongardie authored Feb 1, 2024
2 parents fd6995f + 4b3ee1e commit 69268a8
Show file tree
Hide file tree
Showing 30 changed files with 291 additions and 535 deletions.
65 changes: 14 additions & 51 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 10 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ repository = "https://github.com/ongardie/cubicle"

default-run = "cub"
edition = "2021"
rust-version = "1.75"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand All @@ -24,8 +25,7 @@ clap = { version = "4.4.18", features = ["derive", "wrap_help"] }
clap_complete = "4.4.9"
indoc = "2.0.4"
# this is a dev-dependency but needed in `system_test` bin
insta = "1.34.0"
lazy_static = "1.4.0"
expect-test = "1.4.1"
rand = "0.8.5"
regex = "1.10.3"
reqwest = { version = "0.11.24", features = ["blocking"] }
Expand All @@ -42,10 +42,11 @@ wildmatch = "2.3.0"

[dev-dependencies]

# See https://docs.rs/insta/latest/insta/#optional-faster-runs
[profile.dev.package.insta]
opt-level = 3

# See https://docs.rs/insta/latest/insta/#optional-faster-runs
[profile.dev.package.similar]
opt-level = 3
[lints.clippy]
explicit_into_iter_loop = "warn"
explicit_iter_loop = "warn"
if_then_some_else_none = "warn"
implicit_clone = "warn"
redundant_else = "warn"
try_err = "warn"
unreadable_literal = "warn"
13 changes: 7 additions & 6 deletions src/apt.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use lazy_static::lazy_static;
use regex::{Regex, RegexBuilder};
use std::str::FromStr;
use std::sync::OnceLock;

use crate::command_ext::Command;
use crate::somehow::{somehow as anyhow, warn, Context, Result};
Expand Down Expand Up @@ -54,15 +54,16 @@ pub fn simulate_satisfy(deps: &[&str]) -> Result<Summary> {
let stdout = String::from_utf8(output.stdout)
.context("failed to read `apt-get satisfy --dry-run ...` output")?;

lazy_static! {
static ref RE: Regex = RegexBuilder::new(
static RE: OnceLock<Regex> = OnceLock::new();
let re = RE.get_or_init(||
RegexBuilder::new(
r#"^([0-9]+) upgraded, ([0-9]+) newly installed, ([0-9]+) to remove and ([0-9]+) not upgraded.$"#
)
.multi_line(true)
.build()
.unwrap();
}
match RE.captures(&stdout) {
.unwrap());

match re.captures(&stdout) {
Some(caps) => {
let count = |i| usize::from_str(caps.get(i).unwrap().as_str()).unwrap();
Ok(Summary {
Expand Down
10 changes: 0 additions & 10 deletions src/bin/gen_github_yaml.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
#![warn(
clippy::explicit_into_iter_loop,
clippy::explicit_iter_loop,
clippy::if_then_some_else_none,
clippy::implicit_clone,
clippy::redundant_else,
clippy::try_err,
clippy::unreadable_literal
)]

//! This program generates `.github/workflows/main.yaml`, used by GitHub
//! Actions. This program is a development time utility that is part of the
//! Cubicle project.
Expand Down
26 changes: 9 additions & 17 deletions src/bin/system_test/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use cubicle::{
Cubicle, EnvironmentName, FullPackageName, ListFormat, ListPackagesFormat, Quiet,
ShouldPackageUpdate, UpdatePackagesConditions,
};
use insta::assert_snapshot;
use expect_test::expect;
use std::collections::BTreeSet;
use std::path::{Path, PathBuf};
use std::str::FromStr;
Expand Down Expand Up @@ -51,10 +51,8 @@ fn test_package_not_found_errors(cub: &Cubicle, test_env: &EnvironmentName) -> R
let err = cub
.new_environment(test_env, Some(&not_exist))
.expect_err("should not be able to use does-not-exist package in `cub new`");
assert_snapshot!(
err.debug_without_backtrace(),
@r###"could not find package definition for "does-not-exist""###
);
expect![[r#"could not find package definition for "does-not-exist""#]]
.assert_eq(&err.debug_without_backtrace());

let envs = cub.get_environment_names()?;
assert!(
Expand All @@ -66,10 +64,8 @@ fn test_package_not_found_errors(cub: &Cubicle, test_env: &EnvironmentName) -> R
let err = cub
.create_enter_tmp_environment(Some(&not_exist))
.expect_err("should not be able to use does-not-exist package in `cub tmp`");
assert_snapshot!(
err.debug_without_backtrace(),
@r###"could not find package definition for "does-not-exist""###
);
expect![[r#"could not find package definition for "does-not-exist""#]]
.assert_eq(&err.debug_without_backtrace());
let new_envs = cub
.get_environment_names()?
.difference(&envs)
Expand All @@ -86,10 +82,8 @@ fn test_package_not_found_errors(cub: &Cubicle, test_env: &EnvironmentName) -> R
let err = cub
.reset_environment(test_env, Some(&not_exist))
.expect_err("should not be able to use does-not-exist package in `cub reset`");
assert_snapshot!(
err.debug_without_backtrace(),
@r###"could not find package definition for "does-not-exist""###
);
expect![[r#"could not find package definition for "does-not-exist""#]]
.assert_eq(&err.debug_without_backtrace());
cub.exec_environment(test_env, &[String::from("cat"), String::from("../foo")])
.context("file `../foo` should still exist")?;

Expand All @@ -104,10 +98,8 @@ fn test_package_not_found_errors(cub: &Cubicle, test_env: &EnvironmentName) -> R
},
)
.expect_err("should not be able to use does-not-exist package in `cub tmp`");
assert_snapshot!(
err.debug_without_backtrace(),
@r###"could not find package definition for "does-not-exist""###
);
expect![[r#"could not find package definition for "does-not-exist""#]]
.assert_eq(&err.debug_without_backtrace());

Ok(())
}
Expand Down
Loading

0 comments on commit 69268a8

Please sign in to comment.