git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH RFC 23/24] cat-file: tests for new atoms added

From
Olga Telezhnaya <olyatelezhnaya@gmail.com>
Date
Jan 26, 2018, 19:43 UTC
Message-ID
<0102016133ff3b5d-2a898107-6989-411d-b7c5-f349e897873e-000000@eu-west-1.amazonses.com>
In-Reply-To
<0102016133ff3a86-44d354ec-13c6-4c38-bc75-1ba4422db5a7-000000@eu-west-1.amazonses.com>

Add some tests for new formatting atoms from ref-filter. Some of new atoms are supported automatically, some of them are expanded into empty string (because they are useless for some types of objects), some of them could be supported later in other patches.

Signed-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>
Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored by: Jeff King <peff@peff.net>
---
 t/t1006-cat-file.sh | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh
index b19f332694620..e72fcaf0e02c5 100755
--- a/t/t1006-cat-file.sh
+++ b/t/t1006-cat-file.sh
@@ -20,6 +20,19 @@ maybe_remove_timestamp () {
     fi
 }
 
+test_atom () {
+    name=$1
+    sha1=$2
+    atoms=$3
+    expected=$4
+
+    test_expect_success "$name" '
+	echo "$expected" >expect &&
+	echo $sha1 | git cat-file --batch-check="$atoms" >actual &&
+	test_cmp expect actual
+    '
+}
+
 run_tests () {
     type=$1
     sha1=$2
@@ -119,6 +132,13 @@ $content"
 	maybe_remove_timestamp "$(cat actual.full)" $no_ts >actual &&
 	test_cmp expect actual
     '
+
+    for atom in refname parent body trailers upstream push symref flag
+    do
+	test_atom "Check %($atom) gives empty output" "$sha1" "%($atom)" ""
+    done
+
+    test_atom "Check %(HEAD) gives only one space as output" "$sha1" '%(HEAD)' ' '
 }
 
 hello_content="Hello World"
@@ -140,6 +160,12 @@ test_expect_success '--batch-check without %(rest) considers whole line' '
 	test_cmp expect actual
 '
 
+shortname=`echo $hello_sha1 | sed 's/^.\{0\}\(.\{7\}\).*/\1/'`
+test_atom 'Check format option %(objectname:short) works' "$hello_sha1" '%(objectname:short)' "$shortname"
+
+test_atom 'Check format option %(align) is not broken' \
+    "$hello_sha1" "%(align:8)%(objecttype)%(end)%(objectname)" "blob    $hello_sha1"
+
 tree_sha1=$(git write-tree)
 tree_size=33
 tree_pretty_content="100644 blob $hello_sha1	hello"
@@ -157,6 +183,17 @@ $commit_message"
 
 run_tests 'commit' $commit_sha1 $commit_size "$commit_content" "$commit_content" 1
 
+test_atom "Check format option %(if) is not broken" "$commit_sha1" \
+    "%(if)%(author)%(then)%(objectname)%(end)" "$commit_sha1"
+test_atom "Check %(tree) works for commit" "$commit_sha1" "%(tree)" "$tree_sha1"
+test_atom "Check %(numparent) works for commit" "$commit_sha1" "%(numparent)" "0"
+test_atom "Check %(authorname) works for commit" "$commit_sha1" "%(authorname)" "$GIT_AUTHOR_NAME"
+test_atom "Check %(authoremail) works for commit" "$commit_sha1" "%(authoremail)" "<$GIT_AUTHOR_EMAIL>"
+test_atom "Check %(committername) works for commit" "$commit_sha1" "%(committername)" "$GIT_COMMITTER_NAME"
+test_atom "Check %(committeremail) works for commit" "$commit_sha1" "%(committeremail)" "<$GIT_COMMITTER_EMAIL>"
+test_atom "Check %(subject) works for commit" "$commit_sha1" "%(subject)" "$commit_message"
+test_atom "Check %(contents) works for commit" "$commit_sha1" "%(contents)" "$commit_message"
+
 tag_header_without_timestamp="object $hello_sha1
 type blob
 tag hellotag
@@ -171,6 +208,17 @@ tag_size=$(strlen "$tag_content")
 
 run_tests 'tag' $tag_sha1 $tag_size "$tag_content" "$tag_content" 1
 
+test_atom "Check %(object) works for tag" "$tag_sha1" "%(object)" "$hello_sha1"
+test_atom "Check %(type) works for tag" "$tag_sha1" "%(type)" "blob"
+test_atom "Check %(tag) works for tag" "$tag_sha1" "%(tag)" "hellotag"
+test_atom "Check %(taggername) works for tag" "$tag_sha1" "%(taggername)" "$GIT_COMMITTER_NAME"
+test_atom "Check %(taggeremail) works for tag" "$tag_sha1" "%(taggeremail)" "<$GIT_COMMITTER_EMAIL>"
+test_atom "Check %(subject) works for tag" "$tag_sha1" "%(subject)" "$tag_description"
+test_atom "Check %(contents) works for tag" "$tag_sha1" "%(contents)" "$tag_description"
+
+test_atom "Check %(color) gives no additional output" "$sha1" \
+    "%(objectname) %(color:green) %(objecttype)" "$sha1  $type"
+
 test_expect_success \
     "Reach a blob from a tag pointing to it" \
     "test '$hello_content' = \"\$(git cat-file blob $tag_sha1)\""

--
https://github.com/git/git/pull/452
Previous: Olga TelezhnayaNext: Olga Telezhnaya
Message 2 of 33 in “ref-filter: get rid of goto”
  1. 01/24 ref-filter: get rid of gotoOlga Telezhnaya, Jan 26, 2018
  2. 23/24 cat-file: tests for new atoms addedOlga Telezhnaya, Jan 26, 2018
  3. 18/24 ref-filter: make valid_atom general againOlga Telezhnaya, Jan 26, 2018
  4. 10/24 ref-filter: make populate_value globalOlga Telezhnaya, Jan 26, 2018
  5. 22/24 for-each-ref: tests for new atoms addedOlga Telezhnaya, Jan 26, 2018
  6. 09/24 cat-file: start use ref_array_item structOlga Telezhnaya, Jan 26, 2018
  7. 19/24 ref-filter: make populate_value internal againOlga Telezhnaya, Jan 26, 2018
  8. 03/24 cat-file: split expand_atom into 2 functionsOlga Telezhnaya, Jan 26, 2018
  9. Junio C HamanoJan 26, 2018
  10. Оля ТележнаяJan 29, 2018
  11. 04/24 cat-file: reuse struct ref_formatOlga Telezhnaya, Jan 26, 2018
  12. Junio C HamanoJan 26, 2018
  13. 24/24 cat-file: update of docsOlga Telezhnaya, Jan 26, 2018
  14. 20/24 ref-filter: unifying formatting of cat-file optsOlga Telezhnaya, Jan 26, 2018
  15. 13/24 ref-filter: add is_cat flagOlga Telezhnaya, Jan 26, 2018
  16. 17/24 cat-file: reuse printing logic from ref-filterOlga Telezhnaya, Jan 26, 2018
  17. 16/24 ref-filter: make cat_file_info independentOlga Telezhnaya, Jan 26, 2018
  18. 14/24 ref_filter: add is_rest_atom_used functionOlga Telezhnaya, Jan 26, 2018
  19. 12/24 ref-filter: get rid of expand_atom_into_fieldsOlga Telezhnaya, Jan 26, 2018
  20. 11/24 cat-file: start reusing populate_valueOlga Telezhnaya, Jan 26, 2018
  21. 02/24 ref-filter: add return value to some functionsOlga Telezhnaya, Jan 26, 2018
  22. Junio C HamanoJan 26, 2018
  23. Оля ТележнаяJan 29, 2018
  24. 08/24 ref-filter: reuse parse_ref_filter_atomOlga Telezhnaya, Jan 26, 2018
  25. 06/24 cat-file: move struct expand_data into ref-filterOlga Telezhnaya, Jan 26, 2018
  26. 21/24 ref-filter: work with objectsize:diskOlga Telezhnaya, Jan 26, 2018
  27. 05/24 ref-filter: make valid_atom as function parameterOlga Telezhnaya, Jan 26, 2018
  28. 07/24 cat-file: start migrating to ref-filterOlga Telezhnaya, Jan 26, 2018
  29. 15/24 cat-file: move skip_object_info into ref-filterOlga Telezhnaya, Jan 26, 2018
  30. Junio C HamanoJan 26, 2018
  31. Оля ТележнаяJan 29, 2018
  32. Junio C HamanoJan 30, 2018
  33. Оля ТележнаяJan 31, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.