Skip to content

Commit

Permalink
Update Haskell tester to use Stack
Browse files Browse the repository at this point in the history
  • Loading branch information
david-yz-liu committed Dec 21, 2023
1 parent 73cf25d commit 8babffd
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 9 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to this project will be documented here.
- Fix bug that prevented test results from being returned when a feedback file could not be found (#458)
- Add support for Python 3.11 and 3.12 (#467)
- Track test environment setup status and report errors when running tests if environment setup is in progress or raised an error (#468)
- Update Haskell tester to use [Stack](https://docs.haskellstack.org/en/stable/) to install dependencies (#469)

## [v2.3.1]
- Fix a bug that prevented test file from being copied from a zip file to another location on disk (#426)
Expand Down
25 changes: 22 additions & 3 deletions server/autotest_server/testers/haskell/haskell_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
from ..tester import Tester, Test, TestError
from ..specs import TestSpecs

STACK_OPTIONS = [
'--resolver=lts-14.27',
'--system-ghc',
'--allow-different-user'
]

class HaskellTest(Test):
def __init__(
Expand Down Expand Up @@ -104,11 +109,25 @@ def run_haskell_tests(self) -> Dict[str, List[Dict[str, Union[int, str]]]]:
haskell_lib = os.path.join(os.path.dirname(os.path.realpath(__file__)), "lib")
for test_file in self.specs["test_data", "script_files"]:
with tempfile.NamedTemporaryFile(dir=this_dir) as f:
cmd = ["tasty-discover", ".", "_", f.name] + self._test_run_flags(test_file)
cmd = [
"stack",
"exec",
*STACK_OPTIONS,
"--",
"tasty-discover",
".",
"_",
f.name,
*self._test_run_flags(test_file)
]
subprocess.run(cmd, stdout=subprocess.DEVNULL, universal_newlines=True, check=True)
with tempfile.NamedTemporaryFile(mode="w+", dir=this_dir) as sf:
cmd = ["runghc", "--", f"-i={haskell_lib}", f.name, f"--stats={sf.name}"]
subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE, universal_newlines=True)
cmd = ["stack", "runghc",
*STACK_OPTIONS,
"--",
f"-i={haskell_lib}", f.name, f"--stats={sf.name}"]
subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE, universal_newlines=True,
check=True)
results[test_file] = self._parse_test_results(csv.reader(sf))
return results

Expand Down
9 changes: 3 additions & 6 deletions server/autotest_server/testers/haskell/requirements.system
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#!/usr/bin/env bash

if ! dpkg -l ghc cabal-install &> /dev/null; then
if ! dpkg -l ghc cabal-install haskell-stack &> /dev/null; then
apt-get -y update
DEBIAN_FRONTEND=noninteractive apt-get install -y -o 'Dpkg::Options::=--force-confdef' -o 'Dpkg::Options::=--force-confold' ghc cabal-install
DEBIAN_FRONTEND=noninteractive apt-get install -y -o 'Dpkg::Options::=--force-confdef' -o 'Dpkg::Options::=--force-confold' ghc cabal-install haskell-stack
fi

# TODO: install these without cabal so they can be properly isolated/uninstalled
cabal update
ghc-pkg describe tasty-discover &>/dev/null || cabal install tasty-discover --global
ghc-pkg describe tasty-quickcheck &>/dev/null || cabal install tasty-quickcheck --global
stack update
16 changes: 16 additions & 0 deletions server/autotest_server/testers/haskell/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,23 @@
import subprocess


HASKELL_TEST_DEPS = [
"tasty-discover",
"tasty-quickcheck"
]

def create_environment(_settings, _env_dir, default_env_dir):
resolver = "lts-14.27"
cmd = [
"stack",
"build",
"--resolver",
resolver,
"--system-ghc",
*HASKELL_TEST_DEPS
]
subprocess.run(cmd, check=True)

return {"PYTHON": os.path.join(default_env_dir, "bin", "python3")}


Expand Down

0 comments on commit 8babffd

Please sign in to comment.