Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 24ac16b99228552d93a944298a22c3cf8b234477 (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
/*******************************************************************************
 * Copyright (c) 2015 QNX Software System and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     Elena Laskavaia (QNX Software System) - initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.codan.core.internal.checkers;

import java.io.File;

import org.eclipse.cdt.codan.core.tests.CheckerTestCase;
import org.eclipse.cdt.codan.internal.checkers.CommentChecker;
import org.junit.Test;

/**
 * Tests for CommentChecker
 */
public class CommentCheckerLineTests extends CheckerTestCase {
	@Override
	public void setUp() throws Exception {
		super.setUp();
		enableProblems(CommentChecker.COMMENT_NO_LINE);
	}

	@Override
	public boolean isCpp() {
		return true;
	}

	//	void foo() {
	//	  return; // error
	//	}
	@Test
	public void testLineComment() throws Exception {
		checkSampleAboveC();
	}

	//	void foo() {
	//	  return;
	//	}
	@Test
	public void testNoLineComment() throws Exception {
		checkSampleAboveC();
	}

	//	char * foo() {
	//	  return "// this is a string";
	//	}
	@Test
	public void testNoLineCommentInString() throws Exception {
		checkSampleAboveC();
	}

	//	void foo() {
	//	  return; // not an error in c++
	//	}
	@Test
	public void testLineCommentCpp() throws Exception {
		checkSampleAboveCpp();
	}

	//	#define AAA // error even in prepro
	@Test
	public void testLineCommentInPrepro() throws Exception {
		checkSampleAboveC();
	}

	// @file:test.h
	// int foo();// error too

	// @file:test.c
	// #include "test.h"
	// int bar() {
	//    foo();
	// }
	public void testHeader() throws Exception {
		loadcode(getContents(2));
		runOnProject();
		checkErrorLine(new File("test.h"), 1); //$NON-NLS-1$
	}
}

Back to the top