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

feat: port Haskell module tests to integration test #913

Merged
merged 16 commits into from Feb 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 0 additions & 17 deletions .github/workflows/workflow.yml
Expand Up @@ -116,23 +116,6 @@ jobs:
toolchain: stable
override: true

# Install Stack at a fixed version (Linux & macOS version)
- name: Install Stack [-nix]
if: matrix.os != 'windows-latest'
uses: mstksg/setup-stack@v1

# Install Stack at a fixed version (Windows version), use Chocolatey
- name: Install Stack [-windows]
if: matrix.os == 'windows-latest'
uses: crazy-max/ghaction-chocolatey@v1
with:
args: install haskell-stack -y

- name: Install GHC version
env:
ARGS: --resolver nightly-2019-09-21
run: stack $ARGS ghc -- --numeric-version --no-install-ghc

# Install Golang at a fixed version
- uses: actions/setup-go@v1
with:
Expand Down
31 changes: 27 additions & 4 deletions src/modules/haskell.rs
Expand Up @@ -22,7 +22,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
&["ghc", "--", "--numeric-version", "--no-install-ghc"],
)?
.stdout;
let formatted_version = format_haskell_version(&haskell_version)?;
let formatted_version = Some(format!("v{}", haskell_version.trim()))?;

let mut module = context.new_module("haskell");
let config: HaskellConfig = HaskellConfig::try_load(module.config);
Expand All @@ -34,7 +34,30 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
Some(module)
}

fn format_haskell_version(haskell_version: &str) -> Option<String> {
let formatted_version = format!("v{}", haskell_version.trim());
Some(formatted_version)
#[cfg(test)]
mod tests {
use crate::modules::utils::test::render_module;
use ansi_term::Color;
use std::fs::File;
use std::io;
use tempfile;

#[test]
fn folder_without_stack_yaml() -> io::Result<()> {
let dir = tempfile::tempdir()?;
let actual = render_module("haskell", dir.path());
let expected = None;
assert_eq!(expected, actual);
Ok(())
}

#[test]
fn folder_with_stack_yaml() -> io::Result<()> {
let dir = tempfile::tempdir()?;
File::create(dir.path().join("stack.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(())
}
}
4 changes: 4 additions & 0 deletions src/utils.rs
Expand Up @@ -43,6 +43,10 @@ pub fn exec_cmd(cmd: &str, args: &[&str]) -> Option<CommandOutput> {
stdout: String::from("0.19.1"),
stderr: String::default(),
}),
"stack ghc -- --numeric-version --no-install-ghc" => Some(CommandOutput {
stdout: String::from("8.6.5"),
stderr: String::default(),
}),
"node --version" => Some(CommandOutput {
stdout: String::from("v12.0.0"),
stderr: String::default(),
Expand Down
71 changes: 0 additions & 71 deletions tests/testsuite/haskell.rs

This file was deleted.

1 change: 0 additions & 1 deletion tests/testsuite/main.rs
Expand Up @@ -12,7 +12,6 @@ mod git_commit;
mod git_state;
mod git_status;
mod golang;
mod haskell;
mod hg_branch;
mod hostname;
mod jobs;
Expand Down