[darcs-users] darcs patch: tests: quote the repo variable in mv.pl ... (and 1 more)

Petr Rockai me at mornfall.net
Tue Sep 2 20:26:04 UTC 2008


David Roundy <droundy at darcs.net> writes:
> Any chance anyone would be willing to review this test-suite change?
Reading...

> [convert mv.pl into shell.
> David Roundy <droundy at darcs.net>**20080902194056] move ./tests/mv.pl ./tests/mv-formerly-pl.sh
> hunk ./tests/mv-formerly-pl.sh 1
> -#!/usr/bin/env perl
> +#!/usr/bin/env bash
> +set -ev
>  
>  # Some tests for 'darcs mv'
>  
> hunk ./tests/mv-formerly-pl.sh 6
> -use lib 'lib/perl';
> -use Test::More tests => 13;
> -use Test::Darcs;
> -use Cwd 'abs_path';
> -use Shell::Command;
> -use strict;
> -use Carp;
> +## I would use the builtin !, but that has the wrong semantics.
> +not () { "$@" && exit 1 || :; }
>  
> hunk ./tests/mv-formerly-pl.sh 9
> -init_tmp_repo();
> +rm -rf temp
> +mkdir temp
> +cd temp
> +darcs init
>  
>  ###
>  
> hunk ./tests/mv-formerly-pl.sh 16
> -my $test_name = 'adding a directory with more than one ../ in it should work.';
> -mkpath('foo.d/second/third','foo.d/other') || die "mkpath failed: $!";
> +echo adding a directory with more than one .. in it should work.
> +mkdir foo.d
> +mkdir foo.d/second
> +mkdir foo.d/second/third
> +mkdir foo.d/other
>  
> hunk ./tests/mv-formerly-pl.sh 22
> -my $out = `ls ./foo.d/other`;
> -print $out;
>  
> hunk ./tests/mv-formerly-pl.sh 23
> -touch './foo.d/other/date.t';
> -darcs qw/add -r foo.d/;
> +touch ./foo.d/other/date.t
> +darcs add -r foo.d
>  
> hunk ./tests/mv-formerly-pl.sh 26
> -chdir 'foo.d/second/third';
> +cd foo.d/second/third
>  
> hunk ./tests/mv-formerly-pl.sh 28
> -my $mv_out = darcs qw!mv ../../other/date.t ../../other/date_moved.t!;
> -unlike($mv_out, qr/darcs failed/, $test_name);
> +darcs mv ../../other/date.t ../../other/date_moved.t
>  
> hunk ./tests/mv-formerly-pl.sh 30
> -chdir '../../../';
> -$test_name = 'refuses to move to an existing file';
> -touch 'ping';
> -touch 'pong';
> -darcs qw/add ping pong/;
> -like(darcs(qw( mv ping pong )), qr/already exists/,$test_name);
> +cd ../../..
> +echo darcs refuses to move to an existing file
> +touch ping
> +touch pong
> +darcs add ping pong
> +not darcs mv ping pong &> out
> +cat out
> +grep 'already exists' out
>  
-- (just noting down that it all seems equivalent up to this point; I am not
   sure, but the not's might be a little more strict, I don't know if like
   checks for error codes -- it doesn't seem to have information for that)
>  # case sensitivity series
>  # -----------------------
> hunk ./tests/mv-formerly-pl.sh 41
> -# these are tests designed to check out darcs behave wrt to renames 
> +# these are tests designed to check out darcs behave wrt to renames
>  # where the case of the file becomes important
>  
>  # are we on a case sensitive file system?
> hunk ./tests/mv-formerly-pl.sh 45
> -my $is_case_sensitive = 1;
> -touch 'is_it_cs';
> -touch 'IS_IT_CS';
> -my @csStat1=stat 'is_it_cs';
> -my @csStat2=stat 'IS_IT_CS';
> -if ($csStat1[1] eq $csStat2[1]) {
> -  $is_case_sensitive = 0;
> -} 
> -my $already_exists = qr/already exists/;
> -my $no_test_cuz_insensitive = "This test can't be run becase the file system is case insensitive";
> +touch is_it_cs
> +rm -f IS_IT_CS
> +
> +if test -e is_it_cs; then
> +  echo This is a case-sensitive file system.
> +else
> +  echo This is NOT a case-sensitive file system.
> +fi
>  
>  # if the new file already exists - we don't allow it
>  # basically the same test as mv ping pong, except we do mv ping PING
> hunk ./tests/mv-formerly-pl.sh 57
>  # and both ping and PING exist on the filesystem
> -$test_name = "case sensitivity - simply don't allow mv if new file exists";
> +echo "case sensitivity - simply don't allow mv if new file exists"
>  touch 'cs-n-1'; touch 'CS-N-1';
>  touch 'cs-y-1'; touch 'CS-Y-1';
> hunk ./tests/mv-formerly-pl.sh 60
> -darcs qw/add cs-n-1 cs-y-1/;
> -if ($is_case_sensitive) {
> +darcs add cs-n-1 cs-y-1
> +
> +if test -e is_it_cs; then
>    # regardless of case-ok, we do NOT want this mv at all
> hunk ./tests/mv-formerly-pl.sh 64
> -  like(darcs(qw( mv           cs-n-1 CS-N-1)), $already_exists, $test_name);
> -  like(darcs(qw( mv --case-ok cs-y-1 CS-Y-1)), $already_exists, $test_name);
> -} else {
> -  pass ( $no_test_cuz_insensitive );
> -  pass ( $no_test_cuz_insensitive );
> -}
> +  not darcs mv cs-n-1 CS-Y-1 &> out
> +  cat out
> +  grep 'already exists' out
> +
> +  not darcs mv --case-ok cs-n-1 CS-Y-1 &> out
> +  cat out
> +  grep 'already exists' out
> +fi
-- ack
>  
>  # if the new file does not already exist - we allow it
> hunk ./tests/mv-formerly-pl.sh 74
> -$test_name = "case sensitivity - the new file does *not* exist";
> -touch 'cs-n-2'; 
> -touch 'cs-y-2'; 
> -darcs qw/add cs-n-2/;
> +echo "case sensitivity - the new file does *not* exist"
> +touch 'cs-n-2';
> +touch 'cs-y-2';
> +darcs add cs-n-2 cs-y-2
>  # these mv's should be allowed regardless of flag or filesystem
> hunk ./tests/mv-formerly-pl.sh 79
> -unlike(darcs(qw( mv           cs-n-2 CS-N-2)), $already_exists, $test_name);
> -unlike(darcs(qw( mv --case-ok cs-y-2 CS-Y-2)), $already_exists, $test_name);
> +darcs mv cs-n-2 CS-N-2
> +darcs mv --case-ok cs-y-2 CS-Y-2
-- ack
>  
>  # parasites - do not accidentally overwrite a file just because it has a
>  # similar name and points to the same inode.  We want to check if a file if the
> hunk ./tests/mv-formerly-pl.sh 85
>  # same NAME already exists - we shouldn't care about what the actual file is!
> -$test_name = "case sensitivity - inode check"; 
> -touch 'cs-n-3'; 
> -touch 'cs-y-3'; 
> -darcs qw/add cs-n-3 cs-y-3/;
> -if ($^O =~ /(msys|win32)/i) {
> -  # afaik, windows does not support hard links
> -  pass ('cannot run this test -- windows does not have hard links');
> -  pass ('cannot run this test -- windows does not have hard links');
> -} elsif ($is_case_sensitive) {
> -  `ln cs-n-3 CS-N-3`;
> -  `ln cs-y-3 CS-Y-3`;
> +echo "case sensitivity - inode check";
> +touch 'cs-n-3';
> +touch 'cs-y-3';
> +darcs add cs-n-3 cs-y-3
> +
> +if ln cs-n-3 CS-N-3; then # checking if we support hard links
> +  ln cs-y-3 CS-Y-3
>    # regardless of case-ok, we do NOT want this mv at all
-- the "if ln ..." check might want to be validated by someone on cygwin/msys?
I can only testify that on Linux with a filesystem without hardlinks, it
properly errors out with ln: creating hard link `b' => `a': Operation not
permitted

> hunk ./tests/mv-formerly-pl.sh 93
> -  like(darcs(qw( mv           cs-n-3 CS-N-3)), $already_exists, $test_name);
> -  like(darcs(qw( mv --case-ok cs-y-3 CS-Y-3)), $already_exists, $test_name);
> -} else {
> -  pass ( $no_test_cuz_insensitive );
> -  pass ( $no_test_cuz_insensitive );
> -}
> +  not darcs mv cs-n-3 CS-N-3 &> out
> +  cat out
> +  grep 'already exists' out
> +
> +  not darcs mv --case-ok cs-y-3 CS-Y-3 &> out
> +  cat out
> +  grep 'already exists' out
> +fi
>  
>  # parasites - we don't allow weird stuff like mv foo bar/foo just because
>  # we opened up some crazy exception based on foo's name
> hunk ./tests/mv-formerly-pl.sh 104
> -$test_name = 'refuses to move to an existing file with same name, different path';
> +echo 'refuses to move to an existing file with same name, different path'
>  touch 'cs-n-4'; touch 'foo.d/cs-n-4';
>  touch 'cs-y-4'; touch 'foo.d/cs-y-4';
> hunk ./tests/mv-formerly-pl.sh 107
> -darcs qw/add cs-n-4/;
> -# regardless of case-ok, we do NOT want this mv at all 
> -like(darcs(qw( mv           cs-n-4 foo.d/cs-n-4)), $already_exists, $test_name);
> -like(darcs(qw( mv --case-ok cs-y-4 foo.d/cs-y-4)), $already_exists, $test_name);
> +darcs add cs-n-4
> +# regardless of case-ok, we do NOT want this mv at all
> +not darcs mv cs-n-4 foo.d/cs-n-4 &> out
> +cat out
> +grep 'already exists' out
> +
> +not darcs mv --case-ok cs-y-4 foo.d/cs-y-4 &> out
> +cat out
> +grep 'already exists' out
>  
>  # ---------------------------
>  # end case sensitivity series
-- hooray...
> hunk ./tests/mv-formerly-pl.sh 120
>  
> -touch 'abs_path.t';
> -darcs qw/add abs_path.t/;
> +touch abs_path.t
> +darcs add abs_path.t
> +REPO_ABS=`pwd`
(correct I think, although I tend to say "`pwd`" myself, ... (possibly just a
bad habit ...))
> +darcs mv "$REPO_ABS/abs_path.t" abs_path_new.t
> +darcs mv abs_path_new.t "$REPO_ABS/abs_path.t"
>  
> hunk ./tests/mv-formerly-pl.sh 126
> -{
> -  my $repo_abs = abs_path();
> -  chomp ($repo_abs);
> -  my $mv_out = darcs("mv \"$repo_abs/abs_path.t\" abs_path_new.t");
> -  unlike($mv_out, qr/darcs failed/, 'mv should work with absolute path as a src argument.');
> -}
> -
> -{
> -  my $repo_abs = abs_path();
> -  chomp ($repo_abs);
> -  my $mv_out = darcs("mv abs_path_new.t \"$repo_abs/abs_path.t\"");
> -  unlike($mv_out, qr/darcs failed/, 'mv should work with absolute path as a target argument.');
> -}
(Hmm. Not a review thing, but are we sure that all darcs failures induce a
"darcs failed" message? I imagine this might be a weakness in the perl tests?)
>  
>  # issue608
> hunk ./tests/mv-formerly-pl.sh 128
> -{
> +
>     touch 'gonna_be_deleted';
> hunk ./tests/mv-formerly-pl.sh 130
> -   darcs "add gonna_be_deleted";
> -   darcs "record -am 'added doomed file'";
> -   rm_rf "gonna_be_deleted"; 
> -   darcs "record -am 'deleted file'"; 
> +   darcs add gonna_be_deleted
> +   darcs record -am 'added doomed file'
> +   rm gonna_be_deleted
> +   darcs record -am 'deleted file'
>     touch 'new_file';
> hunk ./tests/mv-formerly-pl.sh 135
> -   darcs "add new_file";
> -   my $out = darcs "mv new_file gonna_be_deleted";
> -   is($out, "", "darcs mv should succeed");
> -}
> +   darcs add new_file
> +   darcs mv new_file gonna_be_deleted
Aye, got through to the end.

Yours,
   Petr.

PS: Yeah, I apparently didn't manage to snuck in a karma whore joke anywhere
this time. Bummer.

-- 
Peter Rockai | me()mornfall!net | prockai()redhat!com
 http://blog.mornfall.net | http://web.mornfall.net

"In My Egotistical Opinion, most people's C programs should be
 indented six feet downward and covered with dirt."
     -- Blair P. Houghton on the subject of C program indentation


More information about the darcs-users mailing list