Skip to content
This repository has been archived by the owner on Mar 6, 2023. It is now read-only.

Commit

Permalink
The first ever end-to-end test
Browse files Browse the repository at this point in the history
  • Loading branch information
NorfairKing committed Feb 28, 2016
1 parent 22c4663 commit 97c3f29
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 1 deletion.
1 change: 1 addition & 0 deletions subdir/.bash_aliases
1 change: 1 addition & 0 deletions subdir/.bash_profile
1 change: 1 addition & 0 deletions subdir/.bashrc
5 changes: 4 additions & 1 deletion super-user-spark.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,12 @@ test-suite spark-tests
type: exitcode-stdio-1.0
main-is: MainTest.hs
hs-source-dirs: src, test
other-modules: ParserSpec
other-modules: CheckSpec
, ParserSpec
, CompilerSpec
, DeployerSpec
, SeedSpec
, EndToEndSpec
build-depends: base >= 4.6 && < 4.9
, super-user-spark
, hspec >= 2.2 && < 2.3
Expand Down
62 changes: 62 additions & 0 deletions test/EndToEndSpec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
module EndToEndSpec (spec) where

import Spark
import System.Directory hiding (createDirectoryIfMissing)
import System.Environment (withArgs)
import System.FilePath.Posix ((</>))
import System.Posix.Files
import Test.Hspec
import Test.QuickCheck
import Utils

spec :: Spec
spec = do
let sandbox = "test_sandbox"
let setup = createDirectoryIfMissing sandbox
let teardown = removeDirectoryRecursive sandbox

let rsc = "test_resources" </> "end-to-end"

beforeAll_ setup $ afterAll_ teardown $ do
describe "standard bash card test" $ do
let bashrsc = rsc </> "bash.sus"
let bashrscres = rsc </> "bash.sus.res"
let cardfile = sandbox </> "bash.sus"

let up = do
copyFile bashrsc cardfile
withCurrentDirectory sandbox $ do
createDirectoryIfMissing "bash"
withCurrentDirectory "bash" $ do
writeFile "bash_aliases" "bash_aliases"
writeFile "bashrc" "bashrc"
writeFile "bash_profile" "bash_profile"

let down = do
removeFile cardfile
withCurrentDirectory sandbox $ do
removeDirectoryRecursive "bash"


beforeAll_ up $ afterAll_ down $ do
it "parses correcty" $ do
withArgs ["parse", cardfile] spark `shouldReturn` ()

it "compiles correctly" $ do
let outfile = sandbox </> "bash.sus.res"

withArgs ["compile", cardfile, "--output", outfile] spark `shouldReturn` ()

actual <- readFile outfile
expected <- readFile bashrscres
actual `shouldBe` expected

it "checks without exceptions" $ do
withArgs ["check", cardfile] spark `shouldReturn` ()

it "deploys correctly" $ do
withArgs ["deploy", cardfile] spark `shouldReturn` ()

readFile ("subdir" </> ".bashrc") `shouldReturn` "bashrc"
readFile ("subdir" </> ".bash_aliases") `shouldReturn` "bash_aliases"
readFile ("subdir" </> ".bash_profile") `shouldReturn` "bash_profile"
8 changes: 8 additions & 0 deletions test_resources/end-to-end/bash.sus
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
card bash {
into subdir
outof bash

.bashrc
.bash_aliases
.bash_profile
}
26 changes: 26 additions & 0 deletions test_resources/end-to-end/bash.sus.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[
{
"destination": "subdir/.bashrc",
"sources": [
"bash/.bashrc",
"bash/bashrc"
],
"deployment kind": "link"
},
{
"destination": "subdir/.bash_aliases",
"sources": [
"bash/.bash_aliases",
"bash/bash_aliases"
],
"deployment kind": "link"
},
{
"destination": "subdir/.bash_profile",
"sources": [
"bash/.bash_profile",
"bash/bash_profile"
],
"deployment kind": "link"
}
]

0 comments on commit 97c3f29

Please sign in to comment.