Re: [PATCH STABLE V2] tests: run "cwd was removed" test only if cwd can actually be removed

2016-10-28 Thread Yuya Nishihara
On Fri, 28 Oct 2016 10:23:57 +0200, Pierre-Yves David wrote:
> > +@check("rmcwd", "can remove current working directory")
> > +def has_rmcwd():
> > +ocwd = os.getcwd()
> > +temp = tempfile.mkdtemp(dir='.', prefix=tempprefix)
> > +try:
> > +os.chdir(temp)
> > +# On Linux, 'rmdir .' isn't allowed, but the other names are okay.
> > +# On Solaris and Windows, the cwd can't be removed by any names.
> > +os.rmdir(os.getcwd())
> > +return True
> > +except OSError:
> > +return False
> 
> Maybe we should check the errno here too? (as a followup)

I copied it from the other filesystem checks. hghave.py seems not that strict
about handling of OSError.
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


Re: [PATCH STABLE V2] tests: run "cwd was removed" test only if cwd can actually be removed

2016-10-28 Thread Pierre-Yves David



On 10/27/2016 02:24 PM, Yuya Nishihara wrote:

# HG changeset patch
# User Yuya Nishihara 
# Date 1477489806 -32400
#  Wed Oct 26 22:50:06 2016 +0900
# Branch stable
# Node ID e405867f4c8a3f77d81ac44aeb75b7b739222c64
# Parent  b9f7b0c10027764cee77f9c6d61877fcffea837f
tests: run "cwd was removed" test only if cwd can actually be removed


I've pushed that one. Thanks.



On some platforms, cwd can't be removed. In which case, util.unlinkpath()
continues with no error since the failure of directory removal isn't critical.
So it doesn't make sense to run the test added by 90a6c18a7c1d on those
platforms. OTOH, we need to run the test in test-rebase-scenario-global.t
since the repository is referenced after that.

diff --git a/tests/hghave.py b/tests/hghave.py
--- a/tests/hghave.py
+++ b/tests/hghave.py
@@ -346,6 +346,21 @@ def has_hardlink():
 finally:
 os.unlink(fn)

+@check("rmcwd", "can remove current working directory")
+def has_rmcwd():
+ocwd = os.getcwd()
+temp = tempfile.mkdtemp(dir='.', prefix=tempprefix)
+try:
+os.chdir(temp)
+# On Linux, 'rmdir .' isn't allowed, but the other names are okay.
+# On Solaris and Windows, the cwd can't be removed by any names.
+os.rmdir(os.getcwd())
+return True
+except OSError:
+return False


Maybe we should check the errno here too? (as a followup)

Cheers,

--
Pierre-Yves David
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


[PATCH STABLE V2] tests: run "cwd was removed" test only if cwd can actually be removed

2016-10-27 Thread Yuya Nishihara
# HG changeset patch
# User Yuya Nishihara 
# Date 1477489806 -32400
#  Wed Oct 26 22:50:06 2016 +0900
# Branch stable
# Node ID e405867f4c8a3f77d81ac44aeb75b7b739222c64
# Parent  b9f7b0c10027764cee77f9c6d61877fcffea837f
tests: run "cwd was removed" test only if cwd can actually be removed

On some platforms, cwd can't be removed. In which case, util.unlinkpath()
continues with no error since the failure of directory removal isn't critical.
So it doesn't make sense to run the test added by 90a6c18a7c1d on those
platforms. OTOH, we need to run the test in test-rebase-scenario-global.t
since the repository is referenced after that.

diff --git a/tests/hghave.py b/tests/hghave.py
--- a/tests/hghave.py
+++ b/tests/hghave.py
@@ -346,6 +346,21 @@ def has_hardlink():
 finally:
 os.unlink(fn)
 
+@check("rmcwd", "can remove current working directory")
+def has_rmcwd():
+ocwd = os.getcwd()
+temp = tempfile.mkdtemp(dir='.', prefix=tempprefix)
+try:
+os.chdir(temp)
+# On Linux, 'rmdir .' isn't allowed, but the other names are okay.
+# On Solaris and Windows, the cwd can't be removed by any names.
+os.rmdir(os.getcwd())
+return True
+except OSError:
+return False
+finally:
+os.chdir(ocwd)
+
 @check("tla", "GNU Arch tla client")
 def has_tla():
 return matchoutput('tla --version 2>&1', br'The GNU Arch Revision')
diff --git a/tests/test-rebase-scenario-global.t 
b/tests/test-rebase-scenario-global.t
--- a/tests/test-rebase-scenario-global.t
+++ b/tests/test-rebase-scenario-global.t
@@ -756,12 +756,19 @@ Test that rebase is not confused by $CWD
   $ touch subfile
   $ hg add subfile
   $ hg commit -m 'second source with subdir'
+#if rmcwd
   $ hg rebase -b . -d 1 --traceback
   rebasing 2:779a07b1b7a0 "first source commit"
   current directory was removed
   (consider changing to repo root: $TESTTMP/cwd-vanish)
   rebasing 3:a7d6f3a00bf3 "second source with subdir" (tip)
   saved backup bundle to 
$TESTTMP/cwd-vanish/.hg/strip-backup/779a07b1b7a0-853e0073-backup.hg (glob)
+#else
+  $ hg rebase -b . -d 1 --traceback
+  rebasing 2:779a07b1b7a0 "first source commit"
+  rebasing 3:a7d6f3a00bf3 "second source with subdir" (tip)
+  saved backup bundle to 
$TESTTMP/cwd-vanish/.hg/strip-backup/779a07b1b7a0-853e0073-backup.hg (glob)
+#endif
 
 Test that rebase is done in topo order (issue5370)
 
diff --git a/tests/test-update-names.t b/tests/test-update-names.t
--- a/tests/test-update-names.t
+++ b/tests/test-update-names.t
@@ -73,6 +73,8 @@ Test update when two commits have symlin
 
 #endif
 
+#if rmcwd
+
 Test that warning is printed if cwd is deleted during update
   $ hg init r4 && cd r4
   $ mkdir dir
@@ -84,3 +86,5 @@ Test that warning is printed if cwd is d
   $ hg up -q null
   current directory was removed
   (consider changing to repo root: $TESTTMP/r1/r4)
+
+#endif
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel