This repository has been archived by the owner on Oct 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 206
Fix #1578 - Redesign option parsing for main executable #1671
Merged
fendor
merged 1 commit into
haskell:master
from
gdziadkiewicz:feature/#1578_-_Redesign_option_parsing_for_main_executable
Mar 11, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,70 @@ | ||
module OptionsSpec where | ||
|
||
import Prelude hiding (unzip) | ||
import Data.List.NonEmpty(unzip) | ||
import Test.Hspec | ||
import Options.Applicative | ||
import Haskell.Ide.Engine.Options(GlobalOpts(..), RunMode(..), ProjectLoadingOpts(..), optionParser) | ||
import System.Exit(ExitCode(..)) | ||
import Data.List(isPrefixOf) | ||
|
||
main :: IO () | ||
main = hspec spec | ||
|
||
spec :: Spec | ||
spec = do | ||
let defaultGlobalOptions = GlobalOpts False Nothing Nothing False Nothing False (ProjectLoadingMode $ ProjectLoadingOpts False []) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line a bit too long, as well. |
||
let getParseFailure (Failure x) = Just (renderFailure x "hie") | ||
getParseFailure _ = Nothing | ||
let sut = optionParser | ||
let parserInfo = info sut mempty | ||
let parserPrefs = prefs mempty | ||
let runSut :: [String] -> ParserResult GlobalOpts | ||
runSut = execParserPure parserPrefs parserInfo | ||
|
||
describe "cmd option parsing" $ do | ||
describe "compiler flag" $ do | ||
let input = ["--compiler"] | ||
let result = runSut input | ||
let (maybeMessage, maybeStatusCode) = unzip $ getParseFailure result | ||
|
||
it "should return ghc version" $ | ||
maybeMessage `shouldSatisfy` any ("ghc" `isPrefixOf`) | ||
it "should return exit code 0" $ | ||
maybeStatusCode `shouldBe` Just ExitSuccess | ||
|
||
describe "numeric version flag" $ do | ||
let input = ["--numeric-version"] | ||
let result = runSut input | ||
let (maybeMessage, maybeStatusCode) = unzip $ getParseFailure result | ||
|
||
it "should return version" $ | ||
maybeMessage `shouldBe` Just "1.1" | ||
it "shoud return exit code 0" $ | ||
maybeStatusCode `shouldBe` Just ExitSuccess | ||
|
||
describe "not providing arguments" $ do | ||
let input = [] | ||
let result = runSut input | ||
let maybeGlobalOptions = getParseResult result | ||
|
||
it "should result in default options" $ | ||
maybeGlobalOptions `shouldBe` Just defaultGlobalOptions | ||
|
||
describe "lsp flag" $ do | ||
let input = ["--lsp"] | ||
let result = runSut input | ||
let maybeGlobalOptions = getParseResult result | ||
|
||
it "should result in default lsp options" $ | ||
maybeGlobalOptions `shouldBe` Just (GlobalOpts False Nothing Nothing False Nothing False LspMode) | ||
|
||
describe "providing two unmatching arguments" $ do | ||
let input = ["--lsp", "--dry-run"] | ||
let result = runSut input | ||
let (maybeMessage, maybeStatusCode) = unzip $ getParseFailure result | ||
|
||
it "should return expected error message" $ | ||
maybeMessage `shouldSatisfy` any ("Invalid option `--dry-run'" `isPrefixOf`) | ||
it "should return error exit code 1" $ | ||
maybeStatusCode `shouldBe` Just (ExitFailure 1) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line too long, limiting yourself to 80 chars per line makes it easier to read on small monitors