-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_run_commands.py
155 lines (148 loc) · 4.38 KB
/
test_run_commands.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
from run_commands import (
GRADLE_BUILD_REGEX,
JAVAC_BUILD_REGEX,
JS_BUILD_REGEX,
MAKE_BUILD_REGEX,
MAVEN_BUILD_REGEX,
PYTHON_BUILD_REGEX,
RUBY_BUILD_REGEX,
match_cmd_regex
)
VALID = 'valid'
INVALID = 'invalid'
TESTS = {
VALID: {
JS_BUILD_REGEX: [
'npm install',
'npm install --arg',
'/mypath/npm install --arg'
'npm ci',
'./npm ci',
'npm ci --ignore-scripts --no-audit --no-progress --prefer-offline',
'npm test',
'npm run build',
'npm run ci',
'npm run test'
],
GRADLE_BUILD_REGEX: [
'gradle build',
'./gradlew clean build -x test publishPlugins',
'gradle test'
],
MAVEN_BUILD_REGEX: [
'mvn clean install',
'/mypath/mvn install',
'mvn -s .m2/settings.xml -gs .m2/settings.xml -B package',
'mvn -B package --file pom.xml',
'mvn -B clean install -T2 -Prelease --file mypath/pom.xml -Dspotless.apply.skip=true',
'mvn -V -B -U --no-transfer-progress clean verify -DskipITs=false',
'mvn test',
'mvn compile'
],
MAKE_BUILD_REGEX: [
'cmake',
'make',
'/mypath/make',
'mypath/cmake',
'make --arg',
' cmake --build . --config $BUILD_TYPE',
'blah cmake -S fltk -B fltk/build blah',
'cmake -E make_directory ${{runner.workspace}}/build'
],
JAVAC_BUILD_REGEX: [
'javac',
'./javac --arg'
],
RUBY_BUILD_REGEX: [
'rake',
'./path/rake',
'rake arg',
'bundle install',
'../mypath/bundle install',
'./rake --args',
'bundle exec rspec mypath/spec.rb',
'bundle install --jobs 4 --retry 3'
],
PYTHON_BUILD_REGEX: [
'pip install pytest pytest-randomly pytest-cov'
'pip install -r requirements.txt',
'pip install --upgrade -r requirements.txt',
'python -m venv venv',
'python2 -c "from this import that; print(that)"',
'python setup.py patch_version --platform=$Env:BUILD_NUMBER.$(git rev-parse --short HEAD)',
'python3 setup.py test',
'python3 -m pip install --upgrade pip setuptools wheel',
'pytest --verbose test/mytest.py',
'/mypath/pytest mypath/test'
]
},
INVALID: {
JS_BUILD_REGEX: [
'gpm install',
'npm cia',
'npms install',
'npm finstall',
'npm run random',
'npm run install'
],
GRADLE_BUILD_REGEX: [
'dgradle build',
'./gradlef clean build',
'gradles build',
'gradle tester',
'gradle debuild',
],
MAVEN_BUILD_REGEX: [
'maven',
'dmvn',
'mvnz',
'mvn random',
'mvn dinstall',
'mvn installf'
],
MAKE_BUILD_REGEX: [
'cmaker',
'dmake'
],
JAVAC_BUILD_REGEX: [
'./myjavac',
'javacc',
'djavac'
],
RUBY_BUILD_REGEX: [
'raker',
'drake',
'bundle dinstall',
'dbundle install'
'bundle installer',
'bunlder install'
],
PYTHON_BUILD_REGEX: [
'pipd install',
'dpip install',
'pip dinstall',
'pip installer',
'python4',
'apython',
'pytesta',
'apytest'
]
}
}
def run_tests():
print('Running tests for run_commands...')
num_failed = 0
for validity in [VALID, INVALID]:
should_be_match = True if validity == VALID else False
for regexp, test_cmds in TESTS[validity].items():
for cmd in test_cmds:
is_match = match_cmd_regex(regexp, cmd)
if is_match != should_be_match:
print(f"Should be {validity}: {cmd}")
num_failed += 1
if num_failed == 0:
print('Test summary: All tests passed!')
else:
print(f"Test summary: {num_failed} tests failed!")
if __name__ == "__main__":
run_tests()