Skip to content

Commit

Permalink
Allow the expected return value to be specified in c file tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Marwes committed Apr 15, 2017
1 parent 9f5db1e commit c1938e3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions scripts/corrode-cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ if '-c' in cflags:

if outfile is None:
outfile = str(PurePath(str(rsfile)).with_suffix(".o"))
print("-------", rsfile)

rustwarn = subprocess.run(
['rustc', '--crate-type=dylib', '--emit', 'obj', '-o', outfile, rsfile],
Expand Down
2 changes: 2 additions & 0 deletions tests/regression-tests/clone-impl.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// returns 123

struct Test
{
int x[100];
Expand Down
18 changes: 16 additions & 2 deletions tests/test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Data.List
import Language.Rust.Corrode.CFG
import System.Directory
import System.FilePath ((</>))
import System.Exit (ExitCode(..))
import System.Process
import Test.Tasty
import Test.Tasty.HUnit
Expand All @@ -33,17 +34,30 @@ regressionDir = "tests" </> "regression-tests"

regressionTest :: String -> TestTree
regressionTest name = testCase name $ do
callProcess "gcc" ["-o", "dist/build" </> name, regressionDir </> (name ++ ".c")]
let cName = regressionDir </> (name ++ ".c")

cFileContents <- readFile cName
let firstLine = head (lines cFileContents)
expectedExitInt =
if isPrefixOf "// returns " firstLine then
read (drop (length "// returns ") firstLine)
else
0
expectedExitcode = if expectedExitInt == 0 then ExitSuccess else ExitFailure expectedExitInt


callProcess "gcc" ["-o", "dist/build" </> name, cName]
cProgram <- spawnProcess ("dist/build" </> name) []

callProcess "python"
[ "./scripts/corrode-cc"
, "-o", "dist/build" </> (name ++ "-rust")
, regressionDir </> (name ++ ".c")
, cName
]
rustProgram <- spawnProcess ("dist/build" </> (name ++ "-rust")) []
expected <- waitForProcess cProgram
actual <- waitForProcess rustProgram
expectedExitcode @=? expected
expected @=? actual

regressionTests :: TestTree
Expand Down

0 comments on commit c1938e3

Please sign in to comment.