Heba Waly | b3b18d1 | 2020-03-02 20:01:59 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='Test advise_if_enabled functionality' |
| 4 | |
Junio C Hamano | cbdc83f | 2024-05-07 17:40:51 -0700 | [diff] [blame] | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=trunk |
| 6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 7 | |
Ævar Arnfjörð Bjarmason | 956d2e4 | 2021-09-23 11:20:46 +0200 | [diff] [blame] | 8 | TEST_PASSES_SANITIZE_LEAK=true |
Heba Waly | b3b18d1 | 2020-03-02 20:01:59 +0000 | [diff] [blame] | 9 | . ./test-lib.sh |
| 10 | |
| 11 | test_expect_success 'advice should be printed when config variable is unset' ' |
| 12 | cat >expect <<-\EOF && |
| 13 | hint: This is a piece of advice |
| 14 | hint: Disable this message with "git config advice.nestedTag false" |
| 15 | EOF |
| 16 | test-tool advise "This is a piece of advice" 2>actual && |
Ævar Arnfjörð Bjarmason | 1108cea | 2021-02-11 02:53:53 +0100 | [diff] [blame] | 17 | test_cmp expect actual |
Heba Waly | b3b18d1 | 2020-03-02 20:01:59 +0000 | [diff] [blame] | 18 | ' |
| 19 | |
| 20 | test_expect_success 'advice should be printed when config variable is set to true' ' |
| 21 | cat >expect <<-\EOF && |
| 22 | hint: This is a piece of advice |
Heba Waly | b3b18d1 | 2020-03-02 20:01:59 +0000 | [diff] [blame] | 23 | EOF |
| 24 | test_config advice.nestedTag true && |
| 25 | test-tool advise "This is a piece of advice" 2>actual && |
Ævar Arnfjörð Bjarmason | 1108cea | 2021-02-11 02:53:53 +0100 | [diff] [blame] | 26 | test_cmp expect actual |
Heba Waly | b3b18d1 | 2020-03-02 20:01:59 +0000 | [diff] [blame] | 27 | ' |
| 28 | |
| 29 | test_expect_success 'advice should not be printed when config variable is set to false' ' |
| 30 | test_config advice.nestedTag false && |
| 31 | test-tool advise "This is a piece of advice" 2>actual && |
| 32 | test_must_be_empty actual |
| 33 | ' |
| 34 | |
James Liu | b79deeb | 2024-05-03 17:17:06 +1000 | [diff] [blame] | 35 | test_expect_success 'advice should not be printed when --no-advice is used' ' |
| 36 | q_to_tab >expect <<-\EOF && |
Junio C Hamano | cbdc83f | 2024-05-07 17:40:51 -0700 | [diff] [blame] | 37 | On branch trunk |
James Liu | b79deeb | 2024-05-03 17:17:06 +1000 | [diff] [blame] | 38 | |
Junio C Hamano | cbdc83f | 2024-05-07 17:40:51 -0700 | [diff] [blame] | 39 | No commits yet |
James Liu | b79deeb | 2024-05-03 17:17:06 +1000 | [diff] [blame] | 40 | |
Junio C Hamano | cbdc83f | 2024-05-07 17:40:51 -0700 | [diff] [blame] | 41 | Untracked files: |
| 42 | QREADME |
James Liu | b79deeb | 2024-05-03 17:17:06 +1000 | [diff] [blame] | 43 | |
Junio C Hamano | cbdc83f | 2024-05-07 17:40:51 -0700 | [diff] [blame] | 44 | nothing added to commit but untracked files present |
| 45 | EOF |
James Liu | b79deeb | 2024-05-03 17:17:06 +1000 | [diff] [blame] | 46 | |
| 47 | test_when_finished "rm -fr advice-test" && |
| 48 | git init advice-test && |
| 49 | ( |
| 50 | cd advice-test && |
| 51 | >README && |
| 52 | git --no-advice status |
| 53 | ) >actual && |
| 54 | test_cmp expect actual |
| 55 | ' |
| 56 | |
| 57 | test_expect_success 'advice should not be printed when GIT_ADVICE is set to false' ' |
| 58 | q_to_tab >expect <<-\EOF && |
Junio C Hamano | cbdc83f | 2024-05-07 17:40:51 -0700 | [diff] [blame] | 59 | On branch trunk |
James Liu | b79deeb | 2024-05-03 17:17:06 +1000 | [diff] [blame] | 60 | |
Junio C Hamano | cbdc83f | 2024-05-07 17:40:51 -0700 | [diff] [blame] | 61 | No commits yet |
James Liu | b79deeb | 2024-05-03 17:17:06 +1000 | [diff] [blame] | 62 | |
Junio C Hamano | cbdc83f | 2024-05-07 17:40:51 -0700 | [diff] [blame] | 63 | Untracked files: |
| 64 | QREADME |
James Liu | b79deeb | 2024-05-03 17:17:06 +1000 | [diff] [blame] | 65 | |
Junio C Hamano | cbdc83f | 2024-05-07 17:40:51 -0700 | [diff] [blame] | 66 | nothing added to commit but untracked files present |
| 67 | EOF |
James Liu | b79deeb | 2024-05-03 17:17:06 +1000 | [diff] [blame] | 68 | |
| 69 | test_when_finished "rm -fr advice-test" && |
| 70 | git init advice-test && |
| 71 | ( |
| 72 | cd advice-test && |
| 73 | >README && |
| 74 | GIT_ADVICE=false git status |
| 75 | ) >actual && |
| 76 | test_cmp expect actual |
| 77 | ' |
| 78 | |
| 79 | test_expect_success 'advice should be printed when GIT_ADVICE is set to true' ' |
| 80 | q_to_tab >expect <<-\EOF && |
Junio C Hamano | cbdc83f | 2024-05-07 17:40:51 -0700 | [diff] [blame] | 81 | On branch trunk |
James Liu | b79deeb | 2024-05-03 17:17:06 +1000 | [diff] [blame] | 82 | |
Junio C Hamano | cbdc83f | 2024-05-07 17:40:51 -0700 | [diff] [blame] | 83 | No commits yet |
James Liu | b79deeb | 2024-05-03 17:17:06 +1000 | [diff] [blame] | 84 | |
Junio C Hamano | cbdc83f | 2024-05-07 17:40:51 -0700 | [diff] [blame] | 85 | Untracked files: |
| 86 | (use "git add <file>..." to include in what will be committed) |
| 87 | QREADME |
James Liu | b79deeb | 2024-05-03 17:17:06 +1000 | [diff] [blame] | 88 | |
Junio C Hamano | cbdc83f | 2024-05-07 17:40:51 -0700 | [diff] [blame] | 89 | nothing added to commit but untracked files present (use "git add" to track) |
| 90 | EOF |
James Liu | b79deeb | 2024-05-03 17:17:06 +1000 | [diff] [blame] | 91 | |
| 92 | test_when_finished "rm -fr advice-test" && |
| 93 | git init advice-test && |
| 94 | ( |
| 95 | cd advice-test && |
| 96 | >README && |
| 97 | GIT_ADVICE=true git status |
| 98 | ) >actual && |
| 99 | cat actual > /tmp/actual && |
| 100 | test_cmp expect actual |
| 101 | ' |
| 102 | |
Heba Waly | b3b18d1 | 2020-03-02 20:01:59 +0000 | [diff] [blame] | 103 | test_done |