=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 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 HEADLESS => !!grep { exists $ENV{$_} && $ENV{$_} } qw(
  AUTOMATED_TESTING
  NONINTERACTIVE_TESTING
);

use constant _WIN32 => ($^O eq 'MSWin32') 
                    && eval { require Win32::Console };

sub banner {
  diag( ' ' );
  diag( '# ' x 36 );
  diag( ' ' );
  diag( "  OS:       $^O" );
  diag( "  PERL:     $]" );
  diag( "  CP:       ", Win32::Console::_GetConsoleOutputCP() ) if _WIN32;
  diag( "  MODE:     ", HEADLESS ? "headless" : "normal" );
  diag( "  STRICT:   ", STRICT   ? "enabled"  : "not enabled" );
  diag( ' ' );
  diag( '# ' x 36 );
}

banner();

while (<DATA>) {
  chomp;
  s/\r\z//;

  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__

bytes
Carp
constant
Config
Exporter
IO::File
Params::Check
Scalar::Util
POSIX
Unicode::Normalize
Unicode::UCD
utf8
vars
version

Test::More
Data::Dumper
File::Temp

Getopt::Long
Encode
lib
List::Util
Pod::Usage
threads
Time::HiRes
Unicode::EastAsianWidth
Unicode::EastAsianWidth::Detect

Win32
Win32::API
Win32::Console
Win32API::File

$LANG
$LOCALE
$PATH_MAX
$TERM

$AUTOMATED_TESTING
$NONINTERACTIVE_TESTING

$PERL_STRICT
$EXTENDED_TESTING
$AUTHOR_TESTING
$RELEASE_TESTING

$NDEBUG
$PERL_NDEBUG

$TB_LIB_OPTS
$TB_OPT_EGC
$TB_OPT_PRINTF_BUF
$TB_OPT_READ_BUF
$TB_OPT_LIBC_WCHAR
$TB_OPT_ATTR_W
$TB_TERMINFO_DIR
$TB_RESIZE_FALLBACK_MS
$TB_DEBUG_LEVEL
$TB_OPT_TRUECOLOR
