Thread (1 message) 1 message, 1 author, 2016-06-15

Re: [PATCH 11/13] contrib/subtree: Make each test self-contained

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:56:03

"David A. Greene" [off-list ref] writes:
+test_create_commit() (
+	repo=$1
+	commit=$2
+	cd "$repo"
+	mkdir -p "$(dirname "$commit")"
+	echo "$commit" > "$commit"
Style.
+	git add "$commit"
+	git commit -m "$commit"
+)
Very nice, but don't we want to check for possible errors in any of
the above commands?
 last_commit_message()
 {
 	git log --pretty=format:%s -1
 }
 
+#
+# Tests for 'git subtree add'
+#
 
-test_expect_success 'fetch subproj history' '
-		git fetch ./subproj sub1 &&
-		git branch sub1 FETCH_HEAD
-'
 
 test_expect_success 'no pull from non-existant subtree' '
-		test_must_fail git subtree pull --prefix=subdir ./subproj sub1
+	test_create_repo "$test_count" &&
+	test_create_repo "$test_count/subproj" &&
+	test_create_commit "$test_count" main1 &&
+	test_create_commit "$test_count/subproj" sub1 &&
+	(
+		cd "$test_count" &&
+		git fetch ./subproj master &&
+		test_must_fail git subtree pull --prefix=subdir ./subproj master
+	)
 '
The goal of making each tests indenendent is a very good one, but
we'd really prefer not to see $test_count which is an implementation
detail of the test framework to be used like this.  It will make it
unnecessarily harder to improve the test framework (e.g. it may want
to stop using the $test_count variable).

This is not limited to this variable, but all other $test_anything
variable.  Earlier I wanted to update the definition of test_tick
which happens to be decimal number of seconds since epoch, but some
tests were comparing it with the raw values read from cat-file output
for a commit object, and it was really painful.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help