<commit_before>#! perl
# Copyright (C) 2006, The Perl Foundation.
# $Id$

use strict;
use warnings;

use lib qw( . lib ../lib ../../lib );
use Parrot::Distribution;
use Test::More tests => 1;

=head1 NAME

t/codingstd/trailing_space.t - checks for superfluous trailing space or tab characters

=head1 SYNOPSIS

    # test all files
    % prove t/codingstd/trailing_space.t

    # test specific files
    % perl t/codingstd/trailing_space.t src/foo.c include/parrot/bar.h

=head1 DESCRIPTION

Checks that files don't have trailing space or tab characters between the
last nominal character on the line and the end of line character.

=head1 SEE ALSO

L<docs/pdds/pdd07_codingstd.pod>

=cut

my $DIST = Parrot::Distribution->new;

my @files = @ARGV ? @ARGV : source_files();
my @failed_files;

foreach my $file (@files) {
    my $buf;
    my $path;

    ## get the full path of the file
    # if we have command line arguments, the file is the full path
    if (@ARGV) {
        $path = $file;
    }

    # otherwise, use the relevant Parrot:: path method
    else {
        $path = $file->path;
    }

    # slurp in the file
    open( my $fh, '<', $path )
        or die "Cannot open '$path' for reading: $!\n";
    {
        local $/;
        $buf = <$fh>;
    }

    if ($buf =~ m{.?[ \t]+$}m) {
        push @failed_files, $path;
    }
}

# check the file
ok( !scalar(@failed_files), 'No trailing spaces or tabs' )
    or diag( join $/ => "Trailing space or tab char found in " .
        scalar @failed_files .  " files:", @failed_files );

exit;

sub source_files {
    return (
        map( $_->files_of_type('C code'),
            $DIST->c_source_file_directories ),

        map( $_->files_of_type('C header'),
            $DIST->c_header_file_directories ),

        map( $_->files_of_type('PMC code'),
            $DIST->pmc_source_file_directories ),

        map( $_->files_of_type('Yacc file'),
            $DIST->yacc_source_file_directories ),

        map( $_->files_of_type('Lex file'),
            $DIST->lex_source_file_directories ),
    );
}

# Local Variables:
#   mode: cperl
#   cperl-indent-level: 4
#   fill-column: 100
# End:
# vim: expandtab shiftwidth=4:<commit_msg> r4870@avon:  cochrane | 2006-11-07 15:36:21 +0100  [devel]  According to cage task #40279 ops files are considered part of the  collection of C-language files in Parrot.  This change adds ops files to be  processed as a part of the coding standard tests.<commit_after>#! perl
# Copyright (C) 2006, The Perl Foundation.
# $Id$

use strict;
use warnings;

use lib qw( . lib ../lib ../../lib );
use Parrot::Distribution;
use Test::More tests => 1;

=head1 NAME

t/codingstd/trailing_space.t - checks for superfluous trailing space or tab characters

=head1 SYNOPSIS

    # test all files
    % prove t/codingstd/trailing_space.t

    # test specific files
    % perl t/codingstd/trailing_space.t src/foo.c include/parrot/bar.h

=head1 DESCRIPTION

Checks that files don't have trailing space or tab characters between the
last nominal character on the line and the end of line character.

=head1 SEE ALSO

L<docs/pdds/pdd07_codingstd.pod>

=cut

my $DIST = Parrot::Distribution->new;

my @files = @ARGV ? @ARGV : source_files();
my @failed_files;

foreach my $file (@files) {
    my $buf;
    my $path;

    ## get the full path of the file
    # if we have command line arguments, the file is the full path
    if (@ARGV) {
        $path = $file;
    }

    # otherwise, use the relevant Parrot:: path method
    else {
        $path = $file->path;
    }

    # slurp in the file
    open( my $fh, '<', $path )
        or die "Cannot open '$path' for reading: $!\n";
    {
        local $/;
        $buf = <$fh>;
    }

    if ($buf =~ m{.?[ \t]+$}m) {
        push @failed_files, $path;
    }
}

# check the file
ok( !scalar(@failed_files), 'No trailing spaces or tabs' )
    or diag( join $/ => "Trailing space or tab char found in " .
        scalar @failed_files .  " files:", @failed_files );

exit;

sub source_files {
    return (
        map( $_->files_of_type('C code'),
            $DIST->c_source_file_directories ),

        map( $_->files_of_type('C header'),
            $DIST->c_header_file_directories ),

        map( $_->files_of_type('PMC code'),
            $DIST->pmc_source_file_directories ),

        map( $_->files_of_type('Yacc file'),
            $DIST->yacc_source_file_directories ),

        map( $_->files_of_type('Lex file'),
            $DIST->lex_source_file_directories ),

        map( $_->files_of_type('Parrot opcode file'),
            $DIST->ops_source_file_directories ),
    );
}

# Local Variables:
#   mode: cperl
#   cperl-indent-level: 4
#   fill-column: 100
# End:
# vim: expandtab shiftwidth=4:
{'fraction_non_alphanumeric': 0.12882787750791974, 'fraction_numerical': 0.01246040126715945, 'mean_word_length': 2.659969088098918, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2107648', 'n_tokens_mistral': 1701, 'n_tokens_neox': 1576, 'n_words': 482}