Fix damlc test with relative --project-root (#6541)

Returning the original relative path from withProjectRoot makes no
sense since we change the directory in there so this PR fixes this to
return the canonicalized project root.

fixes #6245

changelog_begin

- [DAML Compiler] damlc test --project-root now works with relative
  paths as well.

changelog_end
This commit is contained in:
Moritz Kiefer 2020-06-30 16:45:28 +02:00 committed by GitHub
parent 0c80c984b6
commit 470d4f28a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View File

@ -194,6 +194,23 @@ testsForDamlcTest damlc = testGroup "damlc test" $
exitCode @?= ExitSuccess
assertBool ("Succeeding scenario in " <> stdout) ("Main.daml:test: ok" `isInfixOf` stdout)
stderr @?= ""
, testCase "damlc test --project-root relative" $ withTempDir $ \projDir -> do
createDirectoryIfMissing True (projDir </> "relative")
writeFileUTF8 (projDir </> "relative" </> "Main.daml") $ unlines
[ "daml 1.2"
, "module Main where"
, "test = scenario do"
, " assert True"
]
writeFileUTF8 (projDir </> "relative" </> "daml.yaml") $ unlines
[ "sdk-version: " <> sdkVersion
, "name: relative"
, "version: 0.0.1"
, "source: ."
, "dependencies: [daml-prim, daml-stdlib]"
]
withCurrentDirectory projDir $
callProcessSilent damlc ["test", "--project-root=relative"]
] <>
[ testCase ("damlc test " <> unwords (args "") <> " in project") $ withTempDir $ \projDir -> do
createDirectoryIfMissing True (projDir </> "a")

View File

@ -173,10 +173,10 @@ withProjectRoot mbProjectDir (ProjectCheck cmdName check) act = do
when check $ do
hPutStrLn stderr (cmdName <> ": Not in project.")
exitFailure
act mbProjectPath pure
act Nothing pure
Just projectPath -> do
projectPath <- canonicalizePath projectPath
withCurrentDirectory projectPath $ act mbProjectPath $ \f -> do
withCurrentDirectory projectPath $ act (Just projectPath) $ \f -> do
absF <- canonicalizePath (previousCwd </> f)
pure (projectPath `makeRelative` absF)