Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pre_commit/languages/haskell.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ def install_environment(
raise FatalError('Expected .cabal files or additional_dependencies')

bindir = os.path.join(envdir, 'bin')
storedir = os.path.join(envdir, 'store')
os.makedirs(bindir, exist_ok=True)
lang_base.setup_cmd(prefix, ('cabal', 'update'))
lang_base.setup_cmd(
prefix,
(
'cabal', 'install',
'cabal', '--store-dir', storedir, 'install',
'--install-method', 'copy',
'--installdir', bindir,
*pkgs,
Expand Down
31 changes: 31 additions & 0 deletions tests/languages/haskell_test.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,43 @@
from __future__ import annotations

from unittest import mock

import pytest

import pre_commit.constants as C
from pre_commit import lang_base
from pre_commit.errors import FatalError
from pre_commit.languages import haskell
from pre_commit.prefix import Prefix
from pre_commit.util import win_exe
from testing.language_helpers import run_language


def test_install_uses_env_local_store(tmp_path):
hook_dir = tmp_path.joinpath('hook dir')
hook_dir.mkdir()
hook_dir.joinpath('example.cabal').touch()
prefix = Prefix(str(hook_dir))
envdir = hook_dir.joinpath('hs_env-default')

with mock.patch.object(lang_base, 'setup_cmd') as setup_cmd:
haskell.install_environment(prefix, C.DEFAULT, ())

assert setup_cmd.call_args_list == [
mock.call(prefix, ('cabal', 'update')),
mock.call(
prefix,
(
'cabal', '--store-dir', str(envdir.joinpath('store')),
'install',
'--install-method', 'copy',
'--installdir', str(envdir.joinpath('bin')),
'example.cabal',
),
),
]


def test_run_example_executable(tmp_path):
example_cabal = '''\
cabal-version: 2.4
Expand Down Expand Up @@ -41,6 +71,7 @@ def test_run_example_executable(tmp_path):
def test_run_dep(tmp_path):
result = run_language(tmp_path, haskell, 'hello', deps=['hello'])
assert result == (0, b'Hello, World!\n')
assert tmp_path.joinpath('hs_env-default', 'store').is_dir()


def test_run_empty(tmp_path):
Expand Down
Loading