1
# Copyright (C) 2009 Sun Microsystems, Inc. All rights reserved. Use
2
# is subject to license terms.
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; version 2 of the License.
8
# This program is distributed in the hope that it will be useful, but
9
# WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
# General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
19
# Walk through all the grammars and feed them to the Grammar
22
package ParseAllGrammars;
23
use base qw(Test::Unit::TestCase);
26
use GenTest::Executor;
27
use GenTest::Executor::Dummy;
28
use GenTest::Generator::FromGrammar;
30
use Digest::SHA1 qw(sha1_base64);
35
my $self = shift()->SUPER::new(@_);
36
# your state for fixture here
50
if ($File::Find::name =~ m/\.yy$/) {
51
push(@files, $File::Find::name);
58
find(\&isGrammar, ("conf"));
59
my @filesToTest = sort(@files);
60
if (defined $ENV{RQG_OTHER_GRAMMAR_DIR}) {
62
find(\&isGrammar, ($ENV{RQG_OTHER_GRAMMAR_DIR}));
63
@filesToTest = (@filesToTest, sort(@files));
65
#@files = sort((@files));
67
foreach $f (@filesToTest) {
68
my $grammar = new GenTest::Grammar(grammar_file => $f);
69
$self->assert_not_null($grammar, "Grammar was null: $f");
71
# Skip further checks of redefine files, recognized by "_redefine." in
72
# file name. These files can contain just a subset of a grammar, so
73
# there is no point looking for a specific grammar rule.
74
my $redefine_file = undef;
75
if ($f =~ m{_redefine\.}) {
79
if (!defined $redefine_file) {
81
my $startRule = $grammar->firstMatchingRule("query");
82
$self->assert_not_null($startRule, '"query" rule was null in '.$f);
83
my $executor = GenTest::Executor->newFromDSN("dummy");
84
$self->assert_not_null($executor);
86
$executor->cacheMetaData();
87
my $generator = GenTest::Generator::FromGrammar->new(
91
$self->assert_not_null($generator);
93
$generator->next([$executor,undef]);
102
my ($self, $file, $hash) = @_;
103
my $executor = GenTest::Executor->newFromDSN("dummy");
104
$self->assert_not_null($executor);
106
$executor->cacheMetaData();
107
my $generator = GenTest::Generator::FromGrammar->new(
108
grammar_file => $file,
112
$self->assert_not_null($generator);
114
foreach $i (1..1000) {
115
$data .= $generator->next([$executor,undef])->[0];
117
my $newhash =sha1_base64($data);
118
$self->assert_str_equals($newhash,$hash,"'$newhash' different from '$hash'. Generator or grammar changed for $file");
123
## Test stability of selected grammars
125
$self->isStable("conf/examples/example.yy",
126
"GVRJcbOKijEUdJQjuor4upMdzDo");