From bc600e4321b525ba5b4e32603b37b18cbc3ea576 Mon Sep 17 00:00:00 2001 From: Brett Mandler Date: Thu, 6 Feb 2020 19:29:57 -0500 Subject: [PATCH] feat: Add cabal and hpack detection for the haskell module (#915) --- src/modules/haskell.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/modules/haskell.rs b/src/modules/haskell.rs index 93b577d0..7324cc9c 100644 --- a/src/modules/haskell.rs +++ b/src/modules/haskell.rs @@ -7,10 +7,13 @@ use crate::utils; /// /// Will display the Haskell version if any of the following criteria are met: /// - 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> { let is_haskell_project = context .try_begin_scan()? - .set_files(&["stack.yaml"]) + .set_files(&["package.yaml", "stack.yaml", "package.yml", "stack.yml"]) + .set_extensions(&["cabal"]) .is_match(); if !is_haskell_project { @@ -51,6 +54,25 @@ mod tests { 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] fn folder_with_stack_yaml() -> io::Result<()> { let dir = tempfile::tempdir()?;