300_Dpkg_BuildOptions.t 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 <http://www.gnu.org/licenses/>.
  15. use Test::More tests => 24;
  16. use Dpkg::ErrorHandling;
  17. use strict;
  18. use warnings;
  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");