Skip to content

Commit

Permalink
Disable line wrapping during scenario tests (#784)
Browse files Browse the repository at this point in the history
Adds support for a `PUFFIN_NO_WRAP` environment variable which disables
line wrapping in `miette` output.

We set this variable in the scenario tests to improve the readability of
snapshots.

I contributed the ability to disable line wrapping upstream at
zkat/miette#328
  • Loading branch information
zanieb committed Jan 4, 2024
1 parent d7c9b15 commit 5e04a95
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 59 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ indicatif = { version = "0.17.7" }
indoc = { version = "2.0.4" }
itertools = { version = "0.11.0" }
mailparse = { version = "0.14.0" }
# For additional textwrap options: https://github.com/zkat/miette/pull/321
miette = { git = "https://github.com/zkat/miette.git", rev = "fd77257cee0f5d03aa7dccb4ba8cbaa40c1a88c6" }
# For additional textwrap options: https://github.com/zkat/miette/pull/321, https://github.com/zkat/miette/pull/328
miette = { git = "https://github.com/zkat/miette.git", rev = "b0744462adbbfbb6d845f382db36be883c7f3c45" }
once_cell = { version = "1.18.0" }
petgraph = { version = "0.6.4" }
platform-info = { version = "2.0.2" }
Expand Down
1 change: 1 addition & 0 deletions crates/puffin-cli/src/commands/pip_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ pub(crate) async fn pip_compile(
.break_words(false)
.word_separator(textwrap::WordSeparator::AsciiSpace)
.word_splitter(textwrap::WordSplitter::NoHyphenation)
.wrap_lines(env::var("PUFFIN_NO_WRAP").map(|_| false).unwrap_or(true))
.build(),
)
}))?;
Expand Down
2 changes: 2 additions & 0 deletions crates/puffin-cli/src/commands/pip_install.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::env;
use std::fmt::Write;
use std::path::Path;

Expand Down Expand Up @@ -58,6 +59,7 @@ pub(crate) async fn pip_install(
.break_words(false)
.word_separator(textwrap::WordSeparator::AsciiSpace)
.word_splitter(textwrap::WordSplitter::NoHyphenation)
.wrap_lines(env::var("PUFFIN_NO_WRAP").map(|_| false).unwrap_or(true))
.build(),
)
}))?;
Expand Down
72 changes: 17 additions & 55 deletions crates/puffin-cli/tests/pip_install_scenarios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ fn requires_package_does_not_exist() -> Result<()> {
.arg("--cache-dir")
.arg(cache_dir.path())
.env("VIRTUAL_ENV", venv.as_os_str())
.env("PUFFIN_NO_WRAP", "1")
.current_dir(&temp_dir), @r###"
success: false
exit_code: 2
Expand Down Expand Up @@ -87,18 +88,15 @@ fn requires_exact_version_does_not_exist() -> Result<()> {
.arg("--cache-dir")
.arg(cache_dir.path())
.env("VIRTUAL_ENV", venv.as_os_str())
.env("PUFFIN_NO_WRAP", "1")
.current_dir(&temp_dir), @r###"
success: false
exit_code: 1
----- stdout -----
----- stderr -----
× No solution found when resolving dependencies:
╰─▶ Because there is no version of
a
available matching ==2.0.0 and root depends on
a==2.0.0, version solving
failed.
╰─▶ Because there is no version of a available matching ==2.0.0 and root depends on a==2.0.0, version solving failed.
"###);
});

Expand Down Expand Up @@ -137,18 +135,15 @@ fn requires_greater_version_does_not_exist() -> Result<()> {
.arg("--cache-dir")
.arg(cache_dir.path())
.env("VIRTUAL_ENV", venv.as_os_str())
.env("PUFFIN_NO_WRAP", "1")
.current_dir(&temp_dir), @r###"
success: false
exit_code: 1
----- stdout -----
----- stderr -----
× No solution found when resolving dependencies:
╰─▶ Because there is no version of
a
available matching >1.0.0 and root depends on
a>1.0.0, version
solving failed.
╰─▶ Because there is no version of a available matching >1.0.0 and root depends on a>1.0.0, version solving failed.
"###);
});

Expand Down Expand Up @@ -188,18 +183,15 @@ fn requires_less_version_does_not_exist() -> Result<()> {
.arg("--cache-dir")
.arg(cache_dir.path())
.env("VIRTUAL_ENV", venv.as_os_str())
.env("PUFFIN_NO_WRAP", "1")
.current_dir(&temp_dir), @r###"
success: false
exit_code: 1
----- stdout -----
----- stderr -----
× No solution found when resolving dependencies:
╰─▶ Because there is no version of
a
available matching <2.0.0 and root depends on
a<2.0.0, version solving
failed.
╰─▶ Because there is no version of a available matching <2.0.0 and root depends on a<2.0.0, version solving failed.
"###);
});

Expand Down Expand Up @@ -239,6 +231,7 @@ fn transitive_requires_package_does_not_exist() -> Result<()> {
.arg("--cache-dir")
.arg(cache_dir.path())
.env("VIRTUAL_ENV", venv.as_os_str())
.env("PUFFIN_NO_WRAP", "1")
.current_dir(&temp_dir), @r###"
success: false
exit_code: 2
Expand Down Expand Up @@ -287,17 +280,15 @@ fn requires_direct_incompatible_versions() -> Result<()> {
.arg("--cache-dir")
.arg(cache_dir.path())
.env("VIRTUAL_ENV", venv.as_os_str())
.env("PUFFIN_NO_WRAP", "1")
.current_dir(&temp_dir), @r###"
success: false
exit_code: 1
----- stdout -----
----- stderr -----
× No solution found when resolving dependencies:
╰─▶ root dependencies are unusable: Conflicting versions
for `a`:
`a==1.0.0` does not
intersect with `a==2.0.0`
╰─▶ root dependencies are unusable: Conflicting versions for `a`: `a==1.0.0` does not intersect with `a==2.0.0`
"###);
});

Expand Down Expand Up @@ -346,27 +337,16 @@ fn requires_transitive_incompatible_with_root_version() -> Result<()> {
.arg("--cache-dir")
.arg(cache_dir.path())
.env("VIRTUAL_ENV", venv.as_os_str())
.env("PUFFIN_NO_WRAP", "1")
.current_dir(&temp_dir), @r###"
success: false
exit_code: 1
----- stdout -----
----- stderr -----
× No solution found when resolving dependencies:
╰─▶ Because
a==1.0.0
depends on
b==2.0.0
and there is no version of
a
available matching <1.0.0 | >1.0.0,
a depends on
b==2.0.0.
And because root depends on
b==1.0.0
and root depends on
a, version
solving failed.
╰─▶ Because a==1.0.0 depends on b==2.0.0 and there is no version of a available matching <1.0.0 | >1.0.0, a depends on b==2.0.0.
And because root depends on b==1.0.0 and root depends on a, version solving failed.
"###);
});

Expand Down Expand Up @@ -419,35 +399,17 @@ fn requires_transitive_incompatible_with_transitive() -> Result<()> {
.arg("--cache-dir")
.arg(cache_dir.path())
.env("VIRTUAL_ENV", venv.as_os_str())
.env("PUFFIN_NO_WRAP", "1")
.current_dir(&temp_dir), @r###"
success: false
exit_code: 1
----- stdout -----
----- stderr -----
× No solution found when resolving dependencies:
╰─▶ Because there is no version of
a
available matching <1.0.0 | >1.0.0 and
a==1.0.0
depends on
c==1.0.0,
a depends on
c==1.0.0.
And because
b==1.0.0
depends on
c==2.0.0
and there is no version of
b
available matching <1.0.0 | >1.0.0,
a *,
b * are
incompatible.
And because root depends on
a and root
depends on b,
version solving failed.
╰─▶ Because there is no version of a available matching <1.0.0 | >1.0.0 and a==1.0.0 depends on c==1.0.0, a depends on c==1.0.0.
And because b==1.0.0 depends on c==2.0.0 and there is no version of b available matching <1.0.0 | >1.0.0, a *, b * are incompatible.
And because root depends on a and root depends on b, version solving failed.
"###);
});

Expand Down
1 change: 1 addition & 0 deletions scripts/scenarios/template.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ fn {{normalized_name}}() -> Result<()> {
.arg("--cache-dir")
.arg(cache_dir.path())
.env("VIRTUAL_ENV", venv.as_os_str())
.env("PUFFIN_NO_WRAP", "1")
.current_dir(&temp_dir), @r###"<snapshot>
"###);
});
Expand Down

0 comments on commit 5e04a95

Please sign in to comment.