fdf3d052807809ead338596bf005ff03c5cd5c64
[p5sagit/p5-mst-13.2.git] / t / TEST
1 #!./perl
2
3 # This is written in a peculiar style, since we're trying to avoid
4 # most of the constructs we'll be testing for.  (This comment is
5 # probably obsolete on the avoidance side, though still currrent
6 # on the peculiarity side.)
7
8 # t/TEST and t/harness need to share code. The logical way to do this would be
9 # to have the common code in a file both require or use. However, t/TEST needs
10 # to still work, to generate test results, even if require isn't working, so
11 # we cannot do that. t/harness has no such restriction, so it is quite
12 # acceptable to have it require t/TEST.
13
14 # In which case, we need to stop t/TEST actually running tests, as all
15 # t/harness needs are its subroutines.
16
17
18 # directories with special sets of test switches
19 my %dir_to_switch =
20     (base => '',
21      comp => '',
22      run => '',
23      '../ext/File-Glob/t' => '-I.. -MTestInit', # FIXME - tests assume t/
24      );
25
26 my %temp_no_core =
27     ('../ext/Attribute-Handlers' => 1,
28      '../ext/B-Debug' => 1,
29      '../ext/Compress-Raw-Bzip2' => 1,
30      '../ext/Compress-Raw-Zlib' => 1,
31      '../ext/Devel-PPPort' => 1,
32      '../ext/Encode' => 1,
33      '../ext/I18N-Langinfo' => 'fixme',
34      '../ext/IO-Compress' => 1,
35      '../ext/IPC-SysV' => 1,
36      '../ext/MIME-Base64' => 1,
37      '../ext/Safe' => 'fixme',
38      '../ext/Time-HiRes' => 1,
39      '../ext/Unicode-Normalize' => 1,
40     );
41
42 if ($::do_nothing) {
43     return 1;
44 }
45
46 # Location to put the Valgrind log.
47 my $Valgrind_Log = 'current.valgrind';
48
49 $| = 1;
50
51 # for testing TEST only
52 #BEGIN { require '../lib/strict.pm'; "strict"->import() };
53 #BEGIN { require '../lib/warnings.pm'; "warnings"->import() };
54
55 delete $ENV{PERL5LIB};
56 delete $ENV{PERLLIB};
57 delete $ENV{PERL5OPT};
58
59 # remove empty elements due to insertion of empty symbols via "''p1'" syntax
60 @ARGV = grep($_,@ARGV) if $^O eq 'VMS';
61 our $show_elapsed_time = $ENV{HARNESS_TIMER} || 0;
62
63 # Cheesy version of Getopt::Std.  We can't replace it with that, because we
64 # can't rely on require working.
65 {
66     my @argv = ();
67     foreach my $idx (0..$#ARGV) {
68         push( @argv, $ARGV[$idx] ), next unless $ARGV[$idx] =~ /^-(\S+)$/;
69         $::benchmark = 1 if $1 eq 'benchmark';
70         $::core    = 1 if $1 eq 'core';
71         $::verbose = 1 if $1 eq 'v';
72         $::torture = 1 if $1 eq 'torture';
73         $::with_utf8 = 1 if $1 eq 'utf8';
74         $::with_utf16 = 1 if $1 eq 'utf16';
75         $::taintwarn = 1 if $1 eq 'taintwarn';
76         $ENV{PERL_CORE_MINITEST} = 1 if $1 eq 'minitest';
77         if ($1 =~ /^deparse(,.+)?$/) {
78             $::deparse = 1;
79             $::deparse_opts = $1;
80         }
81     }
82     @ARGV = @argv;
83 }
84
85 chdir 't' if -f 't/TEST';
86
87 die "You need to run \"make test\" first to set things up.\n"
88   unless -e 'perl' or -e 'perl.exe' or -e 'perl.pm';
89
90 if ($ENV{PERL_3LOG}) { # Tru64 third(1) tool, see perlhack
91     unless (-x 'perl.third') {
92         unless (-x '../perl.third') {
93             die "You need to run \"make perl.third first.\n";
94         }
95         else {
96             print "Symlinking ../perl.third as perl.third...\n";
97             die "Failed to symlink: $!\n"
98                 unless symlink("../perl.third", "perl.third");
99             die "Symlinked but no executable perl.third: $!\n"
100                 unless -x 'perl.third';
101         }
102     }
103 }
104
105 # check leakage for embedders
106 $ENV{PERL_DESTRUCT_LEVEL} = 2 unless exists $ENV{PERL_DESTRUCT_LEVEL};
107
108 $ENV{EMXSHELL} = 'sh';        # For OS/2
109
110 if ($show_elapsed_time) { require Time::HiRes }
111
112 my %skip = (
113             '.' => 1,
114             '..' => 1,
115             'CVS' => 1,
116             'RCS' => 1,
117             'SCCS' => 1,
118             '.svn' => 1,
119            );
120
121 # Roll your own File::Find!
122 sub _find_tests {
123     my($dir) = @_;
124     opendir DIR, $dir or die "Trouble opening $dir: $!";
125     foreach my $f (sort { $a cmp $b } readdir DIR) {
126         next if $skip{$f};
127
128         my $fullpath = "$dir/$f";
129
130         if (-d $fullpath) {
131             _find_tests($fullpath);
132         } elsif ($f =~ /\.t$/) {
133             push @ARGV, $fullpath;
134         }
135     }
136 }
137
138
139 # Scan the text of the test program to find switches and special options
140 # we might need to apply.
141 sub _scan_test {
142     my($test, $type) = @_;
143
144     open(my $script, "<", $test) or die "Can't read $test.\n";
145     my $first_line = <$script>;
146
147     $first_line =~ tr/\0//d if $::with_utf16;
148
149     my $switch = "";
150     if ($first_line =~ /#!.*\bperl.*\s-\w*([tT])/) {
151         $switch = qq{"-$1"};
152     } else {
153         if ($::taintwarn) {
154             # not all tests are expected to pass with this option
155             $switch = '"-t"';
156         } else {
157             $switch = '';
158         }
159     }
160
161     my $file_opts = "";
162     if ($type eq 'deparse') {
163         # Look for #line directives which change the filename
164         while (<$script>) {
165             $file_opts .= ",-f$3$4"
166               if /^#\s*line\s+(\d+)\s+((\w+)|"([^"]+)")/;
167         }
168     }
169
170     return { file => $file_opts, switch => $switch };
171 }
172                   
173 sub _run_test {
174     my($harness, $test, $type) = @_;
175     if (!defined $type) {
176         # To conform to the interface expected by exec in TAP::Harness
177         $type = 'perl';
178     }
179
180     my $options = _scan_test($test, $type);
181     my $return_dir;
182
183     my $perl = './perl';
184     my $lib  = '../lib';
185     $test =~ /^(.+)\/[^\/]+/;
186     my $dir = $1;
187     my $ext_dir;
188
189     my $testswitch = $dir_to_switch{$dir};
190     if (!defined $testswitch) {
191         if ($test =~ s!^(\.\./ext/[^/]+)/t!t!) {
192             $ext_dir = $1;
193             $return_dir = '../../t';
194             $lib = '../../lib';
195             $perl = '../../t/perl';
196             $testswitch = "-I../.. -MTestInit=U2T,A";
197             if ($temp_no_core{$ext_dir}) {
198                 $testswitch = $testswitch . ',NC';
199             }
200             chdir $ext_dir or die "Can't chdir to '$ext_dir': $!";
201         } else {
202             $testswitch = '-I.. -MTestInit';  # -T will remove . from @INC
203         }
204     }
205
206     my $utf8 = $::with_utf8 ? '-I$lib -Mutf8' : '';
207
208     my $results;
209     if ($type eq 'deparse') {
210         my $deparse_cmd =
211           "$perl $testswitch $options->{switch} -I$lib -MO=-qq,Deparse,-sv1.,".
212           "-l$::deparse_opts$options->{file} ".
213           "$test > $test.dp ".
214           "&& $perl $testswitch $options->{switch} -I$lib $test.dp |";
215         open($results, $deparse_cmd)
216           or print "can't deparse '$deparse_cmd': $!.\n";
217     }
218     elsif ($type eq 'perl') {
219         my $redir = $^O eq 'VMS' ? '2>&1' : '';
220
221         if ($ENV{PERL_VALGRIND}) {
222             my $valgrind = $ENV{VALGRIND} // 'valgrind';
223             my $vg_opts = $ENV{VG_OPTS}
224               //  "--suppressions=perl.supp --leak-check=yes "
225                 . "--leak-resolution=high --show-reachable=yes "
226                   . "--num-callers=50"; 
227             $perl = "$valgrind --log-fd=3 $vg_opts $perl";
228             $redir = "3>$Valgrind_Log";
229         }
230
231         my $run = $perl . _quote_args("$testswitch $options->{switch} $utf8")
232           . " $test $redir|";
233         open($results, $run) or print "can't run '$run': $!.\n";
234     }
235
236     if ($return_dir) {
237         chdir $return_dir
238             or die "Can't chdir from '$ext_dir' to '$return_dir': $!";
239     }
240
241     # Our environment may force us to use UTF-8, but we can't be sure that
242     # anything we're reading from will be generating (well formed) UTF-8
243     # This may not be the best way - possibly we should unset ${^OPEN} up
244     # top?
245     binmode $results;
246
247     return $results;
248 }
249
250 sub _quote_args {
251     my ($args) = @_;
252     my $argstring = '';
253
254     foreach (split(/\s+/,$args)) {
255        # In VMS protect with doublequotes because otherwise
256        # DCL will lowercase -- unless already doublequoted.
257        $_ = q(").$_.q(") if ($^O eq 'VMS') && !/^\"/ && length($_) > 0;
258        $argstring .= ' ' . $_;
259     }
260     return $argstring;
261 }
262
263 sub _populate_hash {
264     return unless defined $_[0];
265     return map {$_, 1} split /\s+/, $_[0];
266 }
267
268 sub _tests_from_manifest {
269     my ($extensions, $known_extensions) = @_;
270     my %skip;
271     my %extensions = _populate_hash($extensions);
272     my %known_extensions = _populate_hash($known_extensions);
273
274     foreach (keys %known_extensions) {
275         $skip{$_}++ unless $extensions{$_};
276     }
277
278     my @results;
279     my $mani = '../MANIFEST';
280     if (open(MANI, $mani)) {
281         while (<MANI>) {
282             if (m!^(ext/(\S+)/+(?:[^/\s]+\.t|test\.pl)|lib/\S+?(?:\.t|test\.pl))\s!) {
283                 my $t = $1;
284                 my $extension = $2;
285                 if (!$::core || $t =~ m!^lib/[a-z]!) {
286                     if (defined $extension) {
287                         $extension =~ s!/t$!!;
288                         # XXX Do I want to warn that I'm skipping these?
289                         next if $skip{$extension};
290                         my $flat_extension = $extension;
291                         $flat_extension =~ s!-!/!g;
292                         next if $skip{$flat_extension}; # Foo/Bar may live in Foo-Bar
293                     }
294                     my $path = "../$t";
295                     push @results, $path;
296                     $::path_to_name{$path} = $t;
297                 }
298             }
299         }
300         close MANI;
301     } else {
302         warn "$0: cannot open $mani: $!\n";
303     }
304     return @results;
305 }
306
307 unless (@ARGV) {
308     # base first, as TEST bails out if that can't run
309     # then comp, to validate that require works
310     # then run, to validate that -M works
311     # then we know we can -MTestInit for everything else, making life simpler
312     foreach my $dir (qw(base comp run cmd io op uni mro)) {
313         _find_tests($dir);
314     }
315     _find_tests("lib") unless $::core;
316     # Config.pm may be broken for make minitest. And this is only a refinement
317     # for skipping tests on non-default builds, so it is allowed to fail.
318     # What we want to to is make a list of extensions which we did not build.
319     my $configsh = '../config.sh';
320     my ($extensions, $known_extensions);
321     if (-f $configsh) {
322         open FH, $configsh or die "Can't open $configsh: $!";
323         while (<FH>) {
324             if (/^extensions=['"](.*)['"]$/) {
325                 $extensions = $1;
326             }
327             elsif (/^known_extensions=['"](.*)['"]$/) {
328                 $known_extensions = $1;
329             }
330         }
331         if (!defined $known_extensions) {
332             warn "No known_extensions line found in $configsh";
333         }
334         if (!defined $extensions) {
335             warn "No extensions line found in $configsh";
336         }
337     }
338     # The "complex" constructions of list return from a subroutine, and push of
339     # a list, might fail if perl is really hosed, but they aren't needed for
340     # make minitest, and the building of extensions will likely also fail if
341     # something is that badly wrong.
342     push @ARGV, _tests_from_manifest($extensions, $known_extensions);
343     unless ($::core) {
344         _find_tests('pod');
345         _find_tests('x2p');
346         _find_tests('porting');
347         _find_tests('japh') if $::torture;
348         _find_tests('t/benchmark') if $::benchmark or $ENV{PERL_BENCHMARK};
349     }
350 }
351
352 if ($::deparse) {
353     _testprogs('deparse', '',   @ARGV);
354 }
355 elsif ($::with_utf16) {
356     for my $e (0, 1) {
357         for my $b (0, 1) {
358             print STDERR "# ENDIAN $e BOM $b\n";
359             my @UARGV;
360             for my $a (@ARGV) {
361                 my $u = $a . "." . ($e ? "l" : "b") . "e" . ($b ? "b" : "");
362                 my $f = $e ? "v" : "n";
363                 push @UARGV, $u;
364                 unlink($u);
365                 if (open(A, $a)) {
366                     if (open(U, ">$u")) {
367                         print U pack("$f", 0xFEFF) if $b;
368                         while (<A>) {
369                             print U pack("$f*", unpack("C*", $_));
370                         }
371                         close(U);
372                     }
373                     close(A);
374                 }
375             }
376             _testprogs('perl', '', @UARGV);
377             unlink(@UARGV);
378         }
379     }
380 }
381 else {
382     _testprogs('perl',    '',   @ARGV);
383 }
384
385 sub _testprogs {
386     my ($type, $args, @tests) = @_;
387
388     print <<'EOT' if ($type eq 'deparse');
389 ------------------------------------------------------------------------------
390 TESTING DEPARSER
391 ------------------------------------------------------------------------------
392 EOT
393
394     $::bad_files = 0;
395
396     foreach my $t (@tests) {
397       unless (exists $::path_to_name{$t}) {
398         my $tname = "t/$t";
399         $::path_to_name{$t} = $tname;
400       }
401     }
402     my $maxlen = 0;
403     foreach (@::path_to_name{@tests}) {
404         s/\.\w+\z/./;
405         my $len = length ;
406         $maxlen = $len if $len > $maxlen;
407     }
408     # + 3 : we want three dots between the test name and the "ok"
409     my $dotdotdot = $maxlen + 3 ;
410     my $valgrind = 0;
411     my $total_files = @tests;
412     my $good_files = 0;
413     my $tested_files  = 0;
414     my $totmax = 0;
415     my %failed_tests;
416
417     while (my $test = shift @tests) {
418         my $test_start_time = $show_elapsed_time ? Time::HiRes::time() : 0;
419
420         if ($test =~ /^$/) {
421             next;
422         }
423         if ($type eq 'deparse') {
424             if ($test eq "comp/redef.t") {
425                 # Redefinition happens at compile time
426                 next;
427             }
428             elsif ($test =~ m{lib/Switch/t/}) {
429                 # B::Deparse doesn't support source filtering
430                 next;
431             }
432         }
433         my $te = $::path_to_name{$test} . '.'
434                     x ($dotdotdot - length($::path_to_name{$test}));
435
436         if ($^O ne 'VMS') {  # defer printing on VMS due to piping bug
437             print $te;
438             $te = '';
439         }
440
441         my $results = _run_test(undef, $test, $type);
442
443         my $failure;
444         my $next = 0;
445         my $seen_leader = 0;
446         my $seen_ok = 0;
447         my $trailing_leader = 0;
448         my $max;
449         my %todo;
450         while (<$results>) {
451             next if /^\s*$/; # skip blank lines
452             if (/^1..$/ && ($^O eq 'VMS')) {
453                 # VMS pipe bug inserts blank lines.
454                 my $l2 = <RESULTS>;
455                 if ($l2 =~ /^\s*$/) {
456                     $l2 = <RESULTS>;
457                 }
458                 $_ = '1..' . $l2;
459             }
460             if ($::verbose) {
461                 print $_;
462             }
463             unless (/^\#/) {
464                 if ($trailing_leader) {
465                     # shouldn't be anything following a postfix 1..n
466                     $failure = 'FAILED--extra output after trailing 1..n';
467                     last;
468                 }
469                 if (/^1\.\.([0-9]+)( todo ([\d ]+))?/) {
470                     if ($seen_leader) {
471                         $failure = 'FAILED--seen duplicate leader';
472                         last;
473                     }
474                     $max = $1;
475                     %todo = map { $_ => 1 } split / /, $3 if $3;
476                     $totmax += $max;
477                     $tested_files++;
478                     if ($seen_ok) {
479                         # 1..n appears at end of file
480                         $trailing_leader = 1;
481                         if ($next != $max) {
482                             $failure = "FAILED--expected $max tests, saw $next";
483                             last;
484                         }
485                     }
486                     else {
487                         $next = 0;
488                     }
489                     $seen_leader = 1;
490                 }
491                 else {
492                     if (/^(not )?ok(?: (\d+))?[^\#]*(\s*\#.*)?/) {
493                         unless ($seen_leader) {
494                             unless ($seen_ok) {
495                                 $next = 0;
496                             }
497                         }
498                         $seen_ok = 1;
499                         $next++;
500                         my($not, $num, $extra, $istodo) = ($1, $2, $3, 0);
501                         $num = $next unless $num;
502
503                         if ($num == $next) {
504
505                             # SKIP is essentially the same as TODO for t/TEST
506                             # this still conforms to TAP:
507                             # http://search.cpan.org/dist/TAP/TAP.pod
508                             $extra and $istodo = $extra =~ /#\s*(?:TODO|SKIP)\b/;
509                             $istodo = 1 if $todo{$num};
510
511                             if( $not && !$istodo ) {
512                                 $failure = "FAILED at test $num";
513                                 last;
514                             }
515                         }
516                         else {
517                             $failure ="FAILED--expected test $next, saw test $num";
518                             last;
519                         }
520                     }
521                     elsif (/^Bail out!\s*(.*)/i) { # magic words
522                         die "FAILED--Further testing stopped" . ($1 ? ": $1\n" : ".\n");
523                     }
524                     else {
525                         # module tests are allowed extra output,
526                         # because Test::Harness allows it
527                         next if $test =~ /^\W*(ext|lib)\b/;
528                         $failure = "FAILED--unexpected output at test $next";
529                         last;
530                     }
531                 }
532             }
533         }
534         close $results;
535
536         if (not defined $failure) {
537             $failure = 'FAILED--no leader found' unless $seen_leader;
538         }
539
540         if ($ENV{PERL_VALGRIND}) {
541             my @valgrind;
542             if (-e $Valgrind_Log) {
543                 if (open(V, $Valgrind_Log)) {
544                     @valgrind = <V>;
545                     close V;
546                 } else {
547                     warn "$0: Failed to open '$Valgrind_Log': $!\n";
548                 }
549             }
550             if ($ENV{VG_OPTS} =~ /cachegrind/) {
551                 if (rename $Valgrind_Log, "$test.valgrind") {
552                     $valgrind++;
553                 } else {
554                     warn "$0: Failed to create '$test.valgrind': $!\n";
555                 }
556             }
557             elsif (@valgrind) {
558                 my $leaks = 0;
559                 my $errors = 0;
560                 for my $i (0..$#valgrind) {
561                     local $_ = $valgrind[$i];
562                     if (/^==\d+== ERROR SUMMARY: (\d+) errors? /) {
563                         $errors += $1;   # there may be multiple error summaries
564                     } elsif (/^==\d+== LEAK SUMMARY:/) {
565                         for my $off (1 .. 4) {
566                             if ($valgrind[$i+$off] =~
567                                 /(?:lost|reachable):\s+\d+ bytes in (\d+) blocks/) {
568                                 $leaks += $1;
569                             }
570                         }
571                     }
572                 }
573                 if ($errors or $leaks) {
574                     if (rename $Valgrind_Log, "$test.valgrind") {
575                         $valgrind++;
576                     } else {
577                         warn "$0: Failed to create '$test.valgrind': $!\n";
578                     }
579                 }
580             } else {
581                 warn "No valgrind output?\n";
582             }
583             if (-e $Valgrind_Log) {
584                 unlink $Valgrind_Log
585                     or warn "$0: Failed to unlink '$Valgrind_Log': $!\n";
586             }
587         }
588         if ($type eq 'deparse') {
589             unlink "./$test.dp";
590         }
591         if ($ENV{PERL_3LOG}) {
592             my $tpp = $test;
593             $tpp =~ s:^\.\./::;
594             $tpp =~ s:/:_:g;
595             $tpp =~ s:\.t$:.3log:;
596             rename("perl.3log", $tpp) ||
597                 die "rename: perl3.log to $tpp: $!\n";
598         }
599         if (not defined $failure and $next != $max) {
600             $failure="FAILED--expected $max tests, saw $next";
601         }
602
603         if( !defined $failure  # don't mask a test failure
604             and $? )
605         {
606             $failure = "FAILED--non-zero wait status: $?";
607         }
608
609         if (defined $failure) {
610             print "${te}$failure\n";
611             $::bad_files++;
612             if ($test =~ /^base/) {
613                 die "Failed a basic test ($test) -- cannot continue.\n";
614             }
615             ++$failed_tests{$test};
616         }
617         else {
618             if ($max) {
619                 my $elapsed;
620                 if ( $show_elapsed_time ) {
621                     $elapsed = sprintf( " %8.0f ms", (Time::HiRes::time() - $test_start_time) * 1000 );
622                 }
623                 else {
624                     $elapsed = "";
625                 }
626                 print "${te}ok$elapsed\n";
627                 $good_files++;
628             }
629             else {
630                 print "${te}skipped\n";
631                 $tested_files -= 1;
632             }
633         }
634     } # while tests
635
636     if ($::bad_files == 0) {
637         if ($good_files) {
638             print "All tests successful.\n";
639             # XXX add mention of 'perlbug -ok' ?
640         }
641         else {
642             die "FAILED--no tests were run for some reason.\n";
643         }
644     }
645     else {
646         my $pct = $tested_files ? sprintf("%.2f", ($tested_files - $::bad_files) / $tested_files * 100) : "0.00";
647         my $s = $::bad_files == 1 ? "" : "s";
648         warn "Failed $::bad_files test$s out of $tested_files, $pct% okay.\n";
649         for my $test ( sort keys %failed_tests ) {
650             print "\t$test\n";
651         }
652         warn <<'SHRDLU_1';
653 ### Since not all tests were successful, you may want to run some of
654 ### them individually and examine any diagnostic messages they produce.
655 ### See the INSTALL document's section on "make test".
656 SHRDLU_1
657         warn <<'SHRDLU_2' if $good_files / $total_files > 0.8;
658 ### You have a good chance to get more information by running
659 ###   ./perl harness
660 ### in the 't' directory since most (>=80%) of the tests succeeded.
661 SHRDLU_2
662         if (eval {require Config; import Config; 1}) {
663             if ($::Config{usedl} && (my $p = $::Config{ldlibpthname})) {
664                 warn <<SHRDLU_3;
665 ### You may have to set your dynamic library search path,
666 ### $p, to point to the build directory:
667 SHRDLU_3
668                 if (exists $ENV{$p} && $ENV{$p} ne '') {
669                     warn <<SHRDLU_4a;
670 ###   setenv $p `pwd`:\$$p; cd t; ./perl harness
671 ###   $p=`pwd`:\$$p; export $p; cd t; ./perl harness
672 ###   export $p=`pwd`:\$$p; cd t; ./perl harness
673 SHRDLU_4a
674                 } else {
675                     warn <<SHRDLU_4b;
676 ###   setenv $p `pwd`; cd t; ./perl harness
677 ###   $p=`pwd`; export $p; cd t; ./perl harness
678 ###   export $p=`pwd`; cd t; ./perl harness
679 SHRDLU_4b
680                 }
681                 warn <<SHRDLU_5;
682 ### for csh-style shells, like tcsh; or for traditional/modern
683 ### Bourne-style shells, like bash, ksh, and zsh, respectively.
684 SHRDLU_5
685             }
686         }
687     }
688     my ($user,$sys,$cuser,$csys) = times;
689     print sprintf("u=%.2f  s=%.2f  cu=%.2f  cs=%.2f  scripts=%d  tests=%d\n",
690         $user,$sys,$cuser,$csys,$tested_files,$totmax);
691     if ($ENV{PERL_VALGRIND}) {
692         my $s = $valgrind == 1 ? '' : 's';
693         print "$valgrind valgrind report$s created.\n", ;
694     }
695 }
696 exit ($::bad_files != 0);
697
698 # ex: set ts=8 sts=4 sw=4 noet: