Skip to content

Commit b44a0bd

Browse files
authored
[ fix #5302 ] make 'cabal test' work for part of the test-suite (#5536)
* [ fix #5302 ] make 'cabal test' work for part of the test-suite 'cabal test' will run only the tests defined by 'agda-tests' * [ #5302 ] CI: work around haskell/cabal#7577 An attempt to get `cabal test` to run after *installing* Agda rather than just building it. * [ #5302 ] disable latex-tests for `cabal test` Mainly for CI, so that we do not have to install LaTeX. * [ #5302 ] disable compiler-stdlib tests for `cabal test` Do not work out of the box, need installation of the stdlib (for `Everything.agda`). * [ #5302 ] CI: `cabal test` also on macOS and Windows * [ #5302 ] `cabal test` macOS: work around haskell/cabal#7209 Cabal removes lower-case vowels from package names on macOS, see haskell/cabal#7209. Thus Agda might be just Agd in error messages reporting source locations. * [ #5302 ] giving up on `cabal test` under Windows The testsuite fails but does not display diffs. tasty-silver might not yet be portable, see agda/tasty-silver#16 * [ #5302 ] fix the alert printed by `cabal test` Correct reference is `v1-install` in `cabal v1-install --run-tests`. * PR #5536: final polishing
1 parent 6e4fb9d commit b44a0bd

7 files changed

Lines changed: 194 additions & 27 deletions

File tree

‎.github/workflows/cabal-test.yml‎

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
name: cabal-test
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- ci-*
8+
- release*
9+
paths:
10+
- '.github/workflows/cabal-test.yml'
11+
- 'Agda.cabal'
12+
- 'Setup.hs'
13+
- 'src/full/**'
14+
- 'src/main/**'
15+
- 'test/**.hs'
16+
pull_request:
17+
paths:
18+
- '.github/workflows/cabal-test.yml'
19+
- 'Agda.cabal'
20+
- 'Setup.hs'
21+
- 'src/full/**'
22+
- 'src/main/**'
23+
- 'test/**.hs'
24+
25+
defaults:
26+
run:
27+
shell: bash
28+
29+
jobs:
30+
auto-cancel:
31+
if: |
32+
!contains(github.event.head_commit.message, '[skip ci]')
33+
&& !contains(github.event.head_commit.message, '[ci skip]')
34+
&& !contains(github.event.head_commit.message, '[github skip]')
35+
&& !contains(github.event.head_commit.message, '[skip github]')
36+
runs-on: Ubuntu-latest # Required, but it can be anything here.
37+
38+
steps:
39+
- uses: styfle/[email protected]
40+
with:
41+
access_token: ${{ github.token }}
42+
43+
cabal:
44+
needs: auto-cancel
45+
46+
runs-on: ${{ matrix.os }}
47+
strategy:
48+
fail-fast: false
49+
matrix:
50+
os:
51+
- ubuntu-latest
52+
- macos-latest
53+
# - windows-latest
54+
## Andreas, 2021-08-28, giving up on running the test-suite under Windows.
55+
## There is e.g. https://github.com/phile314/tasty-silver/issues/16
56+
## that may be responsible that diffs are not shown,
57+
## and that prevents me from running the test-suite interactively.
58+
ghc-ver: ['latest']
59+
cabal-ver: ['latest']
60+
61+
steps:
62+
- uses: actions/checkout@v2
63+
with:
64+
submodules: recursive
65+
66+
- uses: haskell/actions/setup@v1
67+
id: setup-haskell
68+
with:
69+
ghc-version: ${{ matrix.ghc-ver }}
70+
cabal-version: ${{ matrix.cabal-ver }}
71+
72+
- name: Configure the build plan
73+
run: |
74+
cabal update
75+
cabal configure -O1 --enable-tests
76+
77+
- uses: actions/cache@v2
78+
name: Cache dependencies
79+
id: cache
80+
with:
81+
path: |
82+
${{ steps.setup-haskell.outputs.cabal-store }}
83+
# The file `plan.json` contains the build information.
84+
key: ${{ runner.os }}-cabal-01-${{ matrix.ghc-ver }}-${{ matrix.cabal-ver }}-${{ hashFiles('**/plan.json') }}
85+
86+
- name: Install dependencies
87+
if: ${{ !steps.cache.outputs.cache-hit }}
88+
run: |
89+
cabal build --only-dependencies --enable-tests
90+
91+
# Andreas, 2021-09-02:
92+
# Installing Agda, instead of just building it, is to work around
93+
# https://github.com/haskell/cabal/issues/7577
94+
# which hides the build executable from the tests when there is
95+
# a Custom cabal setup (atm works only for Simple setup).
96+
# Once haskell/cabal#7577 is fixed, we can dispose of this workaround.
97+
- name: Install Agda
98+
run: |
99+
mkdir -p ${HOME}/bin
100+
cabal install --installdir=${HOME}/bin
101+
# bin instead of .cabal/bin as this might be more portable (Windows)
102+
103+
- name: Build and test Agda
104+
run: |
105+
export PATH=${HOME}/bin:${PATH}
106+
cabal test

‎Agda.cabal‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,11 @@ test-suite agda-tests
915915
, UserManual.Tests
916916
, Utils
917917

918+
-- Andreas, 2021-08-26, see https://github.com/haskell/cabal/issues/7577
919+
-- Since 'agda-tests' wants to call 'agda', we have to add it here,
920+
-- should we want to run 'cabal test'.
921+
build-tool-depends: Agda:agda
922+
918923
build-depends: Agda
919924
, array >= 0.5.1.1 && < 0.6
920925
, base >= 4.9.0.0 && < 4.16

‎test/Compiler/Tests.hs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ disabledTests =
106106
]
107107
where disable = RFInclude
108108

109+
-- | Filtering out compiler tests using the Agda standard library.
110+
111+
stdlibTestFilter :: [RegexFilter]
112+
stdlibTestFilter =
113+
[ disable "Compiler/.*/with-stdlib"
114+
]
115+
where disable = RFInclude
116+
109117
tests :: IO TestTree
110118
tests = do
111119
nodeBin <- findExecutable "node"

‎test/LaTeXAndHTML/Tests.hs‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,19 @@ userManualTestDir = testDirPrefix "user-manual"
5252
disabledTests :: [RegexFilter]
5353
disabledTests = []
5454

55+
-- | Filtering out tests using Text.ICU.
56+
57+
icuTests :: [RegexFilter]
58+
icuTests = [ disable "LaTeXAndHTML/.*/Grapheme.*" ]
59+
where disable = RFInclude
60+
61+
-- | Filtering out tests using latex.
62+
63+
latexTests :: [RegexFilter]
64+
latexTests = [ disable "LaTeXAndHTML/.*LaTeX/.*" ]
65+
where disable = RFInclude
66+
67+
5568
-- | Test group with subgroups
5669
--
5770
-- @

‎test/Main.hs‎

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
{-# LANGUAGE DoAndIfThenElse #-}
2-
31
module Main where
42

53
import qualified Compiler.Tests as COMPILER
@@ -22,21 +20,24 @@ import Utils
2220

2321
main :: IO ()
2422
main = do
25-
agdaBin <- doesEnvContain "AGDA_BIN"
26-
if agdaBin
27-
then
28-
tests >>= TM.defaultMain1 disabledTests
29-
else do
23+
doesEnvContain "AGDA_BIN" >>= \case
24+
True -> TM.defaultMain1 disabledTests =<< tests
25+
False -> do
3026
putStrLn $ unlines
31-
[ "The AGDA_BIN environment variable is not set. Do not execute"
32-
, "these tests directly using \"cabal test\" or \"cabal install --run-tests\", instead"
33-
, "use the Makefile."
34-
, "Are you maybe using the Makefile together with an old cabal-install version?"
35-
, "Versions of cabal-install before 1.20.0.0 have a bug and will trigger this error."
36-
, "The Makefile requires cabal-install 1.20.0.0 or later to work properly."
37-
, "See also Issue #1489 and #1490."
38-
]
39-
exitWith (ExitFailure 1)
27+
[ "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
28+
, "@ The AGDA_BIN environment variable is not set. @"
29+
, "@ Maybe you are running 'cabal test' or 'cabal v1-install --runtests'? @"
30+
, "@ This will only run parts of the Agda test-suite. @"
31+
, "@ The preferred way of running the tests is via the Makefile ('make test'). @"
32+
, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
33+
]
34+
agdaBin <- getAgdaBin
35+
doesCommandExist agdaBin >>= \case
36+
True ->
37+
TM.defaultMain1 cabalDisabledTests =<< tests
38+
False -> do
39+
putStrLn $ unwords ["Could not find executable", agdaBin ]
40+
exitFailure
4041

4142
-- | All tests covered by the tasty testsuite.
4243
tests :: IO TestTree
@@ -45,13 +46,13 @@ tests = do
4546
sequence $
4647
-- N.B.: This list is written using (:) so that lines can be swapped easily:
4748
-- (The number denotes the order of the Makefile as of 2021-08-25.)
48-
{- 5 -} sg LATEXHTML.tests :
49-
{- 3 -} sg BUGS.tests :
5049
{- 1 -} sg SUCCEED.tests :
51-
{- 6 -} pu INTERNAL.tests :
52-
{- 9 -} sg USERMANUAL.tests :
53-
{- 4 -} pu INTERACTIVE.tests :
5450
{- 2 -} sg FAIL.tests :
51+
{- 3 -} sg BUGS.tests :
52+
{- 4 -} pu INTERACTIVE.tests :
53+
{- 9 -} sg USERMANUAL.tests :
54+
{- 5 -} sg LATEXHTML.tests :
55+
{- 6 -} pu INTERNAL.tests :
5556
{- 7 -} sg COMPILER.tests :
5657
{- 8 -} sg LIBSUCCEED.tests :
5758
[]
@@ -62,6 +63,21 @@ tests = do
6263
-- sg m = (:[]) <$> m
6364
-- pu x = pure [x]
6465

66+
-- | Filtering out tests for @cabal test@.
67+
68+
cabalDisabledTests :: [RegexFilter]
69+
cabalDisabledTests = concat
70+
[ disabledTests
71+
, makefileDependentTests
72+
, LATEXHTML.latexTests
73+
, LATEXHTML.icuTests
74+
, COMPILER.stdlibTestFilter
75+
]
76+
77+
-- | Some tests get extra setup through the @Makefile@.
78+
79+
makefileDependentTests :: [RegexFilter]
80+
makefileDependentTests = SUCCEED.makefileDependentTests
6581

6682
disabledTests :: [RegexFilter]
6783
disabledTests = concat

‎test/Succeed/Tests.hs‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import Test.Tasty
1313
import Test.Tasty.Silver
1414
import Test.Tasty.Silver.Advanced
1515
(readFileMaybe, goldenTestIO1, GDiff (..), GShow (..))
16+
import Test.Tasty.Silver.Filter ( RegexFilter( RFInclude ) )
1617

1718
import System.Directory
1819
import System.Exit
@@ -34,9 +35,17 @@ tests = do
3435

3536
return $ testGroup "Succeed" tests'
3637
where
37-
-- Andreas, 2020-10-19, work around issue #4940:
38-
-- Put @ExecAgda@ last.
39-
reorder = uncurry (++) . List.partition (("ExecAgda" /=) . dropAgdaExtension)
38+
reorder = id
39+
-- -- Andreas, 2020-10-19, work around issue #4940:
40+
-- -- Put @ExecAgda@ last.
41+
-- reorder = uncurry (++) . List.partition (not . ("ExecAgda" `List.isInfixOf`))
42+
43+
-- | Tests that get special preparation from the Makefile.
44+
makefileDependentTests :: [RegexFilter]
45+
makefileDependentTests =
46+
[ disable "Succeed/ExecAgda"
47+
]
48+
where disable = RFInclude
4049

4150
data TestResult
4251
= TestSuccess

‎test/Utils.hs‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,7 @@ getEnvAgdaArgs :: IO AgdaArgs
135135
getEnvAgdaArgs = maybe [] words <$> getEnvVar "AGDA_ARGS"
136136

137137
getAgdaBin :: IO FilePath
138-
getAgdaBin = fromMaybeM err $ getEnvVar "AGDA_BIN"
139-
where
140-
err = fail "AGDA_BIN environment variable not set, aborting..."
138+
getAgdaBin = getProg "agda"
141139

142140
-- | Gets the program executable. If an environment variable
143141
-- YYY_BIN is defined (with yyy converted to upper case),
@@ -315,6 +313,18 @@ cleanOutput' pwd t = foldl (\ t' (rgx, n) -> replace rgx n t') t rgxs
315313
, ("\\\\", "/")
316314
, ("\\.hs(:[[:digit:]]+){2}", ".hs:«line»:«col»")
317315
, (T.pack Agda.Version.package, "«Agda-package»")
316+
-- Andreas, 2021-08-26. When run with 'cabal test',
317+
-- Agda.Version.package didn't match, so let's be generous:
318+
-- Andreas, 2021-09-02. The match failure could be triggered
319+
-- when we are running the *installed* version of Agda rather
320+
-- than the *built* one, see .github/workflows/cabal-test.yml.
321+
-- Maybe the match failures will disappear once we drop
322+
-- the workaround for haskell/cabal#7577.
323+
-- Andreas, 2021-08-28. To work around haskell/cabal#7209,
324+
-- "The Grinch stole all the vowels", we also have to
325+
-- recognize Agd (instead of Agda) as package name.
326+
-- See CI run: https://github.com/agda/agda/runs/3449775214?check_suite_focus=true
327+
, ("Agda?-[.0-9]+(-[[:alnum:]]+)?", "«Agda-package»")
318328
, ("[^ (]*lib.prim", "agda-default-include-path")
319329
, ("\xe2\x80\x9b|\xe2\x80\x99|\xe2\x80\x98|`", "'")
320330
]

0 commit comments

Comments
 (0)