Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions htagcli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,6 @@ test-suite tests
Tests.Model.Pattern
Tests.Model.Tag

ghc-options:
-F
-pgmF=tasty-autocollect

build-depends:
hedgehog,
hspec,
Expand All @@ -147,7 +143,6 @@ test-suite tests
path-io,
resourcet,
tasty,
tasty-autocollect,
tasty-expected-failure,
tasty-hedgehog,
tasty-hunit-compat,
Expand Down
27 changes: 26 additions & 1 deletion tests/Main.hs
Original file line number Diff line number Diff line change
@@ -1 +1,26 @@
{- AUTOCOLLECT.MAIN -}
module Main (main) where

import Test.Tasty (defaultMain, testGroup)
import Tests.Check.Album qualified as Check.Album
import Tests.Check.Artist qualified as Check.Artist
import Tests.Check.Track qualified as Check.Track
import Tests.Commands as Commands
import Tests.Config as Config
import Tests.Model.AudioTrack qualified as Model.AudioTrack
import Tests.Model.Pattern qualified as Model.Pattern
import Tests.Model.Tag qualified as Model.Tag

main :: IO ()
main =
defaultMain $
testGroup
"Tests"
[ Commands.test,
Config.test,
Model.AudioTrack.test,
Model.Pattern.test,
Model.Tag.test,
Check.Album.test,
Check.Artist.test,
Check.Track.test
]
31 changes: 18 additions & 13 deletions tests/Tests/Check/Album.hs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
{- AUTOCOLLECT.TEST -}
{-# LANGUAGE QuasiQuotes #-}

module Tests.Check.Album
(
{- AUTOCOLLECT.TEST.export -}
)
where
module Tests.Check.Album (test) where

import Check.Album qualified as Album
import Data.List.NonEmpty ((<|))
Expand All @@ -23,8 +18,18 @@ import Test.Tasty qualified as Tasty
import Test.Tasty.HUnit qualified as Tasty
import Tests.Common qualified as Common

test :: TestTree
test :: Tasty.TestTree
test =
Tasty.testGroup
"Check.Album"
[ testCheckCover,
testCheckDirectory,
testCheckSameTags,
testCheckSequential
]

testCheckCover :: Tasty.TestTree
testCheckCover =
Tasty.testGroup
"check cover"
[ Tasty.testCase "check an album without a cover.png" $
Expand Down Expand Up @@ -80,8 +85,8 @@ test =
}
covers = fromList [[relfile|cover.jpg|], [relfile|cover.png|]]

test :: TestTree
test =
testCheckDirectory :: Tasty.TestTree
testCheckDirectory =
Tasty.testGroup
"check directory"
[ Tasty.testCase "an album is in a single directory" $ do
Expand All @@ -105,8 +110,8 @@ test =
{ AudioTrack.atFile = newDir </> Path.filename (AudioTrack.atFile track)
}

test :: TestTree
test =
testCheckSameTags :: Tasty.TestTree
testCheckSameTags =
Tasty.testGroup
"check same tags"
[ Tasty.testCase "all tracks have the same tags" $ do
Expand All @@ -120,8 +125,8 @@ test =
where
commonTags = fromList [Tag.Genre, Tag.Year, Tag.Artist, Tag.AlbumArtist]

test :: TestTree
test =
testCheckSequential :: Tasty.TestTree
testCheckSequential =
Tasty.testGroup
"check sequential tracks"
[ Tasty.testCase "the tracks are sequential" $ do
Expand Down
11 changes: 3 additions & 8 deletions tests/Tests/Check/Artist.hs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
{- AUTOCOLLECT.TEST -}
{-# LANGUAGE QuasiQuotes #-}

module Tests.Check.Artist
(
{- AUTOCOLLECT.TEST.export -}
)
where
module Tests.Check.Artist (test) where

import Check.Artist qualified as Artist
import Model.Artist qualified as Artist
Expand All @@ -17,10 +12,10 @@ import Test.Tasty qualified as Tasty
import Test.Tasty.HUnit qualified as Tasty
import Tests.Common qualified as Common

test :: TestTree
test :: Tasty.TestTree
test =
Tasty.testGroup
"check artist"
"Check.Artist"
[ Tasty.testCase "two albums of the same artist with the same genre" $ do
let album1 = tenTracksAlbum (HTagLib.mkAlbum "album-1") rock
album2 = tenTracksAlbum (HTagLib.mkAlbum "album-2") rock
Expand Down
16 changes: 9 additions & 7 deletions tests/Tests/Check/Track.hs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
{- AUTOCOLLECT.TEST -}
{-# LANGUAGE QuasiQuotes #-}

module Tests.Check.Track
(
{- AUTOCOLLECT.TEST.export -}
)
where
module Tests.Check.Track (test) where

import Check.Track qualified as Track
import Model.AudioTrack qualified as AudioTrack
Expand All @@ -18,8 +13,15 @@ import Test.Hspec.Expectations (shouldBe)
import Test.Tasty qualified as Tasty
import Test.Tasty.HUnit qualified as Tasty

test :: TestTree
test :: Tasty.TestTree
test =
Tasty.testGroup
"Check.Track"
[ testFilenameMatches
]

testFilenameMatches :: Tasty.TestTree
testFilenameMatches =
Tasty.testGroup
"FilenameMatches"
[ Tasty.testCase
Expand Down
14 changes: 6 additions & 8 deletions tests/Tests/Commands.hs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
{- AUTOCOLLECT.TEST -}
{-# LANGUAGE QuasiQuotes #-}

module Tests.Commands
(
{- AUTOCOLLECT.TEST.export -}
)
where
module Tests.Commands (test) where

import Check.Track qualified as Track
import Commands qualified
Expand All @@ -23,8 +18,11 @@ import Test.Tasty qualified as Tasty
import Test.Tasty.HUnit qualified as Tasty
import Tests.Common qualified as Common

test :: TestTree
test =
test :: Tasty.TestTree
test = Tasty.testGroup "Commands" [testFixFilePaths]

testFixFilePaths :: Tasty.TestTree
testFixFilePaths =
Tasty.testGroup
"fixFilePaths"
[ Tasty.testCase "dry run" $
Expand Down
15 changes: 7 additions & 8 deletions tests/Tests/Config.hs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
{- AUTOCOLLECT.TEST -}
module Tests.Config
(
{- AUTOCOLLECT.TEST.export -}
)
where
module Tests.Config (test) where

import Config qualified
import Test.Hspec.Expectations (shouldSatisfy)
import Test.Tasty qualified as Tasty
import Test.Tasty.HUnit qualified as Tasty
import UnliftIO.Exception qualified as Exception

test :: TestTree
test =
test :: Tasty.TestTree
test = Tasty.testGroup "Config" [testParseDefaultConfig]

testParseDefaultConfig :: Tasty.TestTree
testParseDefaultConfig =
Tasty.testCase "Default config should parse" $ do
result <-
Exception.tryAny $ Config.parseByteString Config.defaultConfigContent
Expand Down
23 changes: 13 additions & 10 deletions tests/Tests/Model/AudioTrack.hs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
{- AUTOCOLLECT.TEST -}
{-# LANGUAGE QuasiQuotes #-}

module Tests.Model.AudioTrack
(
{- AUTOCOLLECT.TEST.export -}
)
where
module Tests.Model.AudioTrack (test) where

import Control.Monad.Morph qualified as Morph
import Control.Monad.Trans.Resource qualified as Resource
Expand All @@ -25,6 +20,14 @@ import Test.Tasty qualified as Tasty
import Test.Tasty.Hedgehog qualified as Tasty
import Text.Megaparsec qualified as Megaparsec

test :: Tasty.TestTree
test =
Tasty.testGroup
"Model.AudioTrack"
[ testParse,
testSetGetRoundTrip
]

audioTrackGen :: Hedgehog.Gen AudioTrack.AudioTrack
audioTrackGen = do
atFile <- absFileGen
Expand Down Expand Up @@ -60,8 +63,8 @@ absFileGen = do
pathPieceGen =
HedgehogGen.string (HedgehogRange.linear 1 20) HedgehogGen.alphaNum

test :: TestTree
test =
testParse :: Tasty.TestTree
testParse =
Tasty.testGroup
"Parse"
[ Tasty.testPropertyNamed "one" "test_parse_one" $ Hedgehog.property $ do
Expand All @@ -77,8 +80,8 @@ test =
=== Right audioTracks
]

test :: TestTree
test =
testSetGetRoundTrip :: Tasty.TestTree
testSetGetRoundTrip =
Tasty.testPropertyNamed "roundtrip" "test_set_get" $ do
Hedgehog.property . Morph.hoist Resource.runResourceT $ do
(_, tempDir) <-
Expand Down
43 changes: 25 additions & 18 deletions tests/Tests/Model/Pattern.hs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
{- AUTOCOLLECT.TEST -}
{-# LANGUAGE QuasiQuotes #-}

module Tests.Model.Pattern
(
{- AUTOCOLLECT.TEST.export -}
)
where
module Tests.Model.Pattern (test) where

import Check.Track qualified as Track
import Hedgehog ((===))
Expand All @@ -26,6 +21,18 @@ import Test.Tasty.HUnit qualified as Tasty
import Test.Tasty.Hedgehog qualified as Tasty
import Text.Megaparsec qualified as Megaparsec

test :: Tasty.TestTree
test =
Tasty.testGroup
"Model.Pattern"
[ testParseRoundTrip,
testStaticPatterns,
testTagPattern,
testOtherPatterns,
testParser,
testFormatting
]

patternGen :: Hedgehog.Gen Pattern.Pattern
patternGen = HedgehogGen.nonEmpty (HedgehogRange.linear 1 5) componentGen

Expand Down Expand Up @@ -62,15 +69,15 @@ textGen :: Hedgehog.Gen Text
textGen =
HedgehogGen.text (HedgehogRange.linear 1 10) HedgehogGen.alphaNum

test :: TestTree
test =
testParseRoundTrip :: Tasty.TestTree
testParseRoundTrip =
Tasty.testPropertyNamed "parse" "test_parse_pattern" $ Hedgehog.property $ do
pattern <- Hedgehog.forAll patternGen
Megaparsec.parse Pattern.parser "" (Pattern.asText pattern)
=== Right pattern

test :: TestTree
test =
testStaticPatterns :: Tasty.TestTree
testStaticPatterns =
Tasty.testGroup
"Static patterns"
[ testFileMatchesAndToPath
Expand Down Expand Up @@ -107,8 +114,8 @@ test =
(trackWithFile [absfile|/some-path/to-somewhere/audio.mp3|])
]

test :: TestTree
test =
testTagPattern :: Tasty.TestTree
testTagPattern =
Tasty.testGroup
"Tag patterns"
[ testFileMatchesAndToPath
Expand Down Expand Up @@ -225,8 +232,8 @@ testFileMatchesAndToPath text pattern track@AudioTrack.AudioTrack {..} =
where
root = [absdir|/|]

test :: TestTree
test =
testOtherPatterns :: Tasty.TestTree
testOtherPatterns =
Tasty.testGroup
"Other patterns"
[ Tasty.testCase
Expand All @@ -241,8 +248,8 @@ test =
`shouldBe` False
]

test :: TestTree
test =
testParser :: Tasty.TestTree
testParser =
Tasty.testGroup
"Pattern parser"
[ Tasty.testCase "single text" $
Expand Down Expand Up @@ -287,8 +294,8 @@ test =
]
]

test :: TestTree
test =
testFormatting :: Tasty.TestTree
testFormatting =
Tasty.testGroup
"Formatting options"
[ Tasty.testCase "no substitutions" $
Expand Down
16 changes: 7 additions & 9 deletions tests/Tests/Model/Tag.hs
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
{- AUTOCOLLECT.TEST -}

module Tests.Model.Tag
(
{- AUTOCOLLECT.TEST.export -}
)
where
module Tests.Model.Tag (test) where

import Hedgehog ((===))
import Hedgehog qualified
import Hedgehog.Gen qualified as Hedgehog
import Model.Tag qualified as Tag
import Test.Tasty qualified as Tasty
import Test.Tasty.Hedgehog qualified as Tasty
import Text.Megaparsec qualified as Megaparsec

test :: TestTree
test =
test :: Tasty.TestTree
test = Tasty.testGroup "Model.Tag" [testParseRoundTrip]

testParseRoundTrip :: Tasty.TestTree
testParseRoundTrip =
Tasty.testPropertyNamed "roundtrip" "test_parse_one" $ Hedgehog.property $ do
tag <- Hedgehog.forAll Hedgehog.enumBounded
Megaparsec.parse Tag.parser "" (Tag.asText tag) === Right tag