Skip to content

Commit 83bd676

Browse files
authored
Merge pull request #15 from Javran/resolver
Implement stack resolver override for Haskell.
2 parents 53df178 + 5b5b11b commit 83bd676

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ The usual workflow is as such:
9696
* When done for the day, you may run `xr clean` in order to remove all
9797
downloaded exercise submissions.
9898

99+
## Track-specific settings
100+
101+
### Haskell
102+
103+
You can optionally override a student iteration's resolver by setting
104+
`XR_HASKELL_STACK_RESOLVER` to a valid resolver version, for example
105+
`XR_HASKELL_STACK_RESOLVER=lts-16.21 xr t`.
99106
100107
## Contributing
101108

tracks/haskell.sh

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,34 @@
1+
function _override_stack_resolver() {
2+
if [[ -z "$XR_HASKELL_STACK_RESOLVER" ]]; then
3+
return
4+
fi
5+
6+
# See https://docs.haskellstack.org/en/stable/pantry/#snapshot-location for
7+
# the resolver syntax. For the purpose of running exercises, it's reasonable
8+
# just to allow LTS and nightly.
9+
if ! [[ "$XR_HASKELL_STACK_RESOLVER" =~ ^(lts-[0-9\.]+|nightly-[0-9-]+)$ ]]; then
10+
echo Skipped resolver override as $XR_HASKELL_STACK_RESOLVER is not allowed.
11+
return
12+
fi
13+
14+
if ! stack --resolver="$XR_HASKELL_STACK_RESOLVER" eval '()' 2>&1 >/dev/null; then
15+
echo Skipped resolver override as stack cannot recognize $XR_HASKELL_STACK_RESOLVER.
16+
return
17+
fi
18+
19+
echo Overriding resolver to $XR_HASKELL_STACK_RESOLVER.
20+
sed -i 's/resolver: .*/resolver: '"$XR_HASKELL_STACK_RESOLVER"'/' stack.yaml
21+
}
22+
123
# Runs all the available tests.
224
function _run_tests() {
3-
stack test -Wall --trace \
25+
_override_stack_resolver \
26+
&& stack test --ghc-options -Wall \
427
&& hlint .
528
}
629

730
# Just runs any available benchmark, importing still needs to be added.
831
function _run_benches() {
9-
stack bench -Wall --no-run-tests
32+
_override_stack_resolver \
33+
&& stack bench --ghc-options -Wall --no-run-tests
1034
}

0 commit comments

Comments
 (0)