# -*- cperl -*-
use strict;
use Benchmark;

# Create a new attribute type, and attach one string attribute of this type
# to the current directory.
# Check that it succeeded, and cleanup.
# This requires that the string value is properly quoted.
# This case tests a regression which was introduced at some point.
#
# This test case does not test the presence of triggers.

use Test::More tests => 8;
select(STDERR); $| = 1; select(STDOUT); $| = 1;
use ClearCase::Argv qw(chdir);
use Argv 1.25;

ClearCase::Argv->summary;      # start keeping stats
ClearCase::Argv->ipc(1);
my $ct = ClearCase::Argv->new({autochomp=>1});
my $silent = $ct->clone;
$silent->stdout(0);
$silent->stderr(0);
die "This test needs to be run in a view, in a vob\n"
  unless $ct->argv(qw(ls -s -d .))->stderr(0)->qx;

my @attype = sort $ct->argv(qw(lstype -kind attype -s -obs))->qx;
my $attype = @attype? $attype[$#attype] . 'Z' : 'FOO';
$silent->argv(qw(mkattype -nc), $attype)->system and die "Aborted: $!\n";
sub one_pass {
  my $ipc = shift;
  my $mode = $ipc? 'ipc' : 'fork';
  $silent->ipc($ipc);
  my $value = q("foo");
  ok(!$silent->argv(qw(mkattr -rep), $attype, $value, '.')->system,
     "String attribute set to $value ($mode mode)");
  $value = q("O'Toole");
  ok(!$silent->argv(qw(mkattr -rep), $attype, $value, '.')->system,
     "String attribute set to $value ($mode mode)");
  $value = q("*test*");
  ok(!$silent->argv(qw(mkattr -rep), $attype, $value, '.')->system,
     "String attribute set to $value ($mode mode)");
  $value = q("Line one\nLine two");
  ok(!$silent->argv(qw(mkattr -rep), $attype, $value, '.')->system,
     "String attribute set to $value ($mode mode)");
}
one_pass(0);
one_pass(1);

$silent->argv(qw(rmtype -f -rmall), "attype:$attype")->system;

print STDERR "\n", ClearCase::Argv->summary;   # print out the stats we kept
