<commit_before>#! perl
# Copyright (C) 2007, The Perl Foundation.
# $Id$
# auto_msvc-01.t

use strict;
use warnings;
use Test::More tests => 39;
use Carp;
use lib qw( lib t/configure/testlib );
use_ok('config::auto::msvc');
use Parrot::Configure;
use Parrot::Configure::Options qw( process_options );
use Parrot::Configure::Test qw(
    test_step_thru_runstep
    test_step_constructor_and_description
);
use IO::CaptureOutput qw| capture |;

########## Win32 ##########

my $args = process_options( {
    argv            => [],
    mode            => q{configure},
} );

my $conf = Parrot::Configure->new();

my $pkg = q{auto::msvc};

$conf->add_steps($pkg);

my $serialized = $conf->pcfreeze();

$conf->options->set(%{$args});
my $step = test_step_constructor_and_description($conf);
SKIP: {
    skip 'MSVC is Windows only', 1 unless $^O =~ /Win32/i;
    ok($step->runstep($conf), "runstep() returned true value");
}

$conf->replenish($serialized);

########## _evaluate_msvc() ##########

$args = process_options( {
    argv            => [],
    mode            => q{configure},
} );
$conf->options->set(%{$args});
$step = test_step_constructor_and_description($conf);
my $msvcref = { _MSC_VER => 1399 };
ok($step->_evaluate_msvc($conf, $msvcref),
    "_evaluate_msvc returned true value");
is($step->result, 'yes', "Got expected result");
is($conf->data->get('msvcversion'), '13.99',
    "Got expected msvc version string");

$conf->replenish($serialized);

########## _evaluate_msvc() ##########

$args = process_options( {
    argv            => [],
    mode            => q{configure},
} );
$conf->options->set(%{$args});
$step = test_step_constructor_and_description($conf);
$msvcref = { _MSC_VER => 1400 };
ok($step->_evaluate_msvc($conf, $msvcref),
    "_evaluate_msvc returned true value");
is($step->result, 'yes', "Got expected result");
is($conf->data->get('msvcversion'), '14.0',
    "Got expected msvc version string");
like(
    $conf->data->get('ccflags'),
    qr/\-D_CRT_SECURE_NO_DEPRECATE/,
    "ccflags appropriately adjusted given MSVC version"
);

$conf->replenish($serialized);

########## _handle_not_msvc() ##########

$args = process_options( {
    argv            => [],
    mode            => q{configure},
} );
$conf->options->set(%{$args});
$step = test_step_constructor_and_description($conf);

my ($status, $major, $minor, $verbose);

$major = 13;
$minor = 99;
$verbose = undef;
$status = $step->_handle_not_msvc($conf, $major, $minor, $verbose);
ok(! defined $status, 'sub return value, as expected, not yet set');
ok(! $step->result(), 'result, as expected, not yet set');

$major = 13;
$minor = undef;
$verbose = undef;
$status = $step->_handle_not_msvc($conf, $major, $minor, $verbose);
ok($status, 'sub return value, as expected, set to true value');
is($step->result(), q{no}, 'Got expected result');
ok(! defined ($conf->data->get( 'msvcversion' )),
    'msvcversion is undef, as expected');

$major = undef;
$minor = 99;
$verbose = undef;
$status = $step->_handle_not_msvc($conf, $major, $minor, $verbose);
ok($status, 'sub return value, as expected, set to true value');
is($step->result(), q{no}, 'Got expected result');
ok(! defined ($conf->data->get( 'msvcversion' )),
    'msvcversion is undef, as expected');

{
    my $stdout;
    $major = undef;
    $minor = undef;
    $verbose = 1;
    capture(
        sub { $status = 
            $step->_handle_not_msvc($conf, $major, $minor, $verbose); },
        \$stdout,
    );
    ok($status, 'sub return value, as expected, set to true value');
    is($step->result(), q{no}, 'Got expected result');
    ok(! defined ($conf->data->get( 'msvcversion' )),
        'msvcversion is undef, as expected');
    like($stdout, qr/\(no\)/, "Got expected verbose output");
    # Prepare for the next test.
    $step->set_result(undef);
}

########## _compose_msvcversion() ##########

my $msvcversion;

$major = 13;
$minor = 99;
$verbose = undef;
$msvcversion = $step->_compose_msvcversion($major, $minor, $verbose);
is($msvcversion, '13.99', "Got expected MSVC version");
is($step->result(), 'yes', "Got expected result");
$step->set_result(undef);

{
    my $stdout;
    $major = 13;
    $minor = 99;
    $verbose = 1;
    capture(
        sub { $msvcversion =
            $step->_compose_msvcversion($major, $minor, $verbose); },
        \$stdout,
    );
    is($msvcversion, '13.99', "Got expected MSVC version");
    is($step->result(), 'yes', "Got expected result");
    like($stdout, qr/yep:\s+$major\.$minor/, "Got expected verbose output");
    $step->set_result(undef);
}

pass("Completed all tests in $0");

################### DOCUMENTATION ###################

=head1 NAME

auto_msvc-01.t - test auto::msvc

=head1 SYNOPSIS

    % prove t/steps/auto_msvc-01.t

=head1 DESCRIPTION

The files in this directory test functionality used by F<Configure.pl>.

The tests in this file test auto::msvc.  Some tests run only if the system is
Win32.

=head1 AUTHOR

<NAME>

=head1 SEE ALSO

config::auto::msvc, F<Configure.pl>.

=cut

# Local Variables:
#   mode: cperl
#   cperl-indent-level: 4
#   fill-column: 100
# End:
# vim: expandtab shiftwidth=4:
<commit_msg>Reverting to r29867 per failure report from fperrad.<commit_after>#! perl
# Copyright (C) 2007, The Perl Foundation.
# $Id$
# auto_msvc-01.t

use strict;
use warnings;
use Test::More tests => 44;
use Carp;
use lib qw( lib t/configure/testlib );
use_ok('config::init::defaults');
use_ok('config::auto::msvc');
use Parrot::Configure;
use Parrot::Configure::Options qw( process_options );
use Parrot::Configure::Test qw(
    test_step_thru_runstep
    test_step_constructor_and_description
);
use IO::CaptureOutput qw| capture |;

########## Win32 ##########

my $args = process_options( {
    argv            => [],
    mode            => q{configure},
} );

my $conf = Parrot::Configure->new();

test_step_thru_runstep($conf, q{init::defaults}, $args);

my $pkg = q{auto::msvc};

$conf->add_steps($pkg);

my $serialized = $conf->pcfreeze();

$conf->options->set(%{$args});
my $step = test_step_constructor_and_description($conf);
SKIP: {
    skip 'MSVC is Windows only', 1 unless $^O =~ /Win32/i;
    ok($step->runstep($conf), "runstep() returned true value");
}

$conf->replenish($serialized);

########## _evaluate_msvc() ##########

$args = process_options( {
    argv            => [],
    mode            => q{configure},
} );
$conf->options->set(%{$args});
$step = test_step_constructor_and_description($conf);
my $msvcref = { _MSC_VER => 1399 };
ok($step->_evaluate_msvc($conf, $msvcref),
    "_evaluate_msvc returned true value");
is($step->result, 'yes', "Got expected result");
is($conf->data->get('msvcversion'), '13.99',
    "Got expected msvc version string");

$conf->replenish($serialized);

########## _evaluate_msvc() ##########

$args = process_options( {
    argv            => [],
    mode            => q{configure},
} );
$conf->options->set(%{$args});
$step = test_step_constructor_and_description($conf);
$msvcref = { _MSC_VER => 1400 };
ok($step->_evaluate_msvc($conf, $msvcref),
    "_evaluate_msvc returned true value");
is($step->result, 'yes', "Got expected result");
is($conf->data->get('msvcversion'), '14.0',
    "Got expected msvc version string");
like(
    $conf->data->get('ccflags'),
    qr/\-D_CRT_SECURE_NO_DEPRECATE/,
    "ccflags appropriately adjusted given MSVC version"
);

$conf->replenish($serialized);

########## _handle_not_msvc() ##########

$args = process_options( {
    argv            => [],
    mode            => q{configure},
} );
$conf->options->set(%{$args});
$step = test_step_constructor_and_description($conf);

my ($status, $major, $minor, $verbose);

$major = 13;
$minor = 99;
$verbose = undef;
$status = $step->_handle_not_msvc($conf, $major, $minor, $verbose);
ok(! defined $status, 'sub return value, as expected, not yet set');
ok(! $step->result(), 'result, as expected, not yet set');

$major = 13;
$minor = undef;
$verbose = undef;
$status = $step->_handle_not_msvc($conf, $major, $minor, $verbose);
ok($status, 'sub return value, as expected, set to true value');
is($step->result(), q{no}, 'Got expected result');
ok(! defined ($conf->data->get( 'msvcversion' )),
    'msvcversion is undef, as expected');

$major = undef;
$minor = 99;
$verbose = undef;
$status = $step->_handle_not_msvc($conf, $major, $minor, $verbose);
ok($status, 'sub return value, as expected, set to true value');
is($step->result(), q{no}, 'Got expected result');
ok(! defined ($conf->data->get( 'msvcversion' )),
    'msvcversion is undef, as expected');

{
    my $stdout;
    $major = undef;
    $minor = undef;
    $verbose = 1;
    capture(
        sub { $status = 
            $step->_handle_not_msvc($conf, $major, $minor, $verbose); },
        \$stdout,
    );
    ok($status, 'sub return value, as expected, set to true value');
    is($step->result(), q{no}, 'Got expected result');
    ok(! defined ($conf->data->get( 'msvcversion' )),
        'msvcversion is undef, as expected');
    like($stdout, qr/\(no\)/, "Got expected verbose output");
    # Prepare for the next test.
    $step->set_result(undef);
}

########## _compose_msvcversion() ##########

my $msvcversion;

$major = 13;
$minor = 99;
$verbose = undef;
$msvcversion = $step->_compose_msvcversion($major, $minor, $verbose);
is($msvcversion, '13.99', "Got expected MSVC version");
is($step->result(), 'yes', "Got expected result");
$step->set_result(undef);

{
    my $stdout;
    $major = 13;
    $minor = 99;
    $verbose = 1;
    capture(
        sub { $msvcversion =
            $step->_compose_msvcversion($major, $minor, $verbose); },
        \$stdout,
    );
    is($msvcversion, '13.99', "Got expected MSVC version");
    is($step->result(), 'yes', "Got expected result");
    like($stdout, qr/yep:\s+$major\.$minor/, "Got expected verbose output");
    $step->set_result(undef);
}

pass("Completed all tests in $0");

################### DOCUMENTATION ###################

=head1 NAME

auto_msvc-01.t - test auto::msvc

=head1 SYNOPSIS

    % prove t/steps/auto_msvc-01.t

=head1 DESCRIPTION

The files in this directory test functionality used by F<Configure.pl>.

The tests in this file test auto::msvc.  Some tests run only if the system is
Win32.

=head1 AUTHOR

<NAME>

=head1 SEE ALSO

config::auto::msvc, F<Configure.pl>.

=cut

# Local Variables:
#   mode: cperl
#   cperl-indent-level: 4
#   fill-column: 100
# End:
# vim: expandtab shiftwidth=4:

{'fraction_non_alphanumeric': 0.2005365526492287, 'fraction_numerical': 0.014084507042253521, 'mean_word_length': 4.0966796875, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 123, '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': '5487893', 'n_tokens_mistral': 3785, 'n_tokens_neox': 3549, 'n_words': 887}