-
Notifications
You must be signed in to change notification settings - Fork 138
/
c_cppcomments.t
75 lines (58 loc) · 1.72 KB
/
c_cppcomments.t
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
#! perl
# Copyright (C) 2001-2009, Parrot Foundation.
# $Id$
use strict;
use warnings;
use lib qw( . lib ../lib ../../lib );
use Test::More tests => 1;
use Parrot::Distribution;
use Parrot::Test::Util::Runloop;
=head1 NAME
t/codingstd/c_cppcomments.t - checks for C++ style comments
=head1 SYNOPSIS
# test all files
% prove t/codingstd/c_cppcomments.t
# test specific files
% perl t/codingstd/c_cppcoments.t src/foo.t include/parrot/bar.h
=head1 DESCRIPTION
Checks that no source file in the distribution uses C++ style comments.
=head1 SEE ALSO
L<docs/pdds/pdd07_codingstd.pod>
=cut
my @files;
if ( @ARGV ) {
@files = <@ARGV>;
}
else {
my $DIST = Parrot::Distribution->new();
@files = $DIST->get_c_language_files();
@files = grep { $_->name !~ /.l$/ } @files;
}
Parrot::Test::Util::Runloop->testloop(
name => 'no c++ comments',
files => [@files],
per_file => \&check_cppcomments,
diag_prefix => 'C++ comments found'
);
# TT # 414 (https://trac.parrot.org/parrot/ticket/414):
# In the POD inside a C source code file, a hyperlink such as
# https://trac.parrot.org will be inaccurately reported as a C++-style
# comment.
# Quick fix added
sub check_cppcomments {
my $buf = shift;
$buf =~ s{ (?:
(?: ' (?: \\\\ | \\' | [^'] )* ' ) # remove ' string
| (?: " (?: \\\\ | \\" | [^"] )* " ) # remove " string
| /\* .*? \*/ # remove C comment
| https?:\/\/ # TT # 414 quick fix
)
}{}gsx;
return $buf !~ m{ ( .*? // .* ) }x;
}
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4: