• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

sschmid / pw-terminal-password-manager / 20761146205

06 Jan 2026 08:22PM UTC coverage: 87.234% (-0.2%) from 87.427%
20761146205

push

github

sschmid
Fit usage within 80 chars

451 of 517 relevant lines covered (87.23%)

422.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.2
/test/test-helper.bash
1
# shellcheck disable=SC2034
2
_common_setup() {
3
        load 'test_helper/bats-support/load.bash'
976✔
4
        load 'test_helper/bats-assert/load.bash'
976✔
5
        load 'test_helper/bats-file/load.bash'
964✔
6

7
        export XDG_CONFIG_HOME="${BATS_TEST_TMPDIR}/.config"
1,446✔
8
        PW_CONFIG="${XDG_CONFIG_HOME}/pw/pw.conf"
964✔
9
        mkdir -p "${XDG_CONFIG_HOME}/pw"
964✔
10

11
        PROJECT_ROOT="$(cd "${BATS_TEST_DIRNAME}/.." &>/dev/null && pwd)"
2,892✔
12
        PATH="${PROJECT_ROOT}/src:${PATH}"
960✔
13

14
        KEYCHAIN_TEST_PASSWORD=" test password "
964✔
15
        NAME_A=" a test name "
964✔
16
        NAME_B=" b test name "
964✔
17
        ACCOUNT_A=" a test account "
964✔
18
        ACCOUNT_B=" b test account "
964✔
19
        URL_A=" a test url "
964✔
20
        URL_B=" b test url "
964✔
21
        SINGLE_LINE_NOTES=" a single line note "
964✔
22
        MULTI_LINE_NOTES=" a test note
23
with multiple lines
24
and spaces "
964✔
25
        PW_1=" 1 test pw "
964✔
26
        PW_2=" 2 test pw "
964✔
27
        PW_3=" 3 test pw "
964✔
28
}
29

30
_set_config_with_copy_paste() {
31
        cat > "${PW_CONFIG}" << 'EOF'
624✔
32
[general]
33
copy = cat > "${BATS_TEST_TMPDIR}/test_clipboard"
34
paste = cat "${BATS_TEST_TMPDIR}/test_clipboard"
35
EOF
36
}
37

38
_copy() {
39
        cat > "${BATS_TEST_TMPDIR}/test_clipboard"
12✔
40
}
41

42
_paste() {
43
        cat "${BATS_TEST_TMPDIR}/test_clipboard"
26✔
44
}
45

46
_config_append_with_plugin() {
47
        cat >> "${PW_CONFIG}" << EOF
608✔
48
[plugins]
49
# unknown key
50
pluginX = invalid
51
plugin = $1
52
EOF
53
}
54

55
_config_append_with_test_plugins() {
56
        cat >> "${1:-"${PW_CONFIG}"}" << EOF
288✔
57
[plugins]
58
# unknown key
59
pluginX = invalid
60
plugin = ${BATS_TEST_DIRNAME}/fixtures/plugins/collision
61
plugin = ${BATS_TEST_DIRNAME}/fixtures/plugins/test
62
EOF
63
}
64

65
_config_append_keychains() {
66
        echo "[keychains]" >> "${PW_CONFIG}"
56✔
67
        printf "keychain = %s\n" "$@" >> "${PW_CONFIG}"
56✔
68
}
69

70
_config_append_keychains_with_key() {
71
        echo "[keychains]" >> "${PW_CONFIG}"
24✔
72
        printf "%s\n" "$@" >> "${PW_CONFIG}"
24✔
73
}
74

75
assert_init_already_exists() {
76
        run pw init "${PW_KEYCHAIN}"
12✔
77
        assert_failure
12✔
78
        assert_output "pw: ${PW_KEYCHAIN} already exists."
8✔
79
}
80

81
assert_item_exists() {
82
        local password="$1"; shift
712✔
83
        run pw -p "$@"
356✔
84
        assert_success
344✔
85
        assert_output "${password}"
344✔
86
}
87

88
assert_item_not_exists() {
89
        run pw "$@"
56✔
90
        assert_failure
32✔
91
        assert_item_not_exists_output "$@"
32✔
92
}
93

94
assert_adds_item() {
95
        local password="$1"; shift
648✔
96
        run pw add "$@" <<< "${password}"
324✔
97
        assert_success
320✔
98
        refute_output
318✔
99
}
100

101
assert_adds_item_with_keychain_password() {
102
        local password="$1"; shift
312✔
103
        run pw add "$@" << EOF
156✔
104
${KEYCHAIN_TEST_PASSWORD}
105
${password}
106
EOF
107
        assert_success
156✔
108
        refute_output
156✔
109
}
110

111
assert_item_already_exists() {
112
        local password="$1"; shift
24✔
113
        run pw add "$@" <<< "${password}"
12✔
114
        assert_failure
12✔
115
        assert_item_already_exists_output "$@"
12✔
116
}
117

118
assert_item_already_exists_with_keychain_password() {
119
        local password="$1"; shift
8✔
120
        run pw add "$@" << EOF
4✔
121
${KEYCHAIN_TEST_PASSWORD}
122
${password}
123
EOF
124
        assert_failure
×
125
        assert_item_already_exists_output "$@"
×
126
}
127

128
assert_removes_item() {
129
        run pw rm "$@"
36✔
130
        assert_success
36✔
131
        assert_removes_item_output "$@"
36✔
132
}
133

134
assert_rm_not_found() {
135
        run pw rm "$@"
20✔
136
        assert_failure
16✔
137
        assert_rm_not_found_output "$@"
16✔
138
}
139

140
assert_edits_item() {
141
        local password="$1"; shift
80✔
142
        run pw edit "$@" <<< "${password}"
40✔
143
        assert_success
40✔
144
        refute_output
40✔
145
}
146

147
assert_edits_item_with_keychain_password() {
148
        local password="$1"; shift
40✔
149
        run pw edit "$@" << EOF
20✔
150
${KEYCHAIN_TEST_PASSWORD}
151
${password}
152
EOF
153
        assert_success
24✔
154
        refute_output
24✔
155
}
156

157
assert_renames_item() {
158
        local rename="$1"; shift
32✔
159
        run pw mv "$@" <<< "${rename}"
16✔
160
        assert_success
16✔
161
        refute_output
16✔
162
}
163

164
assert_renames_item_with_keychain_password() {
165
        local rename="$1"; shift
64✔
166
        run pw mv "$@" << EOF
32✔
167
${KEYCHAIN_TEST_PASSWORD}
168
${rename}
169
EOF
170
        assert_success
28✔
171
}
172

173
_skip_manual_test() {
174
        if [[ -v PW_TEST_RUN_MANUAL_TESTS ]]; then
76✔
175
                echo "# Please enter $1" >&3
×
176
        else
177
                skip "Requires user input. Use test/run -m to also run manual tests."
76✔
178
        fi
179
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc