Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl6: Read file in test folder when using prove6

When writing tests, text file gets read in the test folder but not outside the folder (i.e., when running prove6). For example, this code reads ReadConfig.ini inside the test folder, but not outside of it:

my %v = ReadIni( 'ReadConfig.ini' );

On the other hand, this code works outside the test folder:

my %v = ReadIni( $*PROGRAM.dirname.IO.add('ReadConfig.ini') );

What would the proper syntax?

Thanks!

like image 618
Mimosinnet Avatar asked Apr 24 '19 11:04

Mimosinnet


1 Answers

So your test contains something like:

my %v = ReadIni( 'ReadConfig.ini' );

When you declare a relative file path it will be absolutified against $*CWD. So if you run your test inside the t/ folder it will look for t/ReadConfig.ini, and if you run it inside t/../ folder it will look for ../ReadConfig.ini. Therefore when you are writing tests you should use absolutified paths such that tooling is not constrained to running tests inside a specific location.


my %v = ReadIni( $*PROGRAM.dirname.IO.add('ReadConfig.ini') );

On the other hand if you provide an absolute file path then there is no discrepancy in what is meant, and this will Do What You Mean regardless of what directory you are in. However I would suggest no using dirname which does not include the volume portion on windows, and would instead use parent:

my %v = ReadIni( $*PROGRAM.parent.add('ReadConfig.ini') );
like image 164
ugexe Avatar answered Sep 23 '22 10:09

ugexe