1
votes

I have created a package and am now creating my tests within the package. For one test my inputs are a set of files and my outputs will be a different set a files created within the test.

I am saving the input files in the test directory of my package and would like to save the output files there too. Since others may run this test, I do not want to specify the input/output file location using my own path eg /home/myname/.julia/v4.0/MyPackage/test/MyInputFile.txt How do I specify that the input location is within the package's test folder?

So basically how do I tell Julia to look in the packages's folder under the test directory and not have to worry about specifying the entire path including user name etc?

For example currently I have to say

readtable(/home/myname/.julia/v4.0/MyPackage/test/MyInputFile.txt, separator = '\t', header = false)

But I'd like to just be able to say

readtable(/MyPackage/test/MyInputFile.txt, separator = '\t', header = false)

so that no matter who the user of the package is and where they may store the package, they can still run the test?

I know that LOAD_PATH gives the path Julia looks for packages but I can't find any information on where it looks when importing files.

2
joinpath(Pkg.dir("MyPackage"), "test") is what you need.Gnimuc

2 Answers

2
votes

joinpath(Pkg.dir("MyPackage"), "test") is what you need.

1
votes

As @GnimucK mentioned in a comment, a better solution is

dirname(@__FILE__)

Why is this better? A package could be installed and used from somewhere else (not the standard package directory). Pkg.dir is "stupid" and does not know better. This is rare, of course, and in most cases it won't matter.