-
Notifications
You must be signed in to change notification settings - Fork 714
Set <pkgname_datadir> to an absolute path #10830
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,2 @@ | ||
import Distribution.Simple | ||
main = defaultMain |
13 changes: 13 additions & 0 deletions
13
cabal-testsuite/PackageTests/DataDirSetupTest/cabal.cabal.out
This file contains hidden or 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,13 @@ | ||
# Setup configure | ||
Configuring datadir-test-0.1.0.0... | ||
# Setup build | ||
Preprocessing library for datadir-test-0.1.0.0... | ||
Building library for datadir-test-0.1.0.0... | ||
Preprocessing test suite 'datadir-test' for datadir-test-0.1.0.0... | ||
Building test suite 'datadir-test' for datadir-test-0.1.0.0... | ||
# Setup test | ||
Running 1 test suites... | ||
Test suite datadir-test: RUNNING... | ||
Test suite datadir-test: PASS | ||
Test suite logged to: cabal.cabal.dist/work/dist/test/datadir-test-0.1.0.0-datadir-test.log | ||
1 of 1 test suites (1 of 1 test cases) passed. |
This file contains hidden or 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,13 @@ | ||
# Setup configure | ||
Configuring datadir-test-0.1.0.0... | ||
# Setup build | ||
Preprocessing library for datadir-test-0.1.0.0... | ||
Building library for datadir-test-0.1.0.0... | ||
Preprocessing test suite 'datadir-test' for datadir-test-0.1.0.0... | ||
Building test suite 'datadir-test' for datadir-test-0.1.0.0... | ||
# Setup test | ||
Running 1 test suites... | ||
Test suite datadir-test: RUNNING... | ||
Test suite datadir-test: PASS | ||
Test suite logged to: cabal.dist/work/dist/test/datadir-test-0.1.0.0-datadir-test.log | ||
1 of 1 test suites (1 of 1 test cases) passed. |
This file contains hidden or 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,5 @@ | ||
import Test.Cabal.Prelude | ||
|
||
main = setupAndCabalTest $ do | ||
setup_build ["--enable-tests"] | ||
setup "test" ["--show-details=streaming"] |
27 changes: 27 additions & 0 deletions
27
cabal-testsuite/PackageTests/DataDirSetupTest/datadir-test.cabal
This file contains hidden or 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,27 @@ | ||
cabal-version: 2.4 | ||
name: datadir-test | ||
version: 0.1.0.0 | ||
synopsis: Test for datadir environment variable | ||
license: BSD-3-Clause | ||
author: Cabal Test Suite | ||
maintainer: [email protected] | ||
build-type: Simple | ||
|
||
data-files: | ||
testdata/sample.txt | ||
|
||
library | ||
exposed-modules: MyLib | ||
build-depends: base >=4.7 && <5 | ||
other-modules: Paths_datadir_test | ||
hs-source-dirs: src | ||
default-language: Haskell2010 | ||
|
||
test-suite datadir-test | ||
type: exitcode-stdio-1.0 | ||
main-is: DataDirTest.hs | ||
hs-source-dirs: test | ||
build-depends: base >=4.7 && <5, | ||
datadir-test, | ||
directory | ||
default-language: Haskell2010 |
This file contains hidden or 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,6 @@ | ||
module MyLib (getDataFileName) where | ||
|
||
import qualified Paths_datadir_test as Paths | ||
|
||
getDataFileName :: FilePath -> IO FilePath | ||
getDataFileName = Paths.getDataFileName |
48 changes: 48 additions & 0 deletions
48
cabal-testsuite/PackageTests/DataDirSetupTest/test/DataDirTest.hs
This file contains hidden or 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,48 @@ | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
module Main where | ||
|
||
import Control.Monad (when) | ||
import System.Directory (createDirectory, doesFileExist, getCurrentDirectory, setCurrentDirectory) | ||
import System.Environment (getEnv) | ||
import System.Exit (exitFailure, exitSuccess) | ||
import System.IO (hPutStrLn, stderr) | ||
import MyLib (getDataFileName) | ||
import Control.Exception | ||
|
||
main :: IO () | ||
main = do | ||
-- Print the datadir environment variable | ||
dataDirEnv <- getEnv "datadir_test_datadir" | ||
putStrLn $ "datadir_test_datadir: " ++ dataDirEnv | ||
|
||
-- Get path to our test data file | ||
dataFilePath <- getDataFileName "testdata/sample.txt" | ||
putStrLn $ "Data file path: " ++ dataFilePath | ||
|
||
-- Check that we can access the file | ||
fileExists <- doesFileExist dataFilePath | ||
putStrLn $ "File exists: " ++ show fileExists | ||
|
||
-- Create a subdirectory and change into it | ||
currentDir <- getCurrentDirectory | ||
putStrLn $ "Current directory: " ++ currentDir | ||
createDirectory "subdir" `catch` \(_ :: SomeException) -> pure () | ||
setCurrentDirectory "subdir" | ||
newDir <- getCurrentDirectory | ||
putStrLn $ "New directory: " ++ newDir | ||
|
||
-- Try to access the data file again after changing directory | ||
dataFilePathAfterCd <- getDataFileName "testdata/sample.txt" | ||
putStrLn $ "Data file path after cd: " ++ dataFilePathAfterCd | ||
|
||
fileExistsAfterCd <- doesFileExist dataFilePathAfterCd | ||
putStrLn $ "File exists after cd: " ++ show fileExistsAfterCd | ||
|
||
-- Exit with error if we can't find the file | ||
when (not fileExistsAfterCd) $ do | ||
hPutStrLn stderr "ERROR: Could not find data file after changing directory!" | ||
hPutStrLn stderr $ "datadir_test_datadir was set to: " ++ dataDirEnv | ||
exitFailure | ||
|
||
putStrLn "SUCCESS: Data file found correctly even after changing directory!" | ||
exitSuccess |
1 change: 1 addition & 0 deletions
1
cabal-testsuite/PackageTests/DataDirSetupTest/testdata/sample.txt
This file contains hidden or 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 @@ | ||
This is test data for the datadir test. |
This file contains hidden or 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,10 @@ | ||
--- | ||
synopsis: Set <pkgname>_datadir to an absolute path when running tests | ||
packages: [Cabal] | ||
prs: 10828 | ||
issues: [10717] | ||
--- | ||
|
||
Fix a regression where `<pkgname>_datadir` was set to a relative path. This | ||
caused issues when running testsuites which changed the working directory and | ||
accessed datafiles. |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.