#!/usr/bin/env perl

# Some tests for 'darcs add'

use lib 'lib/perl';
use Test::More 'no_plan';
use Test::Darcs;
use Shell::Command;
use strict;
use warnings;

init_tmp_repo();

###

my $test_name = 'Make sure that messages about directories call them directories.';
mkpath 'foo.d';
mkpath 'oof.d';
darcs qw( add foo.d );
darcs qw( add oof.d );
# Try adding the same directory when it's already in the repo 
like(darcs(qw( add foo.d )), qr/directory/,$test_name);
like(darcs(qw( add foo.d oof.d )), qr/directories/,$test_name);

###

$test_name = 'Make sure that messages about files call them files.';
touch 'bar';
touch 'baz';
darcs qw( add bar ) ;
darcs qw( add baz ) ;
like(darcs(qw( add bar )), qr/following file is/, $test_name);
like(darcs(qw( add bar baz )), qr/following files are/, $test_name);

###

$test_name = 'Make sure that messages about both files and directories say so.';
like(darcs(qw( add bar foo.d )), qr/files and directories/, $test_name);

###

$test_name = 'Make sure that parent directories are added for files.';
mkpath 'a.d/aa.d/aaa.d';
mkpath 'b.d/bb.d';
touch 'a.d/aa.d/aaa.d/baz';
touch 'a.d/aa.d/aaa.d/bar';
like(darcs(qw( add a.d/aa.d/aaa.d/bar a.d/aa.d/aaa.d/baz b.d/bb.d )), qr/^$/, $test_name);
###

$test_name = 'Make sure that darcs doesn\'t complains about duplicate adds when adding parent dirs.';
mkpath 'c.d/';
touch 'c.d/baz';
like(darcs(qw( add c.d/baz c.d )), qr/^$/, $test_name);

###

$test_name = 'Make sure that add output looks good when adding files in subdir.';
mkpath 'd.d/';
touch 'd.d/foo';
like(darcs(qw(add -rv d.d)), qr/d.d\/foo/,$test_name);

{
    my $test_name = 'adding a non-existent dir and file gives the expected message';
    my $out = darcs(qw!add notadir/notafile!);
    like($out,qr/does not exist/i,$test_name);
}

chdir '../';
