=pod

=head1 DESCRIPTION

Performs no real testing, but prints relevant information about the system it's 
being run on, such as the version numbers of dependencies, the values of 
important environment variables, etc.

=head1 SEE ALSO

L<Perl Testing in 2023|https://toby.ink/blog/2023/01/24/perl-testing-in-2023/>

L<TOBYINK/Type-Tiny/t/00-begin.t|https://metacpan.org/release/TOBYINK/Type-Tiny-2.004000/source/t/00-begin.t>

=head1 COPYRIGHT AND LICENSE

The original script is copyright (c) 2013-2014, 2017-2023 by Toby Inkster.

This is a free script; you can redistribute it and/or modify it under the same 
terms as the Perl 5 programming language system itself.

=cut

use strict;
use warnings;

use Win32;
use Test::More;

sub diag_version {
  my ($module, $version, $return) = @_;

  if ($module =~ /\//) {
    my @modules  = split /\s*\/\s*/, $module;
    my @versions = map diag_version($_, undef, 1), @modules;
    return @versions if $return;
    return diag sprintf('  %-43s %s', join("/", @modules), 
      join("/", @versions));
  }

  unless (defined $version) {
    eval "use $module ()";
    $version = $module->VERSION;
  }

  if (!defined $version) {
    return 'undef' if $return;
    return diag sprintf('  %-40s    undef', $module);
  }

  my ($major, $rest) = split /\./, $version;
  $major =~ s/^v//;
  return "$major\.$rest" if $return;
  return diag sprintf('  %-40s % 4d.%s', $module, $major, $rest);
}

sub diag_env {
  require B;
  my $var = shift;
  return diag sprintf('  $%-40s   %s', $var, 
    exists $ENV{$var} ? B::perlstring($ENV{$var}) : "undef");
}

use constant STRICT => !!grep { exists $ENV{$_} && $ENV{$_} } qw(
  PERL_STRICT
  EXTENDED_TESTING
  AUTHOR_TESTING
  RELEASE_TESTING
);

use constant MANUAL_TESTS => exists($ENV{MANUAL_TESTS})
                          && !$ENV{AUTOMATED_TESTING}
                          && !$ENV{NONINTERACTIVE_TESTING};

use constant PERL_ONLY => exists($ENV{PERL_ONLY}) && $ENV{PERL_ONLY};

sub banner {
  diag( ' ' );
  diag( '# ' x 36 );
  diag( ' ' );
  diag( "  OS:           $^O" );
  diag( "  PERL:         $]" );
  diag( "  CP:           ", Win32::GetConsoleOutputCP() );
  diag( "  STRICT:       ", STRICT       ? "enabled"  : "not enabled"  );
  diag( "  MANUAL_TESTS: ", MANUAL_TESTS ? "enabled"  : "not enabled"  );
  diag( "  PERL_ONLY:    ", PERL_ONLY    ? "enabled"  : "not enabled"  );
  diag( ' ' );
  diag( '# ' x 36 );
}

banner();

while (<DATA>) {
  chomp;
    
  if (/^#\s*(.*)$/ or /^$/) {
    diag($1 || "");
    next;
  }

  if (/^\$(.+)$/) {
    diag_env($1);
    next;
  }

  if (/^perl$/) {
    diag_version("Perl", $]);
    next;
  }
    
  diag_version($_) if /\S/;
}

diag( ' ' );
diag( '# ' x 36 );
diag( ' ' );

pass;
done_testing;

__DATA__

Devel::StrictMode
Importer
Import::Into
UNIVERSAL::Object
Win32::API
Win32::Console
Win32::Console::PatchForRT33513

autodie::Scope::Guard
B/B::Deparse
Class::Struct
constant
Cwd
Data::Dumper
Encode
English
Exporter
Hash::Util/Hash::Util::FieldHash
List::Util/Scalar::Util
overload
Module::Loaded
Params::Check
POSIX
subs
Symbol
Tie::Hash
utf8
Win32
Win32API::File
vars
version

Devel::Refcount
Test::More
Test::Exception

Class::XSAccessor
Devel::Cycle
Devel::GlobalDestruction
Moo/Moos/Moose
MRO::Compat
namespace::sweep
PerlX::Assert
Sub::Util
Type::Tiny/Types::Standard

$AUTOMATED_TESTING
$NONINTERACTIVE_TESTING
$PERL_STRICT
$EXTENDED_TESTING
$AUTHOR_TESTING
$RELEASE_TESTING

$NDEBUG
$PERL_NDEBUG
$MANUAL_TESTS
$PERL_PLATFORM_OVERRIDE

$PERLX_ASSERT_PP_FILTER
$PERL_ONLY