#!/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_commit single_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 $" \ -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 $" \ -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_numbering series_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_body description_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_description no_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_revset empty_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_revset invalid_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_differs committer_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 $" \ -o match:"^Committer: Other Committer $" \ cat 0001-Add-foo-file.patch } atf_test_case default_revset default_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_undescribed skip_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_description empty_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_argument unexpected_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_option unknown_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_directory output_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_run dry_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 }