Slic3r/t/retraction.t

50 lines
1.4 KiB
Perl
Raw Normal View History

2012-12-05 03:39:40 +04:00
use Test::More tests => 2;
2012-11-21 23:41:14 +04:00
use strict;
use warnings;
BEGIN {
use FindBin;
use lib "$FindBin::Bin/../lib";
}
use Slic3r;
use Slic3r::Test;
2012-12-05 03:39:40 +04:00
my $config = Slic3r::Config->new_from_defaults;
my $test = sub {
2012-11-21 23:41:14 +04:00
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
my $retracted = 1; # ignore the first travel move from home to first point
Slic3r::Test::GCodeReader->new(gcode => Slic3r::Test::gcode($print))->parse(sub {
my ($self, $cmd, $args, $info) = @_;
if ($info->{retracting}) {
2012-12-05 03:39:40 +04:00
fail 'retracted by the correct amount'
if !Slic3r::Test::compare(-$info->{dist_E}, $config->retract_length->[0]);
2012-11-21 23:41:14 +04:00
$retracted = 1;
}
if ($info->{extruding}) {
2012-12-05 03:39:40 +04:00
if ($retracted) {
fail 'unretracted by the correct amount'
if !Slic3r::Test::compare($info->{dist_E}, $config->retract_length->[0] + $config->retract_restart_extra->[0]);
$retracted = 0;
}
2012-11-21 23:41:14 +04:00
}
if ($info->{travel} && $info->{dist_XY} >= $config->retract_before_travel->[0]) {
2012-12-05 03:39:40 +04:00
fail 'retracted before long travel move' if !$retracted;
2012-11-21 23:41:14 +04:00
}
});
2012-12-05 03:39:40 +04:00
1;
};
$config->set('retract_length', [1.5]);
$config->set('retract_before_travel', [3]);
ok $test->(), 'retraction';
2012-11-21 23:41:14 +04:00
2012-12-05 03:39:40 +04:00
$config->set('retract_restart_extra', [1]);
ok $test->(), 'retraction with restart extra length';
2012-11-21 23:41:14 +04:00
__END__