Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local cargo test broken if ~/.config/starship.toml has add_newline = false #5077

Closed
domsleee opened this issue Apr 8, 2023 · 2 comments
Closed
Labels
🐛 bug Something isn't working as expected.

Comments

@domsleee
Copy link
Contributor

domsleee commented Apr 8, 2023

Current Behavior

cargo test fails (6 tests) if add_newline = false is in ~/.config/starship.toml, and STARSHIP_CONFIG is clear.
The tests rely on the default config, i.e. add_newline = true

Output:

thread 'print::test::custom_subset' panicked at 'assertion failed: `(left == right)`
  left: `"\nb"`,
 right: `"b"`', src\print.rs:758:9
...
failures:
    print::test::custom_expands
    print::test::custom_missing
    print::test::custom_mixed
    print::test::custom_subset
    print::test::env_expands
    print::test::env_mixed

Expected behaviour

The tests shouldn't depend on the STARSHIP_CONFIG environment variable, nor should they depend on the contents of ~/.config/starship.toml

Possible Solution

Similar to how it is done in setup_config in configure.rs#setup_config in #5001
This is simple to fix after #5001 goes through, relevant changes in that PR around Context::new, see #5001 (comment):

  • During testing, STARSHIP_CONFIG is read from the env hashmap
  • During testing, if HOME is in the env hashmap, it used instead of utils::home_dir()

Environment

  • Starship version: 1.13.1
  • pwsh version: PowerShell 7.3.3
  • Operating system: Windows 10.0.19044
  • Terminal emulator:
  • Git Commit Hash:
  • Branch/Tag: master
  • Rust Version: rustc 1.70.0-nightly (28a29282f 2023-04-06)
  • Rust channel: nightly-x86_64-pc-windows-msvc release
  • Build Time: 2023-04-07 14:29:12 +10:00

Relevant Shell Configuration

add_newline = false
@domsleee domsleee added the 🐛 bug Something isn't working as expected. label Apr 8, 2023
@davidkna
Copy link
Member

davidkna commented Apr 8, 2023

I think the

let renderer = ModuleRenderer::new("status")
.config(toml::toml! {
format = "$fill$status"
[status]
style = "fg:white bg:red bold"
pipestatus = true
pipestatus_segment_format = "[$status](bg:blue fg:yellow)"
disabled = false
})
.status(main_exit_code)
.pipestatus(pipe_exit_code)
.width(100);
let context = crate::modules::Context::from(renderer);
approach would also work.

Edit: Actually, a .config() method on Context matching the ModuleRenderer feature would be nice to have.

@domsleee
Copy link
Contributor Author

These tests are fixed by #5079, so I'll close this issue
Thanks @marcybelardo & @davidkna 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working as expected.
Projects
None yet
Development

No branches or pull requests

2 participants