300_Dpkg_BuildOptions.t 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #
  2. # This program is free software; you can redistribute it and/or modify
  3. # it under the terms of the GNU General Public License as published by
  4. # the Free Software Foundation; either version 2 of the License, or
  5. # (at your option) any later version.
  6. #
  7. # This program is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. # GNU General Public License for more details.
  11. #
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. use Test::More tests => 24;
  15. use Dpkg::ErrorHandling;
  16. use strict;
  17. use warnings;
  18. use_ok('Dpkg::BuildOptions');
  19. {
  20. no warnings;
  21. # Disable warnings related to invalid values fed during
  22. # the tests
  23. report_options(quiet_warnings => 1);
  24. }
  25. $ENV{DEB_BUILD_OPTIONS} = 'noopt foonostripbar parallel=3 bazNOCHECK';
  26. my $dbo = Dpkg::BuildOptions->new();
  27. ok($dbo->has("noopt"), "has noopt");
  28. is($dbo->get("noopt"), undef, "noopt value");
  29. ok($dbo->has("foonostripbar"), "has foonostripbar");
  30. is($dbo->get("foonostripbar"), undef, "foonostripbar value");
  31. ok($dbo->has("parallel"), "has parallel");
  32. is($dbo->get("parallel"), 3, "parallel value");
  33. ok(!$dbo->has("bazNOCHECK"), "not has bazNOCHECK");
  34. $dbo->reset();
  35. $dbo->merge('no opt no-strip parallel = 5 nocheck', 'test');
  36. ok($dbo->has('no'), "has no");
  37. is($dbo->get('no'), undef, "no value");
  38. ok($dbo->has('opt'), "has opt");
  39. is($dbo->get('opt'), undef, "opt value");
  40. ok($dbo->has('no-strip'), "has no-strip");
  41. is($dbo->get('no-strip'), undef, "no-strip value");
  42. ok($dbo->has('parallel'), "has parallel");
  43. is($dbo->get('parallel'), '', "parallel value");
  44. ok($dbo->has('nocheck'), "has nocheck");
  45. is($dbo->get('nocheck'), undef, "nocheck value");
  46. $dbo->reset();
  47. $dbo->set('parallel', 5);
  48. $dbo->set('noopt', undef);
  49. my $env = $dbo->export();
  50. is($env, "noopt parallel=5", "value of export");
  51. is($ENV{DEB_BUILD_OPTIONS}, $env, 'env match return value of export');
  52. $env = $dbo->export("OTHER_VARIABLE");
  53. is($ENV{OTHER_VARIABLE}, $env, 'export to other variable');
  54. $ENV{DEB_BUILD_OPTIONS} = 'foobar';
  55. $dbo = Dpkg::BuildOptions->new();
  56. $dbo->set("noopt", 1);
  57. is($dbo->output(), "foobar noopt", "output");
  58. $dbo = Dpkg::BuildOptions->new(envvar => "OTHER_VARIABLE");
  59. is($dbo->get("parallel"), 5, "import from other variable, check parallel");
  60. ok($dbo->has("noopt"), "import from other variable, check noopt");