Skip to content

Commit

Permalink
check config in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszcz committed Oct 15, 2024
1 parent 53cb70d commit 3be6ce7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
9 changes: 5 additions & 4 deletions app/Commands/Dev/DevCompile/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Commands.Dev.DevCompile.Reg.Options
import Commands.Dev.DevCompile.Rust.Options
import Commands.Dev.DevCompile.Tree.Options
import CommonOptions
import Juvix.Config qualified as Config

data DevCompileCommand
= Core (CoreOptions 'InputMain)
Expand All @@ -22,15 +23,15 @@ data DevCompileCommand
parseDevCompileCommand :: Parser DevCompileCommand
parseDevCompileCommand =
hsubparser
( mconcat
( mconcat $
[ commandCore,
commandReg,
commandTree,
commandCasm,
commandAsm,
commandRust,
commandNativeRust
commandAsm
]
<> [commandRust | Config.config ^. Config.configRust]
<> [commandNativeRust | Config.config ^. Config.configRust]
)

commandCore :: Mod CommandFields DevCompileCommand
Expand Down
3 changes: 2 additions & 1 deletion test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Format qualified
import Formatter qualified
import Internal qualified
import Isabelle qualified
import Juvix.Config qualified as Config
import Nockma qualified
import Package qualified
import Parsing qualified
Expand Down Expand Up @@ -40,12 +41,12 @@ slowTests =
return Internal.allTests,
return Compilation.allTests,
return Examples.allTests,
Rust.allTests,
Casm.allTests,
VampIR.allTests,
return Anoma.allTests,
return Repl.allTests
]
<> sequence (if Config.config ^. Config.configRust then [Rust.allTests] else [])

fastTests :: IO TestTree
fastTests =
Expand Down
27 changes: 17 additions & 10 deletions test/Runtime/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Runtime.Base where

import Base
import Data.FileEmbed
import Juvix.Config qualified as Config
import System.Process qualified as P

clangCompile ::
Expand All @@ -25,12 +26,14 @@ clangCompile mkClangArgs inputFile outputFile execute step =

clangAssertion :: Int -> Path Abs File -> Path Abs File -> Text -> ((String -> IO ()) -> Assertion)
clangAssertion optLevel inputFile expectedFile stdinText step = do
step "Check clang and wasmer are on path"
assertCmdExists $(mkRelFile "clang")
assertCmdExists $(mkRelFile "wasmer")

step "Lookup WASI_SYSROOT_PATH"
sysrootPath :: Path Abs Dir <- getWasiSysrootPath
if
| Config.config ^. Config.configWasm -> do
step "Check clang and wasmer are on path"
assertCmdExists $(mkRelFile "clang")
assertCmdExists $(mkRelFile "wasmer")
| otherwise -> do
step "Check clang is on path"
assertCmdExists $(mkRelFile "clang")

expected <- readFile expectedFile

Expand All @@ -40,10 +43,14 @@ clangAssertion optLevel inputFile expectedFile stdinText step = do
let executeNative :: Path Abs File -> IO Text
executeNative outputFile = readProcess (toFilePath outputFile) [] stdinText

step "Compile C to WASM32-WASI"
actualWasm <- clangCompile (wasiArgs optLevel sysrootPath) inputFile $(mkRelFile "Program.wasm") executeWasm step
step "Compare expected and actual program output"
assertEqDiffText ("check: WASM output = " <> toFilePath expectedFile) actualWasm expected
when (Config.config ^. Config.configWasm) $ do
step "Lookup WASI_SYSROOT_PATH"
sysrootPath :: Path Abs Dir <- getWasiSysrootPath

step "Compile C to WASM32-WASI"
actualWasm <- clangCompile (wasiArgs optLevel sysrootPath) inputFile $(mkRelFile "Program.wasm") executeWasm step
step "Compare expected and actual program output"
assertEqDiffText ("check: WASM output = " <> toFilePath expectedFile) actualWasm expected

step "Compile C to native 64-bit code"
actualNative <- clangCompile (native64Args optLevel) inputFile $(mkRelFile "Program") executeNative step
Expand Down

0 comments on commit 3be6ce7

Please sign in to comment.