mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-11-28 15:56:28 +00:00
feat: Add cabal and hpack detection for the haskell module (#915)
This commit is contained in:
parent
2509a79176
commit
bc600e4321
@ -7,10 +7,13 @@ use crate::utils;
|
|||||||
///
|
///
|
||||||
/// Will display the Haskell version if any of the following criteria are met:
|
/// Will display the Haskell version if any of the following criteria are met:
|
||||||
/// - Current directory contains a `stack.yaml` file
|
/// - Current directory contains a `stack.yaml` file
|
||||||
|
/// - Current directory contains a `.cabal` file
|
||||||
|
/// - Current directory contains a `package.yaml` file
|
||||||
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||||
let is_haskell_project = context
|
let is_haskell_project = context
|
||||||
.try_begin_scan()?
|
.try_begin_scan()?
|
||||||
.set_files(&["stack.yaml"])
|
.set_files(&["package.yaml", "stack.yaml", "package.yml", "stack.yml"])
|
||||||
|
.set_extensions(&["cabal"])
|
||||||
.is_match();
|
.is_match();
|
||||||
|
|
||||||
if !is_haskell_project {
|
if !is_haskell_project {
|
||||||
@ -51,6 +54,25 @@ mod tests {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn folder_with_hpack_file() -> io::Result<()> {
|
||||||
|
let dir = tempfile::tempdir()?;
|
||||||
|
File::create(dir.path().join("package.yaml"))?.sync_all()?;
|
||||||
|
let actual = render_module("haskell", dir.path());
|
||||||
|
let expected = Some(format!("via {} ", Color::Red.bold().paint("λ v8.6.5")));
|
||||||
|
assert_eq!(expected, actual);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
#[test]
|
||||||
|
fn folder_with_cabal_file() -> io::Result<()> {
|
||||||
|
let dir = tempfile::tempdir()?;
|
||||||
|
File::create(dir.path().join("test.cabal"))?.sync_all()?;
|
||||||
|
let actual = render_module("haskell", dir.path());
|
||||||
|
let expected = Some(format!("via {} ", Color::Red.bold().paint("λ v8.6.5")));
|
||||||
|
assert_eq!(expected, actual);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn folder_with_stack_yaml() -> io::Result<()> {
|
fn folder_with_stack_yaml() -> io::Result<()> {
|
||||||
let dir = tempfile::tempdir()?;
|
let dir = tempfile::tempdir()?;
|
||||||
|
Loading…
Reference in New Issue
Block a user