diff --git a/package.yaml b/package.yaml index 893802c..cc42a10 100644 --- a/package.yaml +++ b/package.yaml @@ -159,3 +159,12 @@ benchmarks: - casa-client ghc-options: - -O2 + +tests: + unit-tests: + main: main.hs + source-dirs: unit-tests + dependencies: + - stackage-server + - hspec + - pantry diff --git a/stack.yaml b/stack.yaml index fd33610..7fe6448 100644 --- a/stack.yaml +++ b/stack.yaml @@ -5,6 +5,10 @@ extra-deps: - classy-prelude-yesod-1.5.0 - unliftio-core-0.1.2.0 - yesod-gitrepo-0.3.0 +- hspec-2.11.1 +- hspec-core-2.11.1 +- hspec-discover-2.11.1 +- hspec-expectations-0.8.3 drop-packages: - Cabal diff --git a/unit-tests/main.hs b/unit-tests/main.hs new file mode 100644 index 0000000..592b734 --- /dev/null +++ b/unit-tests/main.hs @@ -0,0 +1,28 @@ +import Pantry (parseVersionThrowing, parsePackageNameThrowing) +import Pantry.Internal.Stackage (VersionP(VersionP), PackageNameP(PackageNameP)) +import Stackage.Snapshot.Diff (SnapshotDiff, snapshotDiff, toDiffList) + +import Test.Hspec (Spec, describe, hspec, it, shouldBe) + +snapshotDiffLength :: SnapshotDiff -> Int +snapshotDiffLength = length . toDiffList + +main :: IO () +main = do + booleanName <- PackageNameP <$> parsePackageNameThrowing "Boolean" + booleanVer <- VersionP <$> parseVersionThrowing "0.2.4" + bookkeepingName <- PackageNameP <$> parsePackageNameThrowing "bookkeeping" + bookkeepingVer <- VersionP <$> parseVersionThrowing "0.4.0.1" + + let + boolean = (booleanName, booleanVer) + bookkeeping = (bookkeepingName, bookkeepingVer) + + hspec $ + describe "Packages with upper case characters" $ + describe "Removal of bookkeeping package is one change" $ do + it "[Boolean, bookkeeping] -> [Boolean]" $ + snapshotDiffLength (snapshotDiff [boolean, bookkeeping] [boolean]) `shouldBe` 1 + + it "[bookkeeping, Boolean] -> [Boolean]" $ + snapshotDiffLength (snapshotDiff [bookkeeping, boolean] [boolean]) `shouldBe` 1