-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
163 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 37 additions & 1 deletion
38
sandwich-webdriver/src/Test/Sandwich/WebDriver/Internal/Binaries/Ffmpeg.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,43 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE TypeApplications #-} | ||
|
||
module Test.Sandwich.WebDriver.Internal.Binaries.Ffmpeg ( | ||
obtainFfmpeg | ||
|
||
-- * Types | ||
FfmpegToUse(..) | ||
, FfmpegToUse(..) | ||
) where | ||
|
||
import Control.Monad.IO.Unlift | ||
import Control.Monad.Logger | ||
import Control.Monad.Reader | ||
import Data.String.Interpolate | ||
import qualified Data.Text as T | ||
import Test.Sandwich | ||
import Test.Sandwich.Contexts.Files | ||
import Test.Sandwich.WebDriver.Internal.Binaries.Ffmpeg.Types | ||
import UnliftIO.Directory | ||
|
||
|
||
-- | Manually obtain an ffmpeg binary, according to the 'FfmpegToUse' policy. | ||
obtainFfmpeg :: ( | ||
MonadReader context m, HasBaseContext context | ||
, MonadUnliftIO m, MonadLoggerIO m, MonadFail m | ||
) => FfmpegToUse -> m (Either T.Text FilePath) | ||
obtainFfmpeg UseFfmpegFromPath = findExecutable "ffmpeg" >>= \case | ||
Nothing -> return $ Left [i|Couldn't find "ffmpeg" on the PATH.|] | ||
Just p -> return $ Right p | ||
obtainFfmpeg (UseFfmpegAt path) = doesFileExist path >>= \case | ||
False -> return $ Left [i|Path '#{path}' didn't exist|] | ||
True -> return $ Right path | ||
obtainFfmpeg (UseFfmpegFromNixpkgs nixContext) = | ||
Right <$> getBinaryViaNixDerivation' @"ffmpeg" nixContext ffmpegDerivation | ||
|
||
|
||
ffmpegDerivation :: T.Text | ||
ffmpegDerivation = [i| | ||
{ ffmpeg | ||
}: | ||
|
||
ffmpeg.override { withXcb = true; } | ||
|] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
sandwich-webdriver/src/Test/Sandwich/WebDriver/Internal/OnDemand.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
|
||
module Test.Sandwich.WebDriver.Internal.OnDemand where | ||
|
||
import Control.Monad.IO.Unlift | ||
import Control.Monad.Logger | ||
import Data.String.Interpolate | ||
import Data.Text as T | ||
import Test.Sandwich | ||
import Test.Sandwich.WebDriver.Internal.Types | ||
import UnliftIO.Async | ||
import UnliftIO.Exception | ||
import UnliftIO.MVar | ||
|
||
|
||
getOnDemand :: forall m a. ( | ||
MonadUnliftIO m, MonadLogger m | ||
) => MVar (OnDemand a) -> m (Either Text a) -> m a | ||
getOnDemand onDemandVar doObtain = do | ||
result <- modifyMVar onDemandVar $ \case | ||
OnDemandErrored msg -> expectationFailure (T.unpack msg) | ||
OnDemandNotStarted -> do | ||
asy <- async $ do | ||
let handler :: SomeException -> m a | ||
handler e = do | ||
modifyMVar_ onDemandVar (const $ return $ OnDemandErrored [i|Got exception: #{e}|]) | ||
throwIO e | ||
|
||
handle handler $ do | ||
doObtain >>= \case | ||
Left err -> do | ||
modifyMVar_ onDemandVar (const $ return $ OnDemandErrored err) | ||
expectationFailure [i|Failed to obtain: #{err}|] | ||
|
||
Right x -> do | ||
modifyMVar_ onDemandVar (const $ return $ OnDemandReady x) | ||
return x | ||
|
||
return (OnDemandInProgress asy, Left asy) | ||
|
||
od@(OnDemandInProgress asy) -> pure (od, Left asy) | ||
od@(OnDemandReady x) -> pure (od, Right x) | ||
|
||
case result of | ||
Right x -> pure x | ||
Left asy -> wait asy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters