Skip to content
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

Doesn't work with Config::MySQL::Reader ( and maybe IO::File ) #39

Open
pavelsr opened this issue Feb 26, 2019 · 2 comments
Open

Doesn't work with Config::MySQL::Reader ( and maybe IO::File ) #39

pavelsr opened this issue Feb 26, 2019 · 2 comments

Comments

@pavelsr
Copy link

pavelsr commented Feb 26, 2019

This test does not work for some reason

use Test::More;
use Test::MockFile;
use Data::Dumper;

# Test that Config::MySQL::Reader does not read comments
use_ok('Config::MySQL::Reader');

my $cnf = <<INI;
[group1]
[group1]
# comment
; comment
path = foo/bar
quoted_param = "foo;bar"
numerical_param = 12345
string_param = 500M
param_with_comment = xyz # abc

# e.g. skip-name-resolve
param-without-value

param-with-two-spaces-after
param-with-tabulation-after  
empty_str ""
INI

my $random_filename = 'foo.ini';
my $mock_file = Test::MockFile->file($random_filename, $cnf);
my $config = Config::MySQL::Reader->read_file($random_filename);

my $res = {
    'group1' => {
        'string_param'                  => '500M',
        'param-with-two-spaces-after'   => undef,
        'path'                          => 'foo/bar',
        'param-without-value'           => undef,
        'param_with_comment'            => 'xyz',
        'param-with-tabulation-after  ' => undef,
        'empty_str ""'                  => undef,
        'quoted_param'                  => '"foo;bar"',
        'numerical_param'               => '12345'
    }
};

is_deeply $config, $res;

done_testing;

I haven't fully investigated this problem yet, but quick code analysis of Config::MySQL::Reader show that maybe issue related to IO::File package call

@toddr
Copy link
Member

toddr commented Feb 26, 2019

I can't look right now but if you do use Test::MockFile qw/strict/;, it might tell you the stack for the file call not being caught.

@toddr
Copy link
Member

toddr commented Feb 3, 2022

More simply:

use Test::MockFile;

# Test that Config::MySQL::Reader does not read comments
use Config::MySQL::Reader ();

my $cnf = <<INI;
[group1]
[group1]
# comment
; comment
path = foo/bar
quoted_param = "foo;bar"
numerical_param = 12345
string_param = 500M
param_with_comment = xyz # abc

# e.g. skip-name-resolve
param-without-value

param-with-two-spaces-after
param-with-tabulation-after  
empty_str ""
INI

my $random_filename = '/foo.ini';
my $mock_file = Test::MockFile->file($random_filename, $cnf);
my $config = Config::MySQL::Reader->read_file($random_filename);

gets:

$>perl t/tmp.t
couldn't read file '/foo.ini': No such file or directory at t/tmp.t line 27.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants