15
15
*/
16
16
17
17
/* This file is to help line up the formal conditions listed in source with tests.
18
- * I look for `sourceGrep` and `testGrep` make make sure that the conditions found,
19
- * are in both sets.
20
- */
18
+ * I look for `sourceGrep` and `testGrep` make make sure that the conditions found,
19
+ * are in both sets.
20
+ */
21
21
22
22
const { exec } = require ( 'child_process' )
23
23
const { promisify } = require ( 'util' )
24
24
const execAsync = promisify ( exec )
25
25
26
- const sourceGrep = 'grep -E \'Precondition|Postcondition\' modules/**/src/*.ts'
27
- const testGrep = 'grep -E \'Precondition|Postcondition\' modules/**/test/*.ts'
26
+ const ignoreIssueCount = parseInt ( process . argv [ 2 ] || 0 , 10 )
27
+
28
+ const sourceGrep = 'grep -E \'Precondition:|Postcondition(:|\\):)\' modules/**/src/*.ts'
29
+ const testGrep = 'grep -E \'Precondition:|Postcondition(:|\\):)\' modules/**/test/*.ts'
28
30
29
31
Promise . all ( [
30
32
execAsync ( sourceGrep ) . then ( clean ) ,
@@ -36,12 +38,15 @@ Promise.all([
36
38
const testSet = new Set ( flatMapForTests ( tests ) )
37
39
38
40
if ( source . length > sourceSet . size ) {
39
- console . log ( 'Duplicate source conditions' , getDuplicates ( source ) )
40
- issues += 1
41
+ const duplicateSources = getDuplicates ( source )
42
+ console . log ( 'Duplicate source conditions' , duplicateSources )
43
+ issues += duplicateSources . length
41
44
}
42
- if ( tests . length > testSet . size ) {
43
- console . log ( 'Duplicate test conditions' , getDuplicates ( tests ) )
44
- issues += 1
45
+ // A single test _may_ be multiple conditions.
46
+ const duplicateTests = getDuplicates ( tests )
47
+ if ( duplicateTests . length ) {
48
+ console . log ( 'Duplicate test conditions' , duplicateTests )
49
+ issues += duplicateTests . length
45
50
}
46
51
47
52
for ( const sourceCondition of sourceSet ) {
@@ -58,12 +63,16 @@ Promise.all([
58
63
}
59
64
}
60
65
61
- process . exit ( issues )
66
+ if ( issues ) {
67
+ console . error ( `Issue count found: ${ issues } ` )
68
+ }
69
+
70
+ process . exit ( Math . max ( 0 , issues - ignoreIssueCount ) )
62
71
} )
63
72
64
- const remove = / ( \* \/ ) | ( \/ \* ) | ( i t \( ' ) | ( ' , \( \) = > \{ ) | ( ' , a s y n c \( \) = > \{ ) / g
73
+ const remove = / ( \* \/ ) | ( \/ \* ) | ( i t \( [ ` ' ] ) | ( [ ` ' ] , \( \) = > \{ ) | ( [ ` ' ] , a s y n c \( \) = > \{ ) / g
65
74
66
- function clean ( { stdout, stderr } ) {
75
+ function clean ( { stdout } ) {
67
76
return stdout . split ( '\n' )
68
77
. map ( l => l . replace ( remove , '' ) )
69
78
// Do not try and clean up ' and things like that...
0 commit comments