Skip Menu |

This queue is for tickets about the File-BaseDir CPAN distribution.

Report information
The Basics
Id: 103805
Status: resolved
Priority: 0/
Queue: File-BaseDir

People
Owner: kimryan [...] cpan.org
Requestors: SREZIC [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 0.06
Fixed in: 0.07



Subject: t/03_userdirs.t does not restore ~/.config/user-dirs.dirs
The END block in t/03_userdirs.t is supposed to restore the old contents of ~/.config/user-dirs.dirs. Unfortunately $xdg_user_dir_installed is never set to true, so the END block never runs. Moreover, changing this configuration file for tests is problematic if users test the module with multiple perls in parallel --- so race conditions are possible, and this might be the case in this fail report: http://www.cpantesters.org/cpan/report/cec91274-dc00-11e4-95a6-11378e88e62e
Thanks for pointing out this bug. I think this is the change required to get it working. my $xdg_user_dir_installed = 0; if (which 'xdg-user-dir') { plan tests => 8; $xdg_user_dir_installed = 0; } else { plan skip_all => '"xdg-user-dir" executable not found. Install package "xdg-user-dirs".'; $xdg_user_dir_installed = 1; } Agree it is not good practice to be altering config file contents during test phase. I adopted this module as it had been abandoned, and applied several old patches. This includes the 03_userdirs.t test. It relies on running the xdg-user-dir binary, which doesn't seem like a good thing to put into a CPAN test suite. But I don't really have the time or knowledge to try and unravel all this code. So if you think above fix is enough, I can apply that.
Sorry, code should be my $xdg_user_dir_installed = 0; if (which 'xdg-user-dir') { plan tests => 8; $xdg_user_dir_installed = 1; } else { plan skip_all => '"xdg-user-dir" executable not found. Install package "xdg-user-dirs".'; } On Sat Apr 18 22:12:20 2015, KIMRYAN wrote: Show quoted text
> Thanks for pointing out this bug. I think this is the change required > to get it working. > > my $xdg_user_dir_installed = 0; > if (which 'xdg-user-dir') { > plan tests => 8; > $xdg_user_dir_installed = 0; > } else { > plan skip_all => '"xdg-user-dir" executable not found. Install > package "xdg-user-dirs".'; > $xdg_user_dir_installed = 1; > > } > > Agree it is not good practice to be altering config file contents > during test phase. I adopted this module as it had been abandoned, and > applied several old patches. This includes the 03_userdirs.t test. It > relies on running the xdg-user-dir binary, which doesn't seem like a > good thing to put into a CPAN test suite. But I don't really have the > time or knowledge to try and unravel all this code. So if you think > above fix is enough, I can apply that.
Still there's the possibility of race conditions (multiple test runs happen at the same time, e.g. for multiple perls) or the possibility of some crash between creation of the test contents and running the END{} block. One possibility would be to fake the $HOME environment variable and use an exclusive version of the config file. See the attached patch. The original test could maybe still be used as an author or travis-ci only test. On 2015-04-18 22:32:57, KIMRYAN wrote: Show quoted text
> Sorry, code should be > > my $xdg_user_dir_installed = 0; > if (which 'xdg-user-dir') { > plan tests => 8; > $xdg_user_dir_installed = 1; > } else { > plan skip_all => '"xdg-user-dir" executable not found. Install > package "xdg-user-dirs".'; > > } > > On Sat Apr 18 22:12:20 2015, KIMRYAN wrote:
> > Thanks for pointing out this bug. I think this is the change required > > to get it working. > > > > my $xdg_user_dir_installed = 0; > > if (which 'xdg-user-dir') { > > plan tests => 8; > > $xdg_user_dir_installed = 0; > > } else { > > plan skip_all => '"xdg-user-dir" executable not found. Install > > package "xdg-user-dirs".'; > > $xdg_user_dir_installed = 1; > > > > } > > > > Agree it is not good practice to be altering config file contents > > during test phase. I adopted this module as it had been abandoned, > > and > > applied several old patches. This includes the 03_userdirs.t test. > > It > > relies on running the xdg-user-dir binary, which doesn't seem like a > > good thing to put into a CPAN test suite. But I don't really have the > > time or knowledge to try and unravel all this code. So if you think > > above fix is enough, I can apply that.
Subject: File-BaseDir-0.06-RT103805.patch
diff --git i/t/03_userdirs.t w/t/03_userdirs.t index d28f344..0302c7b 100644 --- i/t/03_userdirs.t +++ w/t/03_userdirs.t @@ -6,6 +6,7 @@ use File::UserDirs qw(:all); use File::BaseDir qw(config_home); use File::Spec::Functions qw(catfile); use File::Which qw(which); +use File::Temp qw(tempdir); my $xdg_user_dir_installed = 0; if (which 'xdg-user-dir') { @@ -16,10 +17,10 @@ if (which 'xdg-user-dir') { } -my $udd = config_home('user-dirs.dirs'); -if (-e $udd) { - rename $udd, "$udd~" or die "could not make backup of $udd: $!"; -} +my $temphomedir = tempdir(CLEANUP => 1); +local $ENV{HOME} = $temphomedir; +mkdir "$temphomedir/.config"; +my $udd = "$temphomedir/.config/user-dirs.dirs"; open my $fh, '>', $udd or die "could not open $udd for writing: $!"; print $fh <<'UDD'; @@ -43,12 +44,3 @@ is xdg_publicshare_dir, catfile($ENV{HOME}, 'public_html'); is xdg_templates_dir, catfile($ENV{HOME}, 'Files/Document templates'); is xdg_videos_dir, catfile($ENV{HOME}, 'Files/Video'); -END { - if ($xdg_user_dir_installed) { - if (-e "$udd~") { - rename "$udd~", $udd or die "could not restore backup of $udd: $!"; - } else { - unlink $udd or die "could not delete $udd: $!"; - } - } -} \ No newline at end of file
Looks like it is passing all tests now at CPAN Testers.