|
| 1 | +# This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | +# License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | +# file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 4 | +# |
| 5 | +# This Source Code Form is "Incompatible With Secondary Licenses", as |
| 6 | +# defined by the Mozilla Public License, v. 2.0. |
| 7 | + |
| 8 | + |
| 9 | +################## |
| 10 | +#Bugzilla Test 15# |
| 11 | +####Productform### |
| 12 | + |
| 13 | +use 5.14.0; |
| 14 | +use strict; |
| 15 | +use warnings; |
| 16 | + |
| 17 | +use File::Spec; |
| 18 | +use Test::More; |
| 19 | + |
| 20 | +my $node; |
| 21 | +foreach my $dir (File::Spec->path()) { |
| 22 | + foreach my $name (qw(node nodejs node.exe)) { |
| 23 | + my $path = File::Spec->catfile($dir, $name); |
| 24 | + if (-x $path && !-d $path) { |
| 25 | + $node = $path; |
| 26 | + last; |
| 27 | + } |
| 28 | + } |
| 29 | + last if $node; |
| 30 | +} |
| 31 | + |
| 32 | +if (!$node && $ENV{BZ_REQUIRE_NODE}) { |
| 33 | + plan tests => 1; |
| 34 | + fail('Node.js is required to test js/productform.js'); |
| 35 | + exit; |
| 36 | +} |
| 37 | + |
| 38 | +plan skip_all => 'Node.js is required to test js/productform.js' if !$node; |
| 39 | + |
| 40 | +my $script = <<'JS'; |
| 41 | +var fs = require('fs'); |
| 42 | +var vm = require('vm'); |
| 43 | +
|
| 44 | +vm.runInThisContext( |
| 45 | + fs.readFileSync('js/productform.js', 'utf8'), |
| 46 | + { filename: 'js/productform.js' } |
| 47 | +); |
| 48 | +
|
| 49 | +console.log( |
| 50 | + merge_arrays( |
| 51 | + ['Trunk', '2.0'], |
| 52 | + ['unspecified', 'Trunk'], |
| 53 | + false |
| 54 | + ).join('\t') |
| 55 | +); |
| 56 | +console.log( |
| 57 | + merge_arrays( |
| 58 | + ['Beta', 'alpha'], |
| 59 | + [{ value: 'ALPHA' }, { value: 'Release' }], |
| 60 | + true |
| 61 | + ).join('\t') |
| 62 | +); |
| 63 | +JS |
| 64 | + |
| 65 | +my $pid = open(my $fh, '-|', $node, '-e', $script); |
| 66 | +if (!defined $pid) { |
| 67 | + plan tests => 1; |
| 68 | + fail("could not run $node: $!"); |
| 69 | + exit; |
| 70 | +} |
| 71 | + |
| 72 | +my @results = <$fh>; |
| 73 | +close($fh); |
| 74 | +my $status = $?; |
| 75 | + |
| 76 | +if ($status || @results != 2) { |
| 77 | + plan tests => 1; |
| 78 | + fail('js/productform.js did not produce the expected test output'); |
| 79 | + diag("Node.js exit status: $status"); |
| 80 | + diag("Node.js output:\n" . join('', @results)); |
| 81 | + exit; |
| 82 | +} |
| 83 | + |
| 84 | +chomp(@results); |
| 85 | +plan tests => 2; |
| 86 | + |
| 87 | +is_deeply( |
| 88 | + [split(/\t/, $results[0])], |
| 89 | + ['2.0', 'Trunk', 'unspecified'], |
| 90 | + 'unsorted product values are sorted and de-duplicated' |
| 91 | +); |
| 92 | +is_deeply( |
| 93 | + [split(/\t/, $results[1])], |
| 94 | + ['alpha', 'Beta', 'Release'], |
| 95 | + 'select options are merged, sorted, and de-duplicated' |
| 96 | +); |
0 commit comments