~ubuntu-branches/ubuntu/natty/libconfig-inifiles-perl/natty-updates

« back to all changes in this revision

Viewing changes to t/22trailing-comment-lines.t

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2009-05-31 14:54:35 UTC
  • mto: This revision was merged to the branch mainline in revision 6.
  • Revision ID: james.westby@ubuntu.com-20090531145435-qhm9d2a09lz0qdbs
Tags: upstream-2.49
ImportĀ upstreamĀ versionĀ 2.49

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
 
 
3
# This script attempts to reproduce:
 
4
# https://rt.cpan.org/Ticket/Display.html?id=30402
 
5
#
 
6
# #30402: WriteConfig does not write the last lines of a file if they are comments
 
7
 
 
8
use Test::More tests => 1;
 
9
 
 
10
use strict;
 
11
use warnings;
 
12
 
 
13
use File::Spec;
 
14
 
 
15
use Config::IniFiles;
 
16
 
 
17
{
 
18
    my $conf = Config::IniFiles->new(
 
19
        -file => File::Spec->catfile(File::Spec->curdir(), 't', 'trailing-comments.ini')
 
20
    );
 
21
 
 
22
    my $new_file = File::Spec->catfile(
 
23
        File::Spec->curdir(), 't', 'new-trail.ini'
 
24
    );
 
25
 
 
26
    $conf->WriteConfig($new_file);
 
27
 
 
28
    my $buffer;
 
29
    {
 
30
        local $/;
 
31
        open my $fh, "<", $new_file;
 
32
        $buffer = <$fh>;
 
33
        close($fh);
 
34
    }
 
35
 
 
36
    # TEST
 
37
    like(
 
38
        $buffer,
 
39
        qr{; End Comment 1\n; End Comment 2\n+\z}ms,
 
40
        "WriteConfig() Preserved end comments."
 
41
    );
 
42
 
 
43
    # Remove the generated files so they won't pollute the filesystem / 
 
44
    # working-copy.
 
45
    unlink($new_file);
 
46
}
 
47