Permalink
Browse files

make -> cabal; MIT license; added dummy QuickCheck tests

  • Loading branch information...
temoto committed Nov 28, 2012
1 parent 68d2e3c commit 617688a64416da522a4745c7073bf277522031a7
Showing with 137 additions and 28 deletions.
  1. +1 −1 .gitignore
  2. +21 −0 LICENSE
  3. +0 −24 Makefile
  4. +7 −3 README.txt
  5. +2 −0 Setup.hs
  6. +49 −0 nginx-lint.cabal
  7. +57 −0 test/Main.hs
View
@@ -1,2 +1,2 @@
+dist/
*.hi
-nginxlint
View
21 LICENSE
@@ -0,0 +1,21 @@
+Copyright (c) 2012 Sergey Shepelev <temotor@gmail.com>
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files
+(the "Software"), to deal in the Software without restriction,
+including without limitation the rights to use, copy, modify, merge,
+publish, distribute, sublicense, and/or sell copies of the Software,
+and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
View
@@ -1,24 +0,0 @@
-# nginxlint make recipe
-
-# settings
-HC := ghc
-
-# Don't modify anything below without a reason.
-srcs := \
- NginxLint/Data.hs \
- NginxLint/Hint.hs \
- NginxLint/Main.hs \
- NginxLint/Parse.hs
-
-.PHONY: all clean test
-
-all: nginxlint
-
-clean:
- @rm -f nginxlint $(patsubst %.hs,%.hi,${srcs}) $(patsubst %.hs,%.o,${srcs})
-
-nginxlint: ${srcs}
- @$(HC) --make ${srcs} -o $@
-
-test: nginxlint
- @./nginxlint test.conf
View
@@ -12,12 +12,16 @@ Usage
nginxlint is written in Haskell, and so it requires GHC (or other Haskell compiler/interpreter).
-Simplest way to get started is run `make test`. This will try to build `nginxlint` binary using `ghc`
-compiler and run it with example config: test.conf.
+Simplest way to get started is run `cabal install`. This will try to build `nginx-lint` binary using
+available Haskell compiler.
+
+Run `nginx-lint test.conf` to see examples of hint this linter may give.
+
+For development, you may wish to run `cabal install --enable-tests`.
General usage:
- ./nginxlint FILE...
+ ./nginx-lint FILE...
TODO
View
@@ -0,0 +1,2 @@
+import Distribution.Simple
+main = defaultMain
View
@@ -0,0 +1,49 @@
+name: nginx-lint
+version: 0.1
+synopsis: Nginx config verification tool (linter).
+-- description:
+homepage: https://github.com/temoto/nginx-lint
+bug-reports: https://github.com/temoto/nginx-lint/issues
+license: MIT
+license-file: LICENSE
+author: Sergey Shepelev
+maintainer: temotor@gmail.com
+category: Web
+build-type: Simple
+cabal-version: >= 1.10
+extra-source-files: README.txt test.conf
+
+source-repository head
+ type: git
+ location: https://github.com/temoto/nginx-lint.git
+
+
+executable nginx-lint
+ default-language: Haskell2010
+ main-is: NginxLint/Main.hs
+ -- TODO: bisect compatible versions
+ build-depends: base (>= 4 && < 5),
+ parsec,
+ transformers,
+ uniplate
+
+ ghc-options: -Wall -O2 -fno-warn-missing-signatures
+
+
+test-suite nginx-lint-test
+ default-language: Haskell2010
+ type: exitcode-stdio-1.0
+ hs-source-dirs: ., test
+ main-is: Main.hs
+ -- TODO: bisect compatible versions
+ build-depends: base (>= 4 && < 5),
+ HUnit,
+ parsec,
+ QuickCheck,
+ test-framework,
+ test-framework-hunit,
+ test-framework-quickcheck2,
+ uniplate
+ other-modules: NginxLint.Data, NginxLint.Parse
+
+ ghc-options: -Wall -O0 -fno-warn-missing-signatures
View
@@ -0,0 +1,57 @@
+module Main (main) where
+
+import Data.List (isInfixOf)
+import qualified Test.Framework as T
+import Test.Framework.Providers.HUnit (testCase)
+import Test.Framework.Providers.QuickCheck2 (testProperty)
+import qualified Test.QuickCheck as Q
+import qualified Text.ParserCombinators.Parsec as P
+
+import NginxLint.Parse (argument, parseFile)
+
+
+main :: IO ()
+main = T.defaultMain tests
+
+tests =
+ [
+ T.testGroup "Cases" $ zipWith (testCase . ("Case "++) . show) [1::Int ..] [
+ ],
+ T.testGroup "Properties" $ zipWith (testProperty . ("Property "++) . show) [1::Int ..] [
+ prop_ParseComment01
+ , prop_ParseArg01
+ ]
+ ]
+
+
+genComment :: Q.Gen String
+genComment = do
+ s <- Q.arbitrary `Q.suchThat` notElem '\n'
+ return $ "#" ++ s
+
+genPlainString :: Q.Gen String
+genPlainString = Q.listOf1 c
+ where
+ c = Q.elements (['A'..'Z'] ++ ['a'..'z'] ++ ['0'..'9'] ++ "~!@#$%^&*")
+
+genArg :: Q.Gen String
+genArg = Q.oneof [genPlainString]
+
+prop_ParseComment01 = Q.forAll genComment isValidConfig
+
+prop_ParseArg01 = Q.forAll genArg isValidArg
+
+
+-- Begin utils
+
+isRight :: Either a b -> Bool
+isRight (Right _) = True
+isRight _ = False
+
+isValidConfig :: String -> Bool
+isValidConfig s = isRight $ P.parse parseFile "" s
+
+isValidArg :: String -> Bool
+isValidArg s = isRight $ P.parse argument "" s
+
+-- End utils

0 comments on commit 617688a

Please sign in to comment.