Dpkg_BuildOptions.t 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 => 24;
  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');