Something went wrong. Try again.
my code lab
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241#!/usr/bin/env atf-sh
init_repo() { DIFFWISE="$(atf_get_srcdir)/diffwise" export JJ_USER="Test User" export JJ_EMAIL="test@example.com" atf_check -o ignore -e ignore jj git init repo cd repo}
commit_file() { local name="${1}"; shift
echo "content of ${name}" > "${name}" atf_check -o ignore -e ignore jj commit "${@}"}
atf_test_case single_commitsingle_commit_head() { atf_set "descr" "One commit yields one patch file in format-patch layout"}single_commit_body() { init_repo commit_file f.txt -m "Add foo file"
atf_check -o inline:"0001-Add-foo-file.patch\n" \ "${DIFFWISE}" -r '@-' atf_check \ -o match:"^From [0-9a-f]{40} Mon Sep 17 00:00:00 2001$" \ -o match:"^From: Test User <test@example\.com>$" \ -o match:"^Date: [A-Z][a-z]{2}, [0-9]{2} [A-Z][a-z]{2} [0-9]{4} [0-9:]{8} [-+][0-9]{4}$" \ -o match:"^Committer: Test User <test@example\.com>$" \ -o match:"^Committer-Date: [A-Z][a-z]{2}, [0-9]{2} [A-Z][a-z]{2} [0-9]{4} [0-9:]{8} [-+][0-9]{4}$" \ -o match:"^Subject: \[PATCH\] Add foo file$" \ -o match:"^---$" \ -o match:"^diff --git a/f\.txt b/f\.txt$" \ cat 0001-Add-foo-file.patch}
atf_test_case series_numberingseries_numbering_head() { atf_set "descr" "Multiple commits are numbered oldest first as [PATCH n/m]"}series_numbering_body() { init_repo commit_file first.txt -m "Add first file" commit_file second.txt -m "Add second file"
atf_check \ -o inline:"0001-Add-first-file.patch\n0002-Add-second-file.patch\n" \ "${DIFFWISE}" -r '@-- | @-' atf_check -o match:"^Subject: \[PATCH 1/2\] Add first file$" \ cat 0001-Add-first-file.patch atf_check -o match:"^Subject: \[PATCH 2/2\] Add second file$" \ cat 0002-Add-second-file.patch}
atf_test_case description_bodydescription_body_head() { atf_set "descr" "The commit description body appears between subject and diff"}description_body_body() { init_repo commit_file f.txt -m "Add foo file" -m "Greetings matter to reviewers."
atf_check -o ignore "${DIFFWISE}" -r '@-' atf_check \ -o match:"^Greetings matter to reviewers\.$" \ cat 0001-Add-foo-file.patch}
atf_test_case no_descriptionno_description_head() { atf_set "descr" "A commit without a description gets an empty subject"}no_description_body() { init_repo echo "content" > f.txt atf_check -o ignore -e ignore jj new
atf_check -o inline:"0001-patch.patch\n" "${DIFFWISE}" -r '@-' atf_check -o match:"^Subject: \[PATCH\]$" cat 0001-patch.patch}
atf_test_case empty_revsetempty_revset_head() { atf_set "descr" "A revset selecting no commits produces no files"}empty_revset_body() { init_repo
atf_check -o empty "${DIFFWISE}" -r 'none()' atf_check -o inline:"none\n" sh -c \ 'ls ./*.patch 2>/dev/null || echo none'}
atf_test_case invalid_revsetinvalid_revset_head() { atf_set "descr" "An invalid revset fails with a diagnostic"}invalid_revset_body() { init_repo
atf_check -s exit:1 -e match:"cannot list commits for revset" \ "${DIFFWISE}" -r 'bogus('}
atf_test_case committer_differscommitter_differs_head() { atf_set "descr" "Author and committer are both shown when they differ"}committer_differs_body() { init_repo commit_file f.txt -m "Add foo file" atf_check -o ignore -e ignore env \ JJ_USER="Other Committer" JJ_EMAIL="other@example.com" \ jj describe -r '@-' -m "Add foo file" -m "Applied for a friend."
atf_check -o ignore "${DIFFWISE}" -r '@-' atf_check \ -o match:"^From: Test User <test@example\.com>$" \ -o match:"^Committer: Other Committer <other@example\.com>$" \ cat 0001-Add-foo-file.patch}
atf_test_case default_revsetdefault_revset_head() { atf_set "descr" "Without -r the working copy and mutable ancestors are exported"}default_revset_body() { init_repo commit_file f.txt -m "Add foo file"
atf_check -o inline:"0001-Add-foo-file.patch\n" \ "${DIFFWISE}" atf_check -o match:"^Subject: \[PATCH\] Add foo file$" \ cat 0001-Add-foo-file.patch}
atf_test_case skip_empty_undescribedskip_empty_undescribed_head() { atf_set "descr" "A commit with no changes and no description is skipped"}skip_empty_undescribed_body() { init_repo commit_file f.txt -m "Add foo file"
atf_check -o empty "${DIFFWISE}" -r '@' atf_check -o inline:"none\n" sh -c \ 'ls ./*.patch 2>/dev/null || echo none'}
atf_test_case empty_with_descriptionempty_with_description_head() { atf_set "descr" "A described commit with no changes is exported"}empty_with_description_body() { init_repo commit_file f.txt -m "Add foo file" atf_check -o ignore -e ignore jj describe -m "Empty milestone"
atf_check -o inline:"0001-Empty-milestone.patch\n" \ "${DIFFWISE}" -r '@' atf_check -o match:"^Subject: \[PATCH\] Empty milestone$" \ cat 0001-Empty-milestone.patch}
atf_test_case unexpected_argumentunexpected_argument_head() { atf_set "descr" "A positional argument is a usage error"}unexpected_argument_body() { init_repo
atf_check -s exit:1 \ -e match:"unexpected argument" \ -e match:"^usage: diffwise" \ "${DIFFWISE}" '@-'}
atf_test_case unknown_optionunknown_option_head() { atf_set "descr" "An unknown option is a usage error"}unknown_option_body() { init_repo
atf_check -s exit:1 \ -e match:"unknown option -x" \ -e match:"^usage: diffwise" \ "${DIFFWISE}" -x}
atf_test_case output_directoryoutput_directory_head() { atf_set "descr" "-o writes patches into the directory, creating it"}output_directory_body() { init_repo commit_file f.txt -m "Add foo file"
atf_check -o inline:"patches/0001-Add-foo-file.patch\n" \ "${DIFFWISE}" -o patches -r '@-' atf_check -o match:"^Subject: \[PATCH\] Add foo file$" \ cat patches/0001-Add-foo-file.patch}
atf_test_case dry_rundry_run_head() { atf_set "descr" "-n prints file names without writing anything"}dry_run_body() { init_repo commit_file f.txt -m "Add foo file"
atf_check -o inline:"0001-Add-foo-file.patch\n" \ "${DIFFWISE}" -n -r '@-' atf_check -o inline:"none\n" sh -c \ 'ls ./*.patch 2>/dev/null || echo none' atf_check -o inline:"patches/0001-Add-foo-file.patch\n" \ "${DIFFWISE}" -n -o patches -r '@-' atf_check -s exit:1 test -d patches}
atf_init_test_cases() { atf_add_test_case single_commit atf_add_test_case committer_differs atf_add_test_case default_revset atf_add_test_case skip_empty_undescribed atf_add_test_case empty_with_description atf_add_test_case series_numbering atf_add_test_case description_body atf_add_test_case no_description atf_add_test_case empty_revset atf_add_test_case invalid_revset atf_add_test_case unexpected_argument atf_add_test_case unknown_option atf_add_test_case output_directory atf_add_test_case dry_run}