Skip to content

Commit 802b46c

Browse files
committed
Add tests to ensure the Stan plugin detects a module's language extensions
Includes test cases for both `LANGUAGE` pragmas and extensions enabled in a project's `.cabal` file.
1 parent 4e95308 commit 802b46c

File tree

5 files changed

+42
-0
lines changed

5 files changed

+42
-0
lines changed

plugins/hls-stan-plugin/test/Main.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ tests =
4040
diags <- waitForDiagnosticsFromSource doc "stan"
4141
liftIO $ length diags @?= 0
4242
return ()
43+
, testCase "respects LANGUAGE pragmas in the source file" $
44+
runStanSession "" $ do
45+
doc <- openDoc "extension-tests/language-pragma/LanguagePragmaTest.hs" "haskell"
46+
diags <- waitForDiagnosticsFromSource doc "stan"
47+
liftIO $ length diags @?= 0
48+
return ()
49+
, testCase "respects language extensions defined in the .cabal file" $
50+
runStanSession "" $ do
51+
doc <- openDoc "extension-tests/cabal-file/CabalFileTest.hs" "haskell"
52+
diags <- waitForDiagnosticsFromSource doc "stan"
53+
liftIO $ length diags @?= 0
54+
return ()
4355
]
4456

4557
testDir :: FilePath
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module CabalFileTest () where
2+
3+
-- With `StrictData` enabled in the `.cabal` file, Stan shouldn't complain here:
4+
data A = A Int Int
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
cabal-version: 3.0
2+
name: cabal-file-test
3+
version: 0.0.0.0
4+
5+
library
6+
exposed-modules: CabalFileTest
7+
hs-source-dirs: extension-tests/cabal-file
8+
-- Specifically, we're testing that Stan respects the following extension definition:
9+
default-extensions: StrictData
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{-# LANGUAGE StrictData #-}
2+
3+
module LanguagePragmaTest () where
4+
5+
-- With the above `StrictData` language pragma, Stan shouldn't complain here:
6+
data A = A Int Int
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
cabal-version: 3.0
2+
name: language-pragma-test
3+
version: 0.0.0.0
4+
5+
-- Without at least a minimal valid `.cabal` file, Stan won't bother building its
6+
-- map of language extensions. This means it also won't detect LANGUAGE pragmas
7+
-- without this file.
8+
9+
library
10+
exposed-modules: LanguagePragmaTest
11+
hs-source-dirs: extension-tests/language-pragma

0 commit comments

Comments
 (0)