summaryrefslogtreecommitdiffstats
path: root/solenv
diff options
context:
space:
mode:
authorTim Retout <tim@retout.co.uk>2012-09-30 13:23:43 +0100
committerTim Retout <tim@retout.co.uk>2012-09-30 16:50:55 +0100
commit5cc1d5ca954a594129bd81159a87f8dfb9bbffe7 (patch)
treea1e192349228854c1e22f192e4559b0e729b143b /solenv
parentinstaller: Create new read_ziplist function. (diff)
downloadcore-5cc1d5ca954a594129bd81159a87f8dfb9bbffe7.tar.gz
core-5cc1d5ca954a594129bd81159a87f8dfb9bbffe7.zip
installer::profiles: Test and rewrite sorting_profile
Change-Id: Ie3c9bddcb4760d2fe2195c1ca0de7520e57d705f
Diffstat (limited to 'solenv')
-rw-r--r--solenv/bin/modules/installer/profiles.pm45
-rw-r--r--solenv/bin/modules/t/installer-profiles.t60
2 files changed, 79 insertions, 26 deletions
diff --git a/solenv/bin/modules/installer/profiles.pm b/solenv/bin/modules/installer/profiles.pm
index 7b621f70a78d..3b99973a92a4 100644
--- a/solenv/bin/modules/installer/profiles.pm
+++ b/solenv/bin/modules/installer/profiles.pm
@@ -42,40 +42,33 @@ use installer::systemactions;
# Sorting the content of a profile
#######################################################
-sub sorting_profile
-{
+sub sorting_profile {
my ($profilesref) = @_;
- my @profile = ();
- my @definedsections = ();
+ my @sections;
+ my %section_content;
- for ( my $i = 0; $i <= $#{$profilesref}; $i++ )
- {
+ for ( my $i = 0; $i < @{$profilesref}; $i++ ) {
my $line = ${$profilesref}[$i];
- if ( $line =~ /^\s*(\[.*\])\s*$/ ) # this is a section (every second line)
- {
- my $section = $1;
+ # Skip unless this is a section (every second line)
+ next unless ( $line =~ /^\s*(\[.*\])\s*$/ );
- if (! grep {$_ eq $section} @definedsections)
- {
- my $sectionline = $section . "\n";
- push(@definedsections, $section);
- push(@profile, $sectionline);
+ my $section = $1;
+ my $next_line = ${$profilesref}[$i+1];
- for ( my $j = 0; $j <= $#{$profilesref}; $j++ )
- {
- my $oneline = ${$profilesref}[$j];
- installer::remover::remove_leading_and_ending_whitespaces(\$oneline);
-
- if ( $oneline eq $section )
- {
- my $nextline = ${$profilesref}[$j+1];
- push(@profile, $nextline);
- }
- }
- }
+ if ( ! exists $section_content{$section} ) {
+ push @sections, $section;
}
+
+ push @{ $section_content{$section} }, $next_line;
+ }
+
+ my @profile;
+
+ for my $section (@sections) {
+ push @profile, "$section\n";
+ push @profile, @{ $section_content{$section} };
}
return \@profile;
diff --git a/solenv/bin/modules/t/installer-profiles.t b/solenv/bin/modules/t/installer-profiles.t
new file mode 100644
index 000000000000..841af1458e85
--- /dev/null
+++ b/solenv/bin/modules/t/installer-profiles.t
@@ -0,0 +1,60 @@
+# Version: MPL 1.1 / GPLv3+ / LGPLv3+
+#
+# The contents of this file are subject to the Mozilla Public License Version
+# 1.1 (the "License"); you may not use this file except in compliance with
+# the License or as specified alternatively below. You may obtain a copy of
+# the License at http://www.mozilla.org/MPL/
+#
+# Software distributed under the License is distributed on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+# for the specific language governing rights and limitations under the
+# License.
+#
+# Major Contributor(s):
+# [ Copyright (C) 2012 Tim Retout <tim@retout.co.uk> (initial developer) ]
+#
+# All Rights Reserved.
+#
+# For minor contributions see the git repository.
+#
+# Alternatively, the contents of this file may be used under the terms of
+# either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+# the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+# in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+# instead of those above.
+
+use strict;
+use warnings;
+
+use Test::More;
+
+use lib '.';
+
+use installer::profiles;
+
+my @input = map { "$_\n" } split "\n", <<'END';
+ [foo]
+1
+NOT SEEN
+ [bar]
+3
+ [foo]
+2
+[bar]
+4
+END
+
+my @expected = map { "$_\n" } split "\n", <<'END';
+[foo]
+1
+2
+[bar]
+3
+4
+END
+
+my $result = installer::profiles::sorting_profile(\@input);
+
+is_deeply($result, \@expected);
+
+done_testing();