1 | <?php |
---|
2 | |
---|
3 | // Simple single-file doc validation utility, using our php-based `jsdoc` parser. |
---|
4 | // To be used as a post-commit hook? |
---|
5 | // |
---|
6 | // to use: |
---|
7 | // php -q parsefile.php dojox/data/AndOrReadStore.js |
---|
8 | // |
---|
9 | // exits normally (status 0) if OK, with status 255 if failed, other values are from PHP untrapped. |
---|
10 | // |
---|
11 | // add --debug to last argument to see output data, eg: |
---|
12 | // |
---|
13 | // php -q parsefile.php dijit/_Widget.js --debug |
---|
14 | // |
---|
15 | // scan all files prior to running generate/makeCix (considerably faster to detect fatal parser-breaking errors) |
---|
16 | // |
---|
17 | // php -q parsefile.php --all |
---|
18 | |
---|
19 | include_once('lib/parser2/dojo2.inc'); |
---|
20 | $allfiles = dojo_get_files(); |
---|
21 | |
---|
22 | function doc_passes($ns, $file, $debug){ |
---|
23 | try{ |
---|
24 | $ret = doc_test($ns, $file, $debug); |
---|
25 | return $ret; |
---|
26 | }catch (Exception $e){ |
---|
27 | return false; |
---|
28 | } |
---|
29 | } |
---|
30 | |
---|
31 | function doc_test($ns, $file, $debug){ |
---|
32 | // the testing of a single file. this is where the actual testing goes. |
---|
33 | |
---|
34 | try{ |
---|
35 | $ret = true; |
---|
36 | $data = dojo_get_contents($ns, $file); |
---|
37 | // test other things. like we're expecting at the _very_ least a $data['#provides'] key? |
---|
38 | if(empty($data['#provides'])){ |
---|
39 | if($debug){ |
---|
40 | print "Warning: no provide() determined. [" . $ns . "/" . $file . "]\n"; |
---|
41 | } |
---|
42 | $ret = false; |
---|
43 | }else{ |
---|
44 | if(count($data['#provides']) > 1){ |
---|
45 | if($debug){ |
---|
46 | print "Warning: Multiple provides() found?\n"; |
---|
47 | $ret = false; |
---|
48 | } |
---|
49 | } |
---|
50 | } |
---|
51 | |
---|
52 | if(count($data) == 0){ |
---|
53 | if($debug){ print "Error: No data found. [" . $ns . "/" . $file . "]"; } |
---|
54 | $ret = false; |
---|
55 | }else{ |
---|
56 | |
---|
57 | } |
---|
58 | |
---|
59 | return $ret; |
---|
60 | }catch (Exception $e){ |
---|
61 | print "Error: Exception trapped processing [" . $ns . "/" . $file . "]\nException:\n"; |
---|
62 | print $e; |
---|
63 | return false; |
---|
64 | } |
---|
65 | } |
---|
66 | |
---|
67 | if($argc){ |
---|
68 | |
---|
69 | $argfile = $argv[1]; |
---|
70 | $debug = in_array("--debug", $argv); |
---|
71 | if($argfile == "--all"){ |
---|
72 | |
---|
73 | $debug = true; |
---|
74 | $haserror = false; |
---|
75 | foreach($allfiles as $set){ |
---|
76 | list($ns, $file) = $set; |
---|
77 | if(!doc_passes($ns, $file, $debug)){ |
---|
78 | $haserror = true; |
---|
79 | } |
---|
80 | } |
---|
81 | |
---|
82 | if($haserror){ |
---|
83 | die(255); |
---|
84 | } |
---|
85 | |
---|
86 | }else{ |
---|
87 | |
---|
88 | $parts = explode("/", $argfile); |
---|
89 | $ns = array_shift($parts); |
---|
90 | $file = implode("/", $parts); |
---|
91 | if(!doc_passes($ns, $file, $debug)){ |
---|
92 | die(255); |
---|
93 | } |
---|
94 | |
---|
95 | } |
---|
96 | |
---|
97 | } |
---|