Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: cf4f4f1530df44737d60204eb1f94bd6dfcf6fe9 (plain) (blame)
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*******************************************************************************
 * Copyright (c) 2010 Marc-Andre Laperle and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * Marc-Andre Laperle - Initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.codan.core.internal.checkers;

import org.eclipse.cdt.codan.core.test.CheckerTestCase;
import org.eclipse.cdt.codan.internal.checkers.SuspiciousSemicolonChecker;

public class SuspiciousSemicolonCheckerTest extends CheckerTestCase {
	@Override
	public void setUp() throws Exception {
		super.setUp();
		enableProblems("org.eclipse.cdt.codan.internal.checkers.SuspiciousSemicolonProblem"); //$NON-NLS-1$
	}

	// void foo() {
	// if(0);
	// }
	public void testIf1() {
		loadCodeAndRun(getAboveComment());
		checkErrorLine(2);
	}

	// void foo() {
	// if(0);
	// {
	// }
	// }
	public void testIf2() {
		loadCodeAndRun(getAboveComment());
		checkErrorLine(2);
	}

	// void foo() {
	// if(0)
	// foo();
	// }
	public void testIf3() {
		loadCodeAndRun(getAboveComment());
		checkNoErrors();
	}

	// void foo() {
	// if(0)
	// ;
	// }
	public void testIf4() {
		loadCodeAndRun(getAboveComment());
		checkErrorLine(3);
	}

	// void foo() {
	// if(0);{
	// }
	// }
	public void testIf5() {
		loadCodeAndRun(getAboveComment());
		checkErrorLine(2);
	}

	// void foo() {
	// if(0) {};
	// }
	public void testIf6() {
		loadCodeAndRun(getAboveComment());
		checkNoErrors();
	}

	// void foo() {
	// if(0
	// );
	// }
	// }
	public void testIf7() {
		loadCodeAndRun(getAboveComment());
		checkErrorLine(3);
	}

	// void foo() {
	// if(0)
	// ;
	// else if(0);
	// }
	public void testElseIf1() {
		loadCodeAndRun(getAboveComment());
		checkErrorLine(3);
		checkErrorLine(4);
	}

	// void foo() {
	// if(0)
	// ;
	// else if(0);
	// {
	//
	// }
	// }
	public void testElseIf2() {
		loadCodeAndRun(getAboveComment());
		checkErrorLine(3);
		checkErrorLine(4);
	}

	// void foo() {
	// if(0)
	// ;
	// else if(0);{
	// }
	// }
	public void testElseIf3() {
		loadCodeAndRun(getAboveComment());
		checkErrorLine(3);
		checkErrorLine(4);
	}

	// void foo() {
	// if(0)
	// ;
	// else if(0){};
	// }
	public void testElseIf4() {
		loadCodeAndRun(getAboveComment());
		checkErrorLine(3);
	}

	// void foo() {
	// if(0)
	// ;
	// else if(0
	// );
	// }
	public void testElseIf5() {
		loadCodeAndRun(getAboveComment());
		checkErrorLine(3);
		checkErrorLine(5);
	}

	// #define OP
	// void foo() {
	//   if(0)
	//     OP;
	// }
	public void testMacro() {
		loadCodeAndRun(getAboveComment());
		checkNoErrors();
	}

	// #define MACRO(cond) if (cond) ;
	// void foo() {
	//   MACRO(true);
	// }
	public void testMacroExpansion() {
		loadCodeAndRun(getAboveComment());
		checkNoErrors();
	}

	// main() {
	//	   if (false)
	//	        ; // only this one is reported
	//	    else
	//	        ;
	// }
	public void testIfElse() {
		setPreferenceValue(SuspiciousSemicolonChecker.ER_ID, SuspiciousSemicolonChecker.PARAM_ALFTER_ELSE, Boolean.TRUE);
		loadCodeAndRun(getAboveComment());
		checkErrorLines(3, 5);
	}
}

Back to the top