From f80dd2469f0560714710f6f4e1d4905b17abb8bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Delanoy?= Date: Tue, 11 Mar 2014 00:16:27 +0100 Subject: [PATCH] cmd/tests: Correctly determine script path for root directories. --- programs/cmd/tests/batch.c | 10 ++++++++-- programs/cmd/tests/test_builtins.cmd | 7 +++++++ programs/cmd/tests/test_builtins.cmd.exp | 3 +++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/programs/cmd/tests/batch.c b/programs/cmd/tests/batch.c index c011d70a010..9df0bc5b501 100644 --- a/programs/cmd/tests/batch.c +++ b/programs/cmd/tests/batch.c @@ -459,8 +459,14 @@ START_TEST(batch) drive[0] = workdir[0]; drive[1] = workdir[1]; /* Should be ':' */ memcpy(path, workdir + drive_len, (workdir_len - drive_len) * sizeof(drive[0])); - path[workdir_len - drive_len] = '\\'; - path_len = workdir_len - drive_len + 1; + + /* Only add trailing backslash to 'path' for non-root directory */ + if (workdir_len - drive_len > 1) { + path[workdir_len - drive_len] = '\\'; + path_len = workdir_len - drive_len + 1; + } else { + path_len = 1; /* \ */ + } shortpath_len = GetShortPathNameA(path, shortpath, sizeof(shortpath)/sizeof(shortpath[0])); diff --git a/programs/cmd/tests/test_builtins.cmd b/programs/cmd/tests/test_builtins.cmd index 1d1eea4ffef..16fdd436b8c 100644 --- a/programs/cmd/tests/test_builtins.cmd +++ b/programs/cmd/tests/test_builtins.cmd @@ -308,6 +308,13 @@ set WINE_FOO= echo ------------ Testing variable expansion ------------ call :setError 0 +echo ~p0 should be path containing batch file +echo %~p0 +mkdir dummydir +cd dummydir +echo %~p0 +cd .. +rmdir dummydir echo ~dp0 should be directory containing batch file echo %~dp0 mkdir dummydir diff --git a/programs/cmd/tests/test_builtins.cmd.exp b/programs/cmd/tests/test_builtins.cmd.exp index 7380185a819..157598419ca 100644 --- a/programs/cmd/tests/test_builtins.cmd.exp +++ b/programs/cmd/tests/test_builtins.cmd.exp @@ -259,6 +259,9 @@ foo 'jim' 'apple"banana"grape' ------------ Testing variable expansion ------------ +~p0 should be path containing batch file +@path@ +@path@ ~dp0 should be directory containing batch file @pwd@\ @pwd@\