Dpkg_BuildOptions.t 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #!/usr/bin/perl
  2. #
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 2 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. use strict;
  16. use warnings;
  17. use Test::More tests => 28;
  18. use Dpkg::ErrorHandling;
  19. use_ok('Dpkg::BuildOptions');
  20. {
  21. no warnings; ## no critic (TestingAndDebugging::ProhibitNoWarnings)
  22. # Disable warnings related to invalid values fed during
  23. # the tests
  24. report_options(quiet_warnings => 1);
  25. }
  26. $ENV{DEB_BUILD_OPTIONS} = 'noopt foonostripbar parallel=3 bazNOCHECK';
  27. my $dbo = Dpkg::BuildOptions->new();
  28. ok($dbo->has('noopt'), 'has noopt');
  29. is($dbo->get('noopt'), undef, 'noopt value');
  30. ok($dbo->has('foonostripbar'), 'has foonostripbar');
  31. is($dbo->get('foonostripbar'), undef, 'foonostripbar value');
  32. ok($dbo->has('parallel'), 'has parallel');
  33. is($dbo->get('parallel'), 3, 'parallel value');
  34. ok(!$dbo->has('bazNOCHECK'), 'not has bazNOCHECK');
  35. $dbo->reset();
  36. $dbo->merge('no opt no-strip parallel = 5 nocheck', 'test');
  37. ok($dbo->has('no'), 'has no');
  38. is($dbo->get('no'), undef, 'no value');
  39. ok($dbo->has('opt'), 'has opt');
  40. is($dbo->get('opt'), undef, 'opt value');
  41. ok($dbo->has('no-strip'), 'has no-strip');
  42. is($dbo->get('no-strip'), undef, 'no-strip value');
  43. ok($dbo->has('parallel'), 'has parallel');
  44. is($dbo->get('parallel'), '', 'parallel value');
  45. ok($dbo->has('nocheck'), 'has nocheck');
  46. is($dbo->get('nocheck'), undef, 'nocheck value');
  47. $dbo->reset();
  48. $dbo->set('parallel', 5);
  49. $dbo->set('noopt', undef);
  50. my $env = $dbo->export();
  51. is($env, 'noopt parallel=5', 'value of export');
  52. is($ENV{DEB_BUILD_OPTIONS}, $env, 'env match return value of export');
  53. $env = $dbo->export('OTHER_VARIABLE');
  54. is($ENV{OTHER_VARIABLE}, $env, 'export to other variable');
  55. $ENV{DEB_BUILD_OPTIONS} = 'foobar';
  56. $dbo = Dpkg::BuildOptions->new();
  57. $dbo->set('noopt', 1);
  58. is($dbo->output(), 'foobar noopt', 'output');
  59. $dbo = Dpkg::BuildOptions->new(envvar => 'OTHER_VARIABLE');
  60. is($dbo->get('parallel'), 5, 'import from other variable, check parallel');
  61. ok($dbo->has('noopt'), 'import from other variable, check noopt');
  62. my %theme = (
  63. metal => undef,
  64. pink => undef,
  65. rusty => undef,
  66. sky => undef,
  67. );
  68. my %theme_ref;
  69. $dbo = Dpkg::BuildOptions->new();
  70. $theme_ref{$_} = 1 foreach keys %theme;
  71. $dbo->set('theme', '+all');
  72. $dbo->parse_features('theme', \%theme);
  73. is_deeply(\%theme, \%theme_ref, 'features set with +all');
  74. $theme{$_} = undef foreach keys %theme;
  75. $theme_ref{$_} = 1 foreach keys %theme;
  76. $theme_ref{rusty} = 0;
  77. $dbo->set('theme', '+all,-rusty');
  78. $dbo->parse_features('theme', \%theme);
  79. is_deeply(\%theme, \%theme_ref, 'features set with +all,-rusty');
  80. $theme{$_} = undef foreach keys %theme;
  81. $theme_ref{$_} = 0 foreach keys %theme;
  82. $theme_ref{metal} = 1;
  83. $dbo->set('theme', '-all,+metal');
  84. $dbo->parse_features('theme', \%theme);
  85. is_deeply(\%theme, \%theme_ref, 'features set with +all,-rusty');
  86. $theme{$_} = $theme_ref{$_} = undef foreach keys %theme;
  87. $theme_ref{pink} = 1;
  88. $theme_ref{sky} = 0;
  89. $dbo->set('theme', '+pink,-sky');
  90. $dbo->parse_features('theme', \%theme);
  91. is_deeply(\%theme, \%theme_ref, 'features set with +pink,-sky');