This repository was archived by the owner on Mar 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-hslua-module-path.hs
More file actions
52 lines (44 loc) · 1.63 KB
/
test-hslua-module-path.hs
File metadata and controls
52 lines (44 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
{-# LANGUAGE OverloadedStrings #-}
{-|
Module : Main
Copyright : © 2021 Albert Krewinkel
License : MIT
Maintainer : Albert Krewinkel <albert+hslua@zeitkraut.de>
Stability : stable
Portability : Requires language extensions ForeignFunctionInterface,
OverloadedStrings.
Tests for the `path` Lua module.
-}
import Control.Monad (void)
import Foreign.Lua (Lua)
import Foreign.Lua.Module.Path (preloadModule, pushModule)
import Test.Tasty (TestTree, defaultMain, testGroup)
import Test.Tasty.HUnit (assertEqual, testCase)
import Test.Tasty.Lua (translateResultsFromFile)
import qualified Foreign.Lua as Lua
main :: IO ()
main = do
luaTestResults <- Lua.run $ do
Lua.openlibs
Lua.requirehs "path" (void pushModule)
translateResultsFromFile "test/test-path.lua"
defaultMain $ testGroup "hslua-module-path" [tests, luaTestResults]
-- | HSpec tests for the Lua 'system' module
tests :: TestTree
tests = testGroup "HsLua path module"
[ testCase "path module can be pushed to the stack" $
Lua.run (void pushModule)
, testCase "path module can be added to the preloader" . Lua.run $ do
Lua.openlibs
preloadModule "path"
assertEqual' "function not added to preloader" Lua.TypeFunction =<< do
Lua.getglobal' "package.preload.path"
Lua.ltype (-1)
, testCase "path module can be loaded as hspath" . Lua.run $ do
Lua.openlibs
preloadModule "hspath"
assertEqual' "loading the module fails " Lua.OK =<<
Lua.dostring "require 'hspath'"
]
assertEqual' :: (Show a, Eq a) => String -> a -> a -> Lua ()
assertEqual' msg expected = Lua.liftIO . assertEqual msg expected