@@ -19,36 +19,85 @@ SONAR_PLUGINS_TMPL = os.path.join(SONAR_HOME, "sonarqube-%s", "extensions", "plu
1919SONAR_ERROR_RE = re .compile (".* ERROR .*" )
2020SONAR_WARN_RE = re .compile (".* WARN .*" )
2121INDENT = " "
22- PROJECT_KEY = "smoketest_project_1"
23- PROJECT_PATH = "../resources/org/sonar/plugins/python/smoketest_project_1"
2422BASEDIR = os .path .dirname (os .path .realpath (__file__ ))
25- JAR_PATH = os .path .normpath (glob (os .path .join (BASEDIR , "../../../target/*SNAPSHOT.jar" ))[0 ])
26-
27-
28- EXP_MEASURES = {
29- "ncloc" : 32.0 ,
30- "lines" : 47.0 ,
31- "files" : 4.0 ,
32- "directories" : 2.0 ,
33- "functions" : 7.0 ,
34- "comment_lines_density" : 5.9 ,
35- "comment_lines" : 2.0 ,
36- "duplicated_lines_density" : 80.9 ,
37- "duplicated_lines" : 38 ,
38- "duplicated_blocks" : 2 ,
39- "duplicated_files" : 2 ,
40- "complexity" : 15.0 ,
41- "function_complexity" : 2.1 ,
42- "violations" : 3 ,
43- "violations_density" : 71.9 ,
44- "coverage" : 43.5 ,
45- "line_coverage" : 36.8 ,
46- "branch_coverage" : 75.0 ,
47- "test_success_density" : 33.3 ,
48- "test_failures" : 1.0 ,
49- "test_errors" : 1.0 ,
50- "tests" : 3.0
51- }
23+ JAR_PATH = os .path .normpath (glob (os .path .join (BASEDIR , "../sonar-python-plugin/target/*SNAPSHOT.jar" ))[0 ])
24+
25+ TEST_PROJECTS_HOME = "testdata"
26+
27+ TEST_PROJECTS = [
28+ # ("smoketest_project_1",
29+ # ["-X"],
30+ # {
31+ # "ncloc": 32.0,
32+ # "lines": 47.0,
33+ # "files": 4.0,
34+ # "directories": 2.0,
35+ # "functions": 7.0,
36+ # "comment_lines_density": 5.9,
37+ # "comment_lines": 2.0,
38+ # "duplicated_lines_density": 80.9,
39+ # "duplicated_lines": 38,
40+ # "duplicated_blocks": 2,
41+ # "duplicated_files": 2,
42+ # "complexity": 15.0,
43+ # "function_complexity": 2.1,
44+ # "violations": 3,
45+ # "violations_density": 71.9,
46+ # "coverage": 43.5,
47+ # "line_coverage": 36.8,
48+ # "branch_coverage": 75.0,
49+ # "test_success_density": 33.3,
50+ # "test_failures": 1.0,
51+ # "test_errors": 1.0,
52+ # "tests": 3.0
53+ # }
54+ # ),
55+ ("smoketest_project_2" ,
56+ ["-X" , "-Dsonar.python.xunit.skipDetails=true" ],
57+ {
58+ "tests" : 3.0 ,
59+ "test_failures" : 1.0 ,
60+ "test_errors" : 1.0 ,
61+ "skipped_tests" : 1.0 ,
62+ "test_success_density" : 33.3 ,
63+ "test_execution_time" : 1.0 ,
64+ }
65+ ),
66+ ("smoketest_project_2" ,
67+ ["-X" , "-Dsonar.python.xunit.skipDetails=false" ],
68+ {
69+ "tests" : 3.0 ,
70+ "test_failures" : 1.0 ,
71+ "test_errors" : 1.0 ,
72+ "skipped_tests" : 1.0 ,
73+ "test_success_density" : 33.3 ,
74+ "test_execution_time" : 1.0 ,
75+ }
76+ ),
77+ ("smoketest_project_3" ,
78+ ["-X" , "-Dsonar.python.xunit.skipDetails=true" ],
79+ {
80+ "tests" : 6.0 ,
81+ "test_failures" : 2.0 ,
82+ "test_errors" : 2.0 ,
83+ "skipped_tests" : 2.0 ,
84+ "test_success_density" : 33.3 ,
85+ "test_execution_time" : 13.0 ,
86+ }
87+ ),
88+ ("smoketest_project_3" ,
89+ ["-X" , "-Dsonar.python.xunit.skipDetails=false" ],
90+ {
91+ "tests" : 3.0 ,
92+ "test_failures" : 1.0 ,
93+ "test_errors" : 1.0 ,
94+ "skipped_tests" : 1.0 ,
95+ "test_success_density" : 33.3 ,
96+ "test_execution_time" : 7.0 ,
97+ }
98+ )
99+ ]
100+
52101
53102RED = ""
54103GREEN = ""
@@ -67,16 +116,22 @@ except ImportError:
67116 pass
68117
69118
70- def test_bootup (version ):
71- print (BRIGHT + "\n Running smoke test for Sonar %s" % version + RESET_ALL )
119+ def runtests (version ):
120+ print (BRIGHT + "\n Running integration test for Sonar %s" % version + RESET_ALL )
72121
73122 if is_installed (version ):
74123 cleanup (version )
75124 install_plugin (version )
76125 started = start_sonar (version )
77126 logsOK = checkSonarLogs (version )
78- analysisFinishedOk = runAnalysis (version )
79- resultingMetricsOk = checkMetrics ()
127+
128+ analysisFinishedOk = True
129+ resultingMetricsOk = True
130+ for project , parameters , exp_measures in TEST_PROJECTS :
131+ projecthome = os .path .join (BASEDIR , TEST_PROJECTS_HOME , project )
132+ analysisFinishedOk &= runAnalysis (version , parameters , projecthome )
133+ resultingMetricsOk &= checkMetrics (project , exp_measures )
134+
80135 stop_sonar (version )
81136 return all ([started , logsOK , analysisFinishedOk , resultingMetricsOk ])
82137 else :
@@ -111,7 +166,8 @@ def start_sonar(version):
111166 sys .stdout .write (INDENT + "starting Sonar ... " )
112167 sys .stdout .flush ()
113168 now = time .time ()
114- rc = subprocess .call (start_script (version ), stdout = subprocess .PIPE , shell = (os .name == "nt" ))
169+ rc = subprocess .call (start_script (version ), stdout = subprocess .PIPE ,
170+ shell = (os .name == "nt" ))
115171 if rc != 0 or not wait_for_sonar (50 , is_webui_up ):
116172 sys .stdout .write (RED + "FAILED\n " + RESET )
117173 return False
@@ -124,7 +180,8 @@ def start_sonar(version):
124180def stop_sonar (version ):
125181 sys .stdout .write (INDENT + "stopping Sonar ... " )
126182 sys .stdout .flush ()
127- rc = subprocess .call (stop_script (version ), stdout = subprocess .PIPE , shell = (os .name == "nt" ))
183+ rc = subprocess .call (stop_script (version ), stdout = subprocess .PIPE ,
184+ shell = (os .name == "nt" ))
128185 if rc != 0 or not wait_for_sonar (30 , is_webui_down ):
129186 sys .stdout .write (RED + "FAILED\n " + RESET )
130187 return False
@@ -216,15 +273,20 @@ def isSonarWarning(line):
216273 return SONAR_WARN_RE .match (line )
217274
218275
219- def runAnalysis (version ):
220- logfname = "analysis_%s.log" % version
221- sys .stdout .write (INDENT + "running analysis (see %s) ... " % logfname )
276+ def runAnalysis (version , parameters , projecthome ):
277+ project = os .path .basename (projecthome )
278+ logfname = "analysis_%s_%s.log" % (version , project )
279+ INDENTx2 = INDENT + INDENT
280+ sys .stdout .write ((INDENT + "running analysis of %s \n " +
281+ INDENTx2 + "with parameters '%s'\n " +
282+ INDENTx2 + "(see logfile %s) ... " )
283+ % (project , parameters , logfname ))
222284 sys .stdout .flush ()
223285 now = time .time ()
224286 runner = "sonar-runner.bat" if os .name == 'nt' else "sonar-runner"
225287 with open (logfname , "w" ) as logfile :
226- rc = subprocess .call ([runner , "-X" ] ,
227- cwd = os . path . join ( BASEDIR , PROJECT_PATH ) ,
288+ rc = subprocess .call ([runner ] + parameters ,
289+ cwd = projecthome ,
228290 stdout = logfile , stderr = logfile )
229291 if rc == 0 :
230292 label = GREEN + "OK, duration: %03.1f s\n " % (time .time () - now )
@@ -237,30 +299,38 @@ def runAnalysis(version):
237299
238300
239301def diffDicts (d1 , d2 ):
240- rc = True
241302 difflist = []
242- if d1 != d2 :
243- rc = False
244- for k1 , v1 in d1 .iteritems ():
245- v2 = d2 .get (k1 , "<None>" )
246- if v1 != v2 :
247- difflist .append ("%s %s/%s" % (k1 , str (v1 ), str (v2 )))
248- return rc , ", " .join (difflist )
249-
250-
251- def checkMetrics ():
303+ #import pprint
304+ #pprint.pprint(d1)
305+ #pprint.pprint(d2)
306+
307+ for k1 , v1 in d1 .iteritems ():
308+ v2 = d2 .get (k1 , None )
309+ if v1 != v2 :
310+ difflist .append ("%s %s/%s" % (k1 , str (v1 ), str (v2 )))
311+ return ", " .join (difflist )
312+
313+
314+ def checkMetrics (project_key , exp_measures ):
252315 sys .stdout .write (INDENT + "checking resulting metrics ... " )
253316 sys .stdout .flush ()
254317
255318 rc = False
256319 try :
257- url = (SONAR_URL + "/api/resources?resource=" + PROJECT_KEY + "&metrics="
258- + "," .join (EXP_MEASURES .keys ()))
320+ url = (SONAR_URL + "/api/resources?resource=" + project_key + "&metrics="
321+ + "," .join (exp_measures .keys ()))
259322 r = requests .get (url )
260- gotMeasures = _toSimpleDict (json .loads (r .text )[0 ]["msr" ])
261-
262- rc , diff = diffDicts (EXP_MEASURES , gotMeasures )
263- label = (GREEN + "OK" ) if rc else (RED + "FAILED, diff: " + diff )
323+ got_measures = {}
324+ json_measures = json .loads (r .text )[0 ].get ("msr" , None )
325+ if json_measures is not None :
326+ got_measures = _toSimpleDict (json_measures )
327+
328+ diff = diffDicts (exp_measures , got_measures )
329+ if diff == "" :
330+ label = (GREEN + "OK" )
331+ rc = True
332+ else :
333+ label = (RED + "FAILED, diff: " + diff )
264334 except requests .exceptions .ConnectionError , e :
265335 label = RED + "FAILED, reason: " + str (e )
266336
@@ -281,7 +351,7 @@ if __name__ == "__main__":
281351 badversions = []
282352 goodversions = []
283353 for sonar_version in SONAR_VERSIONS :
284- if test_bootup (sonar_version ):
354+ if runtests (sonar_version ):
285355 goodversions .append (sonar_version )
286356 else :
287357 badversions .append (sonar_version )
0 commit comments