* [PATCH] Add basic test-script for git-submodule
@ 2007-05-27 20:34 Lars Hjemli
2007-05-29 7:10 ` Junio C Hamano
0 siblings, 1 reply; 9+ messages in thread
From: Lars Hjemli @ 2007-05-27 20:34 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Johannes Schindelin, git
This test verifies the basic operations in git-submodule, i.e. that it is
able to clone and update a submodule repository, that its status output is
sane, and that it errors out when the submodule path is occupied during
init.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
---
Finally the test-script emerges. Btw, thanks for fixing my broken submodule
patch :)
t/t7400-submodule-basic.sh | 82 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 82 insertions(+), 0 deletions(-)
create mode 100755 t/t7400-submodule-basic.sh
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
new file mode 100755
index 0000000..2212b29
--- /dev/null
+++ b/t/t7400-submodule-basic.sh
@@ -0,0 +1,82 @@
+#!/bin/sh
+#
+# Copyright (c) 2007 Lars Hjemli
+#
+
+test_description='Basic submodule support in porcelain
+
+This test tries to run the init, update and status commands of git-submodule
+with a known good setup (and two known bad)
+'
+
+. ./test-lib.sh
+
+
+# create a submodule repository
+mkdir lib && cd lib
+git-init >/dev/null
+echo a >a && git-add a && git-commit -q -m "submodule commit 1"
+git-tag -a -m "rev-1" rev-1
+rev1=$(git-rev-parse HEAD)
+cd ..
+
+# add submodule and other files to super repo
+echo a >a && echo z >z
+git-add a lib z && git-commit -q -m "super commit 1"
+
+# move submodule to another location, register repo url in .gitmodules
+mv lib .subrepo
+GIT_CONFIG=.gitmodules git-config module.lib.url ./.subrepo
+
+test_expect_success 'status is "missing"' \
+ 'git-submodule status | grep "^-$rev1"'
+
+# make sure 'init' will not overwrite a regular file
+touch lib
+test_expect_failure 'init fails when path is used by a file' \
+ 'git-submodule init'
+
+# make sure 'init' will not overwrite a nonempty directory
+rm lib
+mkdir -p lib/foo
+test_expect_failure 'init fails when path is used by a nonempty directory' \
+ 'git-submodule init'
+
+# turn lib into an empty directory, just like git-checkout would do
+rmdir lib/foo
+test_expect_success 'init works when path is an empty dir' \
+ 'git-submodule init && test -d lib/.git && git-diff --exit-code'
+
+head=$(cd lib && git-rev-parse HEAD)
+test_expect_success 'submodule HEAD should match rev1' \
+ 'test "$head" = "$rev1"'
+
+test_expect_success 'status is "up-to-date" after init' \
+ 'git-submodule status | grep "^ $rev1"'
+
+# change the submodule HEAD
+cd lib
+echo b >b && git-add b && git-commit -q -m "submodule commit 2"
+rev2=$(git-rev-parse HEAD)
+cd ..
+
+test_expect_success 'status is "modified" after submodule commit' \
+ 'git-submodule status | grep "^\+$rev2"'
+
+test_expect_success 'the --cached sha1 should be rev1' \
+ 'git-submodule --cached status | grep "^\+$rev1"'
+
+test_expect_failure 'git-diff --exit-code reports local modifications' \
+ 'git-diff --exit-code'
+
+test_expect_success 'update should checkout the correct commit' \
+ 'git-submodule update && git-diff --exit-code'
+
+head=$(cd lib && git-rev-parse HEAD)
+test_expect_success 'submodule HEAD should match rev1' \
+ 'test "$head" = "$rev1"'
+
+test_expect_success 'status is "up-to-date" after update' \
+ 'git-submodule status | grep "^ $rev1"'
+
+test_done
--
1.5.2.74.g6b2d
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] Add basic test-script for git-submodule
2007-05-27 20:34 [PATCH] Add basic test-script for git-submodule Lars Hjemli
@ 2007-05-29 7:10 ` Junio C Hamano
2007-05-30 6:48 ` Lars Hjemli
0 siblings, 1 reply; 9+ messages in thread
From: Junio C Hamano @ 2007-05-29 7:10 UTC (permalink / raw)
To: Lars Hjemli; +Cc: Johannes Schindelin, git
Lars Hjemli <hjemli@gmail.com> writes:
> +# create a submodule repository
> +mkdir lib && cd lib
> +git-init >/dev/null
> +echo a >a && git-add a && git-commit -q -m "submodule commit 1"
> +git-tag -a -m "rev-1" rev-1
> +rev1=$(git-rev-parse HEAD)
> +cd ..
> +
> +# add submodule and other files to super repo
> +echo a >a && echo z >z
> +git-add a lib z && git-commit -q -m "super commit 1"
> +
> +# move submodule to another location, register repo url in .gitmodules
> +mv lib .subrepo
> +GIT_CONFIG=.gitmodules git-config module.lib.url ./.subrepo
We typically try to catch malfunction even while setting up the test case.
> +test_expect_success 'status is "missing"' \
> + 'git-submodule status | grep "^-$rev1"'
> +
> +# make sure 'init' will not overwrite a regular file
> +touch lib
> +test_expect_failure 'init fails when path is used by a file' \
> + 'git-submodule init'
I am guilty for introducing "expect-failure", but it is usually
a mistake to use it unless you are testing something very trivial.
For example, for this case, you would want to make sure the
command "git-submodule init" exits with non-zero status, but
also you would want to make sure that it does not disturb the
existing file "lib". You might also want to see if the command
gives the right error message (or status code) as well, although
typically the wording of error message is subject to change, so
we tend to try not to be too strict about it.
In any case, I would probably write this part of the code like
this:
test_expect_success 'init fails when path is used by a file' '
echo hello >lib &&
if git-submodule init
then
echo "Oops, should have failed"
false
elif test -f lib && test "$(cat lib)" = hello
then
: happy
else
echo "Oops, failed but lib file was molested"
false
fi
'
Later when somebody tries to improve git-submodule and botches,
he can run the test with "-i -v" and observe which "Oops" comes
out to see why the test failed -- it would give him a clue on
how he broke it.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] Add basic test-script for git-submodule
2007-05-29 7:10 ` Junio C Hamano
@ 2007-05-30 6:48 ` Lars Hjemli
2007-06-01 3:54 ` Junio C Hamano
0 siblings, 1 reply; 9+ messages in thread
From: Lars Hjemli @ 2007-05-30 6:48 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Johannes Schindelin, git
On 5/29/07, Junio C Hamano <junkio@cox.net> wrote:
> Lars Hjemli <hjemli@gmail.com> writes:
>
> > +# create a submodule repository
> > +mkdir lib && cd lib
> > +git-init >/dev/null
> > +echo a >a && git-add a && git-commit -q -m "submodule commit 1"
> > +git-tag -a -m "rev-1" rev-1
> > +rev1=$(git-rev-parse HEAD)
> > +cd ..
> > +
> > +# add submodule and other files to super repo
> > +echo a >a && echo z >z
> > +git-add a lib z && git-commit -q -m "super commit 1"
> > +
> > +# move submodule to another location, register repo url in .gitmodules
> > +mv lib .subrepo
> > +GIT_CONFIG=.gitmodules git-config module.lib.url ./.subrepo
>
> We typically try to catch malfunction even while setting up the test case.
Ok
>
> > +test_expect_success 'status is "missing"' \
> > + 'git-submodule status | grep "^-$rev1"'
> > +
> > +# make sure 'init' will not overwrite a regular file
> > +touch lib
> > +test_expect_failure 'init fails when path is used by a file' \
> > + 'git-submodule init'
>
> I am guilty for introducing "expect-failure", but it is usually
> a mistake to use it unless you are testing something very trivial.
>
> For example, for this case, you would want to make sure the
> command "git-submodule init" exits with non-zero status, but
> also you would want to make sure that it does not disturb the
> existing file "lib".
Would you prefer a patch on top of this version of the test-script or
on top of the later patch which uses .git/config to store submodule
url?
--
larsh
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] Add basic test-script for git-submodule
2007-05-30 6:48 ` Lars Hjemli
@ 2007-06-01 3:54 ` Junio C Hamano
2007-06-01 7:10 ` Lars Hjemli
0 siblings, 1 reply; 9+ messages in thread
From: Junio C Hamano @ 2007-06-01 3:54 UTC (permalink / raw)
To: Lars Hjemli; +Cc: Junio C Hamano, Johannes Schindelin, git
"Lars Hjemli" <hjemli@gmail.com> writes:
> Would you prefer a patch on top of this version of the test-script or
> on top of the later patch which uses .git/config to store submodule
> url?
As you said you will be redoing submodule + .git/config stuff in
your other message, I would expect a replacement (i.e. not on
top of this) patch for tests to check the existing submodule
features. If you want to finish the submodule + .git/config one
first and then test script on top to test both existing featues
and submodule + .git/config features, that is fine as well.
Your choice.
One important point is to treat the test-script take #1 as
"already rejected", and not basing further patches on it.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] Add basic test-script for git-submodule
2007-06-01 3:54 ` Junio C Hamano
@ 2007-06-01 7:10 ` Lars Hjemli
2007-06-01 7:56 ` Johannes Sixt
0 siblings, 1 reply; 9+ messages in thread
From: Lars Hjemli @ 2007-06-01 7:10 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Johannes Schindelin, git
This test tries to verify basic sanity of git-submodule, i.e. that it is
able to clone and update a submodule repository, that its status output is
sane, and that it barfs when the submodule path is occupied during init.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
---
On 6/1/07, Junio C Hamano <junkio@cox.net> wrote:
> As you said you will be redoing submodule + .git/config stuff in
> your other message, I would expect a replacement (i.e. not on
> top of this) patch for tests to check the existing submodule
> features. If you want to finish the submodule + .git/config one
> first and then test script on top to test both existing featues
> and submodule + .git/config features, that is fine as well.
> Your choice.
My continuous quest for self-discipline left me no choice but to attempt
the creation of a proper testscript for the existing features ;-)
t/t7400-submodule-basic.sh | 143 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 143 insertions(+), 0 deletions(-)
create mode 100755 t/t7400-submodule-basic.sh
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
new file mode 100755
index 0000000..a8beee2
--- /dev/null
+++ b/t/t7400-submodule-basic.sh
@@ -0,0 +1,143 @@
+#!/bin/sh
+#
+# Copyright (c) 2007 Lars Hjemli
+#
+
+test_description='Basic porcelain support for submodules
+
+This test tries to verify basic sanity of the init, update and status
+subcommands of git-submodule.
+'
+
+. ./test-lib.sh
+
+#
+# Test setup:
+# -create a repository in directory lib
+# -add a couple of files
+# -add directory lib to 'superproject', this creates a DIRLINK entry
+# -add a couple of regular files to enable testing of submodule filtering
+# -mv lib subrepo
+# -add an entry to .gitmodules for path 'lib'
+#
+test_expect_success 'Prepare submodule testing' '
+ mkdir lib &&
+ cd lib &&
+ git-init &&
+ echo a >a &&
+ git-add a &&
+ git-commit -m "submodule commit 1" &&
+ git-tag -a -m "rev-1" rev-1 &&
+ rev1=$(git-rev-parse HEAD) &&
+ if test -z "$rev1"
+ then
+ echo "[OOPS] submodule git-rev-parse returned nothing"
+ false
+ fi &&
+ cd .. &&
+ echo a >a &&
+ echo z >z &&
+ git-add a lib z &&
+ git-commit -m "super commit 1" &&
+ mv lib .subrepo &&
+ GIT_CONFIG=.gitmodules git-config module.lib.url ./.subrepo
+'
+
+test_expect_success 'status should only print one line' '
+ lines=$(git-submodule status | wc -l)
+ test "$lines" = "1"
+'
+
+test_expect_success 'status should initially be "missing"' '
+ git-submodule status | grep "^-$rev1"
+'
+
+test_expect_success 'init should fail when path is used by a file' '
+ echo "hello" >lib &&
+ if git-submodule init
+ then
+ echo "[OOPS] init should have failed"
+ false
+ elif test -f lib && test "$(cat lib)" != "hello"
+ then
+ echo "[OOPS] init failed but lib file was molested"
+ false
+ else
+ rm lib
+ fi
+'
+
+test_expect_success 'init should fail when path is used by a nonempty directory' '
+ mkdir lib &&
+ echo "hello" >lib/a &&
+ if git-submodule init
+ then
+ echo "[OOPS] init should have failed"
+ false
+ elif test "$(cat lib/a)" != "hello"
+ then
+ echo "[OOPS] init failed but lib/a was molested"
+ false
+ else
+ rm lib/a
+ fi
+'
+
+test_expect_success 'init should work when path is an empty dir' '
+ rm -rf lib &&
+ mkdir lib &&
+ git-submodule init &&
+ head=$(cd lib && git-rev-parse HEAD) &&
+ if test -z "$head"
+ then
+ echo "[OOPS] Failed to obtain submodule head"
+ false
+ elif test "$head" != "$rev1"
+ then
+ echo "[OOPS] Submodule head is $head but should have been $rev1"
+ false
+ fi
+'
+
+test_expect_success 'status should be "up-to-date" after init' '
+ git-submodule status | grep "^ $rev1"
+'
+
+test_expect_success 'status should be "modified" after submodule commit' '
+ cd lib &&
+ echo b >b &&
+ git-add b &&
+ git-commit -m "submodule commit 2" &&
+ rev2=$(git-rev-parse HEAD) &&
+ cd .. &&
+ if test -z "$rev2"
+ then
+ echo "[OOPS] submodule git-rev-parse returned nothing"
+ false
+ fi &&
+ git-submodule status | grep "^\+$rev2"
+'
+
+test_expect_success 'the --cached sha1 should be rev1' '
+ git-submodule --cached status | grep "^\+$rev1"
+'
+
+test_expect_success 'update should checkout rev1' '
+ git-submodule update &&
+ head=$(cd lib && git-rev-parse HEAD) &&
+ if test -z "$head"
+ then
+ echo "[OOPS] submodule git-rev-parse returned nothing"
+ false
+ elif test "$head" != "$rev1"
+ then
+ echo "[OOPS] init did not checkout correct head"
+ false
+ fi
+'
+
+test_expect_success 'status should be "up-to-date" after update' '
+ git-submodule status | grep "^ $rev1"
+'
+
+test_done
--
1.5.2.839.ga3b1-dirty
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] Add basic test-script for git-submodule
2007-06-01 7:10 ` Lars Hjemli
@ 2007-06-01 7:56 ` Johannes Sixt
2007-06-01 8:13 ` Lars Hjemli
0 siblings, 1 reply; 9+ messages in thread
From: Johannes Sixt @ 2007-06-01 7:56 UTC (permalink / raw)
To: git
Lars Hjemli wrote:
> +test_expect_success 'status should only print one line' '
> + lines=$(git-submodule status | wc -l)
&& is missing.
> + test "$lines" = "1"
Please don't put output of wc in quotes because some versions of wc emit
padding:
test $lines = 1
(without the quotes around 1 - like in other test scripts).
-- Hannes
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] Add basic test-script for git-submodule
2007-06-01 7:56 ` Johannes Sixt
@ 2007-06-01 8:13 ` Lars Hjemli
2007-06-01 19:50 ` Junio C Hamano
0 siblings, 1 reply; 9+ messages in thread
From: Lars Hjemli @ 2007-06-01 8:13 UTC (permalink / raw)
To: Johannes Sixt; +Cc: Junio C Hamano, Johannes Schindelin, git@vger.kernel.org
This test tries to verify basic sanity of git-submodule, i.e. that it is
able to clone and update a submodule repository, that its status output is
sane, and that it barfs when the submodule path is occupied during init.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
---
On Fri, 01 Jun 2007 09:56:12 +0200, Johannes Sixt <J.Sixt@eudaptics.com> wrote:
> Lars Hjemli wrote:
>> +test_expect_success 'status should only print one line' '
>> + lines=$(git-submodule status | wc -l)
>
> && is missing.
>
>> + test "$lines" = "1"
>
> Please don't put output of wc in quotes because some versions of wc emit
> padding:
>
> test $lines = 1
>
> (without the quotes around 1 - like in other test scripts).
>
Thanks, and sorry...
t/t7400-submodule-basic.sh | 143 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 143 insertions(+), 0 deletions(-)
create mode 100755 t/t7400-submodule-basic.sh
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
new file mode 100755
index 0000000..a985a6e
--- /dev/null
+++ b/t/t7400-submodule-basic.sh
@@ -0,0 +1,143 @@
+#!/bin/sh
+#
+# Copyright (c) 2007 Lars Hjemli
+#
+
+test_description='Basic porcelain support for submodules
+
+This test tries to verify basic sanity of the init, update and status
+subcommands of git-submodule.
+'
+
+. ./test-lib.sh
+
+#
+# Test setup:
+# -create a repository in directory lib
+# -add a couple of files
+# -add directory lib to 'superproject', this creates a DIRLINK entry
+# -add a couple of regular files to enable testing of submodule filtering
+# -mv lib subrepo
+# -add an entry to .gitmodules for path 'lib'
+#
+test_expect_success 'Prepare submodule testing' '
+ mkdir lib &&
+ cd lib &&
+ git-init &&
+ echo a >a &&
+ git-add a &&
+ git-commit -m "submodule commit 1" &&
+ git-tag -a -m "rev-1" rev-1 &&
+ rev1=$(git-rev-parse HEAD) &&
+ if test -z "$rev1"
+ then
+ echo "[OOPS] submodule git-rev-parse returned nothing"
+ false
+ fi &&
+ cd .. &&
+ echo a >a &&
+ echo z >z &&
+ git-add a lib z &&
+ git-commit -m "super commit 1" &&
+ mv lib .subrepo &&
+ GIT_CONFIG=.gitmodules git-config module.lib.url ./.subrepo
+'
+
+test_expect_success 'status should only print one line' '
+ lines=$(git-submodule status | wc -l) &&
+ test $lines = 1
+'
+
+test_expect_success 'status should initially be "missing"' '
+ git-submodule status | grep "^-$rev1"
+'
+
+test_expect_success 'init should fail when path is used by a file' '
+ echo "hello" >lib &&
+ if git-submodule init
+ then
+ echo "[OOPS] init should have failed"
+ false
+ elif test -f lib && test "$(cat lib)" != "hello"
+ then
+ echo "[OOPS] init failed but lib file was molested"
+ false
+ else
+ rm lib
+ fi
+'
+
+test_expect_success 'init should fail when path is used by a nonempty directory' '
+ mkdir lib &&
+ echo "hello" >lib/a &&
+ if git-submodule init
+ then
+ echo "[OOPS] init should have failed"
+ false
+ elif test "$(cat lib/a)" != "hello"
+ then
+ echo "[OOPS] init failed but lib/a was molested"
+ false
+ else
+ rm lib/a
+ fi
+'
+
+test_expect_success 'init should work when path is an empty dir' '
+ rm -rf lib &&
+ mkdir lib &&
+ git-submodule init &&
+ head=$(cd lib && git-rev-parse HEAD) &&
+ if test -z "$head"
+ then
+ echo "[OOPS] Failed to obtain submodule head"
+ false
+ elif test "$head" != "$rev1"
+ then
+ echo "[OOPS] Submodule head is $head but should have been $rev1"
+ false
+ fi
+'
+
+test_expect_success 'status should be "up-to-date" after init' '
+ git-submodule status | grep "^ $rev1"
+'
+
+test_expect_success 'status should be "modified" after submodule commit' '
+ cd lib &&
+ echo b >b &&
+ git-add b &&
+ git-commit -m "submodule commit 2" &&
+ rev2=$(git-rev-parse HEAD) &&
+ cd .. &&
+ if test -z "$rev2"
+ then
+ echo "[OOPS] submodule git-rev-parse returned nothing"
+ false
+ fi &&
+ git-submodule status | grep "^\+$rev2"
+'
+
+test_expect_success 'the --cached sha1 should be rev1' '
+ git-submodule --cached status | grep "^\+$rev1"
+'
+
+test_expect_success 'update should checkout rev1' '
+ git-submodule update &&
+ head=$(cd lib && git-rev-parse HEAD) &&
+ if test -z "$head"
+ then
+ echo "[OOPS] submodule git-rev-parse returned nothing"
+ false
+ elif test "$head" != "$rev1"
+ then
+ echo "[OOPS] init did not checkout correct head"
+ false
+ fi
+'
+
+test_expect_success 'status should be "up-to-date" after update' '
+ git-submodule status | grep "^ $rev1"
+'
+
+test_done
--
1.5.2.839.ga3b1-dirty
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] Add basic test-script for git-submodule
2007-06-01 8:13 ` Lars Hjemli
@ 2007-06-01 19:50 ` Junio C Hamano
2007-06-02 1:27 ` Lars Hjemli
0 siblings, 1 reply; 9+ messages in thread
From: Junio C Hamano @ 2007-06-01 19:50 UTC (permalink / raw)
To: Lars Hjemli
Cc: Johannes Sixt, Junio C Hamano, Johannes Schindelin,
git@vger.kernel.org
"Lars Hjemli" <hjemli@gmail.com> writes:
> This test tries to verify basic sanity of git-submodule, i.e. that it is
> able to clone and update a submodule repository, that its status output is
> sane, and that it barfs when the submodule path is occupied during init.
>
> Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Micronit...
> +test_expect_success 'the --cached sha1 should be rev1' '
> + git-submodule --cached status | grep "^\+$rev1"
> +'
What's the purpose of that solitary backslash?
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH] Add basic test-script for git-submodule
2007-06-01 19:50 ` Junio C Hamano
@ 2007-06-02 1:27 ` Lars Hjemli
0 siblings, 0 replies; 9+ messages in thread
From: Lars Hjemli @ 2007-06-02 1:27 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Johannes Sixt, Johannes Schindelin, git
This test tries to verify basic sanity of git-submodule, i.e. that it is
able to clone and update a submodule repository, that its status output is
sane, and that it barfs when the submodule path is occupied during init.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
---
On 6/1/07, Junio C Hamano <junkio@cox.net> wrote:
> "Lars Hjemli" <hjemli@gmail.com> writes:
> > +test_expect_success 'the --cached sha1 should be rev1' '
> > + git-submodule --cached status | grep "^\+$rev1"
> > +'
>
> What's the purpose of that solitary backslash?
That's just a sign of me being sloppy, expecting the behaviour of 'grep -E' without
bothering to study the man-page. Sorry.
t/t7400-submodule-basic.sh | 143 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 143 insertions(+), 0 deletions(-)
create mode 100755 t/t7400-submodule-basic.sh
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
new file mode 100755
index 0000000..6274729
--- /dev/null
+++ b/t/t7400-submodule-basic.sh
@@ -0,0 +1,143 @@
+#!/bin/sh
+#
+# Copyright (c) 2007 Lars Hjemli
+#
+
+test_description='Basic porcelain support for submodules
+
+This test tries to verify basic sanity of the init, update and status
+subcommands of git-submodule.
+'
+
+. ./test-lib.sh
+
+#
+# Test setup:
+# -create a repository in directory lib
+# -add a couple of files
+# -add directory lib to 'superproject', this creates a DIRLINK entry
+# -add a couple of regular files to enable testing of submodule filtering
+# -mv lib subrepo
+# -add an entry to .gitmodules for path 'lib'
+#
+test_expect_success 'Prepare submodule testing' '
+ mkdir lib &&
+ cd lib &&
+ git-init &&
+ echo a >a &&
+ git-add a &&
+ git-commit -m "submodule commit 1" &&
+ git-tag -a -m "rev-1" rev-1 &&
+ rev1=$(git-rev-parse HEAD) &&
+ if test -z "$rev1"
+ then
+ echo "[OOPS] submodule git-rev-parse returned nothing"
+ false
+ fi &&
+ cd .. &&
+ echo a >a &&
+ echo z >z &&
+ git-add a lib z &&
+ git-commit -m "super commit 1" &&
+ mv lib .subrepo &&
+ GIT_CONFIG=.gitmodules git-config module.lib.url ./.subrepo
+'
+
+test_expect_success 'status should only print one line' '
+ lines=$(git-submodule status | wc -l) &&
+ test $lines = 1
+'
+
+test_expect_success 'status should initially be "missing"' '
+ git-submodule status | grep "^-$rev1"
+'
+
+test_expect_success 'init should fail when path is used by a file' '
+ echo "hello" >lib &&
+ if git-submodule init
+ then
+ echo "[OOPS] init should have failed"
+ false
+ elif test -f lib && test "$(cat lib)" != "hello"
+ then
+ echo "[OOPS] init failed but lib file was molested"
+ false
+ else
+ rm lib
+ fi
+'
+
+test_expect_success 'init should fail when path is used by a nonempty directory' '
+ mkdir lib &&
+ echo "hello" >lib/a &&
+ if git-submodule init
+ then
+ echo "[OOPS] init should have failed"
+ false
+ elif test "$(cat lib/a)" != "hello"
+ then
+ echo "[OOPS] init failed but lib/a was molested"
+ false
+ else
+ rm lib/a
+ fi
+'
+
+test_expect_success 'init should work when path is an empty dir' '
+ rm -rf lib &&
+ mkdir lib &&
+ git-submodule init &&
+ head=$(cd lib && git-rev-parse HEAD) &&
+ if test -z "$head"
+ then
+ echo "[OOPS] Failed to obtain submodule head"
+ false
+ elif test "$head" != "$rev1"
+ then
+ echo "[OOPS] Submodule head is $head but should have been $rev1"
+ false
+ fi
+'
+
+test_expect_success 'status should be "up-to-date" after init' '
+ git-submodule status | grep "^ $rev1"
+'
+
+test_expect_success 'status should be "modified" after submodule commit' '
+ cd lib &&
+ echo b >b &&
+ git-add b &&
+ git-commit -m "submodule commit 2" &&
+ rev2=$(git-rev-parse HEAD) &&
+ cd .. &&
+ if test -z "$rev2"
+ then
+ echo "[OOPS] submodule git-rev-parse returned nothing"
+ false
+ fi &&
+ git-submodule status | grep "^+$rev2"
+'
+
+test_expect_success 'the --cached sha1 should be rev1' '
+ git-submodule --cached status | grep "^+$rev1"
+'
+
+test_expect_success 'update should checkout rev1' '
+ git-submodule update &&
+ head=$(cd lib && git-rev-parse HEAD) &&
+ if test -z "$head"
+ then
+ echo "[OOPS] submodule git-rev-parse returned nothing"
+ false
+ elif test "$head" != "$rev1"
+ then
+ echo "[OOPS] init did not checkout correct head"
+ false
+ fi
+'
+
+test_expect_success 'status should be "up-to-date" after update' '
+ git-submodule status | grep "^ $rev1"
+'
+
+test_done
--
1.5.2.839.ga3b1-dirty
^ permalink raw reply related [flat|nested] 9+ messages in thread
end of thread, other threads:[~2007-06-02 1:25 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-27 20:34 [PATCH] Add basic test-script for git-submodule Lars Hjemli
2007-05-29 7:10 ` Junio C Hamano
2007-05-30 6:48 ` Lars Hjemli
2007-06-01 3:54 ` Junio C Hamano
2007-06-01 7:10 ` Lars Hjemli
2007-06-01 7:56 ` Johannes Sixt
2007-06-01 8:13 ` Lars Hjemli
2007-06-01 19:50 ` Junio C Hamano
2007-06-02 1:27 ` Lars Hjemli
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).