prop_ListJobIDs :: Property
prop_ListJobIDs = monadicIO $ do
  let extractJobIDs :: (Show e, Monad m) => m (GenericResult e a) -> m a
      extractJobIDs = (>>= genericResult (fail . show) return)
  jobs <- pick $ resize 10 (listOf1 genJobId `suchThat` (\l -> l == nub l))
  (e, f, g) <-
    run . withSystemTempDirectory "jqueue-test-ListJobIDs." $ \tempdir -> do
    empty_dir <- extractJobIDs $ getJobIDs [tempdir]
    mapM_ (\jid -> writeFile (tempdir </> jobFileName jid) "") jobs
    full_dir <- extractJobIDs $ getJobIDs [tempdir]
    invalid_dir <- getJobIDs [tempdir </> "no-such-dir"]
    return (empty_dir, sortJobIDs full_dir, invalid_dir)
  _ <- stop $ conjoin [ counterexample "empty directory" $ e ==? []
                      , counterexample "directory with valid names" $
                        f ==? sortJobIDs jobs
                      , counterexample "invalid directory" $ isBad g
                      ]
  return ()

-- | Tests loading jobs from disk.
prop_ListJobIDs :: Property
prop_ListJobIDs = monadicIO $ do
  let extractJobIDs :: (Show e, Monad m) => m (GenericResult e a) -> m a
      extractJobIDs = (>>= genericResult (fail . show) return)
  jobs <- pick $ resize 10 (listOf1 genJobId `suchThat` (\l -> l == nub l))
  (e, f, g) <-
    run . withSystemTempDirectory "jqueue-test-ListJobIDs." $ \tempdir -> do
    empty_dir <- extractJobIDs $ getJobIDs [tempdir]
    mapM_ (\jid -> writeFile (tempdir </> jobFileName jid) "") jobs
    full_dir <- extractJobIDs $ getJobIDs [tempdir]
    invalid_dir <- getJobIDs [tempdir </> "no-such-dir"]
    return (empty_dir, sortJobIDs full_dir, invalid_dir)
  _ <- stop $ conjoin [ counterexample "empty directory" $ e ==? []
                      , counterexample "directory with valid names" $
                        f ==? sortJobIDs jobs
                      , counterexample "invalid directory" $ isBad g
                      ]
  return ()

-- | Tests loading jobs from disk.
prop_ListJobIDs = monadicIO $ do
  let extractJobIDs :: (Show e, Monad m) => m (GenericResult e a) -> m a
      extractJobIDs = (>>= genericResult (fail . show) return)
  jobs <- pick $ resize 10 (listOf1 genJobId `suchThat` (\l -> l == nub l))
  (e, f, g) <-
    run . withSystemTempDirectory "jqueue-test-ListJobIDs." $ \tempdir -> do
    empty_dir <- extractJobIDs $ getJobIDs [tempdir]
    mapM_ (\jid -> writeFile (tempdir </> jobFileName jid) "") jobs
    full_dir <- extractJobIDs $ getJobIDs [tempdir]
    invalid_dir <- getJobIDs [tempdir </> "no-such-dir"]
    return (empty_dir, sortJobIDs full_dir, invalid_dir)
  _ <- stop $ conjoin [ counterexample "empty directory" $ e ==? []
                      , counterexample "directory with valid names" $
                        f ==? sortJobIDs jobs
                      , counterexample "invalid directory" $ isBad g
                      ]
  return ()

-- | Tests loading jobs from disk.