Skip to content

Commit

Permalink
Add regression test for #169
Browse files Browse the repository at this point in the history
  • Loading branch information
FPtje committed Oct 22, 2023
1 parent 3677c2a commit 89c880f
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
3 changes: 2 additions & 1 deletion default.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ mkDerivation, aeson, base, bytestring, containers
, directory, deepseq, effectful, filemanip, filepath
, optparse-applicative, parsec, pretty, signal, lib, uu-parsinglib
, uuagc, uuagc-cabal, tasty, tasty-golden
, uuagc, uuagc-cabal, tasty, tasty-golden, tasty-hunit
}:
let
# Clean up the source of the derivation to prevent rebuilds
Expand Down Expand Up @@ -51,6 +51,7 @@ in mkDerivation {
uuagc-cabal
tasty
tasty-golden
tasty-hunit
];
executableHaskellDepends = [
aeson
Expand Down
14 changes: 14 additions & 0 deletions glualint.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,20 @@ test-suite golden

default-language: Haskell2010

test-suite linttest
type: exitcode-stdio-1.0
main-is: Spec.hs
hs-source-dirs: tests/linttest
build-depends:
, base
, bytestring
, glualint
, tasty >=1.4 && <2
, tasty-hunit >=0.10 && <0.12
, uu-parsinglib

default-language: Haskell2010

executable glualint
-- Disable the executable for ghcjs and older versions of ghc. The executable
-- uses functions only available in ghc 8+
Expand Down
46 changes: 46 additions & 0 deletions tests/linttest/Spec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import qualified Data.ByteString.Lazy as LBS
import qualified Data.ByteString.Lazy.Char8 as LBS8
import GLua.AG.Token (Region (..))
import qualified GLuaFixer.Interface as GLua
import GLuaFixer.LintMessage (
Issue (..),
LintMessage (..),
Severity (..),
)
import GLuaFixer.LintSettings (LintSettings, defaultLintSettings)
import Test.Tasty (TestTree, defaultMain, testGroup)
import Test.Tasty.HUnit (testCase, (@=?))
import Text.ParserCombinators.UU.BasicInstances (LineColPos (..))

main :: IO ()
main = defaultMain tests

tests :: TestTree
tests = testGroup "Unit tests" [testQuotedStringWarningPosition]

-- | Regression test for https://github.com/FPtje/GLuaFixer/issues/169
testQuotedStringWarningPosition :: TestTree
testQuotedStringWarningPosition =
testCase "Assert that the warning is thrown and in the right region" $
let
input = "bar = a or b\nfoo = \"\" and \"\" and \"dddd\" || \"[]\""
expectedRegion = Region (LineColPos 1 27 40) (LineColPos 1 29 42)
warning = SyntaxInconsistency "||" "or"
msg = LintMessage LintWarning expectedRegion warning testFilePath
in
lintString input @=? [msg]

-- | Helper to lint a string
lintString :: String -> [LintMessage]
lintString input =
let
settings = defaultLintSettings
in
case GLua.lex settings testFilePath input of
Left errs -> errs
Right mTokens -> case GLua.parse settings testFilePath mTokens of
Left errs -> errs
Right ast -> GLua.lexiconLint testFilePath settings mTokens <> GLua.astLint testFilePath settings ast

testFilePath :: String
testFilePath = "test input"

0 comments on commit 89c880f

Please sign in to comment.