Skip to content

Commit ba8994f

Browse files
committed
Added unit-tests and fixversion tools
1 parent d3a5d14 commit ba8994f

File tree

12 files changed

+449
-46
lines changed

12 files changed

+449
-46
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
tmp/**
2+
tests/**
23
!tmp/README
34
*.bak
45

docs/FIXVERSION.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# fixversion command
2+
3+
I have included a build tool that will compate versions and dates of the
4+
various files in this application.
5+
6+
## Checking versions and dates
7+
8+
```shell
9+
$ fixversion
10+
```
11+
12+
## Fix dates and versions
13+
14+
To change all the version numbers in the various scripts and man pages
15+
to the latest git tag version and current date run the following
16+
command:
17+
18+
```shell
19+
$ fixversion fix
20+
```

docs/UNIT-TESTS.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
# UNIT TESTING NOTES DEVELOPMENT
3+
4+
The shell script 'unit-tests' runs a series of tests on the notes(1),
5+
notebook(1) and journal(1) scripts.
6+
7+
Each function is tested for the appropriate output (directories created,
8+
files encrypted etc) and any errors output to tests/error_log_for_unit_tests.
9+
10+
The shell script places an appropriate framework around each script and
11+
runs through a series of test use cases checking what is output compared
12+
to what is expected.
13+
14+
15+
## RUNNING UNIT TESTS
16+
17+
To run the unit tests you need to set the environment variable $TESTKEY
18+
to the GPG Key you wish to use and then run the 'unit-tests' shell script.
19+
20+
21+
```shell
22+
$ export TESTKEY="E33A79B685AA......325F41243EDA850A"
23+
$ ./unit-tests
24+
```
25+
26+
The script edits the notes(1) config file after creation to point to the
27+
GPG key $TESTKEY. this allows the user to guarantee which GPG key is
28+
used in the unit-tests script if the developer has more than one private key.
29+
30+
### Testing "notes newkey newGPGkey"
31+
32+
If the user also sets $ALTGPGKEY before running the test then the
33+
notes(1) command 'newkey' will decrypt from $TESTKEY and then encrypt to
34+
$ALTGPGKEY.
35+
36+
If no $ALTGPGKEY is found in the environment the unit-tests script will
37+
set $ALTGPGKEY = $TESTKEY to test notes newkey command.
38+

docs/journal.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.\" Manpage for Standard (?) Unix Notes
22
.\" aka notes
33
.\" See https://github.com/Standard-Unix-Notes/unix-notes
4-
.TH journal 1 "24 June 2021" "2.2" "Journal man page"
4+
.TH journal 1 "06 July 2021" "2.5" "Journal man page"
55
.SH NAME
66
Journal \- GPG encrypted journal
77
.SH SYNOPSIS

docs/notebook.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.\" Manpage for Standard (?) Unix Notes
22
.\" aka notes
33
.\" See https://github.com/Standard-Unix-Notes/unix-notes
4-
.TH notebook 1 "24 June 2021" "2.2" "Notes man page"
4+
.TH notebook 1 "06 July 2021" "2.5" "Notes man page"
55
.SH NAME
66
Notes \- GPG encrypted notes
77
.SH SYNOPSIS

docs/notes.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.\" Manpage for Standard (?) Unix Notes
22
.\" aka notes
33
.\" See https://github.com/Standard-Unix-Notes/unix-notes
4-
.TH notes 1 "24 June 2021" "2.2" "Notes man page"
4+
.TH notes 1 "06 July 2021" "2.5" "Notes man page"
55
.SH NAME
66
Notes \- GPG encrypted notes
77
.SH SYNOPSIS

fixversion

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/bin/sh
2+
TESTDIR="`pwd`/tests"
3+
ERRORLOG="${TESTDIR}/error_log_for_unit_tests"
4+
rm -f $ERRORLOG
5+
log () {
6+
echo $@ >> $ERRORLOG
7+
}
8+
FIXUP=0
9+
test "$1" = "fix" && FIXUP=1
10+
11+
display () {
12+
13+
cat << EOF
14+
15+
==== VERSIONS & DATES IN FILES ====
16+
17+
TODAY = $TODAY
18+
19+
SCRIPTS:
20+
notes $NOTESVER
21+
notebook $NOTEBOOKVER
22+
journal $JOURNALVER
23+
24+
MAN PAGES:
25+
notes(1) $NOTESMAN $NOTESMANDATE
26+
notebook(1) $NOTEBOOKMAN $NOTEBOOKMANDATE
27+
journal(1) $JOURNALMAN $JOURNALMANDATE
28+
29+
GIT TAGS:
30+
git $GITVER
31+
32+
EOF
33+
34+
}
35+
36+
get_versions () {
37+
# get versions and dates
38+
NOTESVER="`grep -m 1 VERSION notes | cut -d '=' -f 2 `"
39+
NOTEBOOKVER="`grep -m 1 VERSION notebook | cut -d '=' -f 2 `"
40+
JOURNALVER="`grep -m 1 VERSION journal | cut -d '=' -f 2 `"
41+
GITVER="`make ver`"
42+
NOTESMAN="`grep .TH docs/notes.1 | cut -d ' ' -f 7 | cut -d '\"' -f 2 `"
43+
NOTESMANDATE="`grep .TH docs/notes.1 | cut -d ' ' -f 4-6 | cut -d '\"' -f 2 `"
44+
NOTEBOOKMAN="`grep .TH docs/notebook.1 | cut -d ' ' -f 7 | cut -d '\"' -f 2 `"
45+
NOTEBOOKMANDATE="`grep .TH docs/notebook.1 | cut -d ' ' -f 4-6 | cut -d '\"' -f 2 `"
46+
JOURNALMAN="`grep .TH docs/journal.1 | cut -d ' ' -f 7 | cut -d '\"' -f 2 `"
47+
JOURNALMANDATE="`grep .TH docs/journal.1 | cut -d ' ' -f 4-6 | cut -d '\"' -f 2 `"
48+
TODAY="`date +\"%d %B %Y\"`"
49+
}
50+
51+
get_versions
52+
53+
if [ $FIXUP -eq 1 ] ; then
54+
echo fixing up version and dates
55+
56+
sed -i "s/^VERSION=.*/VERSION=${GITVER}/" notes
57+
# no need to edit notebook(1) as is link to notes
58+
sed -i "s/^VERSION=.*/VERSION=${GITVER}/" journal
59+
sed -i "/^.TH/s/\"${NOTESMAN}\"/\"${GITVER}\"/" docs/notes.1
60+
sed -i "/^.TH/s/\"${NOTEBOOKMAN}\"/\"${GITVER}\"/" docs/notebook.1
61+
sed -i "/^.TH/s/\"${JOURNALMAN}\"/\"${GITVER}\"/" docs/journal.1
62+
# and the dates ...
63+
sed -i "/^.TH/s/\"${NOTESMANDATE}\"/\"${TODAY}\"/" docs/notes.1
64+
sed -i "/^.TH/s/\"${NOTEBOOKMANDATE}\"/\"${TODAY}\"/" docs/notebook.1
65+
sed -i "/^.TH/s/\"${JOURNALMANDATE}\"/\"${TODAY}\"/" docs/journal.1
66+
else
67+
# just log to errorlog
68+
test "$GITVER" != "$NOTESVER" && log GITVER not equal to NOTESVER
69+
test "$GITVER" != "$NOTEBOOKVER" && log GITVER not equal to NOTEBOOKVER
70+
test "$GITVER" != "$JOURNALVER" && log GITVER not equal to JOURNALVER
71+
test "$GITVER" != "$NOTESMAN" && log GITVER not equal to NOTESMAN
72+
test "$GITVER" != "$NOTEBOOKMAN" && log GITVER not equal to NOTEBOOKMAN
73+
test "$GITVER" != "$JOURNALMAN" && log GITVER not equal to JOURNALMAN
74+
fi
75+
76+
get_versions
77+
78+
display

journal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# The idea came from 'pass' the standard Unix password manager
1010

1111
# VARIABLES
12-
VERSION=2.1
12+
VERSION=2.5
1313
#NOTES_UMASK='077'
1414
# Handle $XDG_DATA_DIR -or- NOTESDIR being set in environment
1515
if [ -n "$XDG_DATA_DIR" -a -z "$NOTESDIR" ] ; then

makefile

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,22 @@ help:
1717
@echo ""
1818
@sed -n s/^##//p makefile
1919

20+
## make unit Run Unit Tests
21+
unit:
22+
./unit-tests
23+
24+
## make ver Show version tag
25+
ver:
26+
@echo $(VER)
27+
28+
## make fix Create a fix versions and date in files c.f. git tag
29+
fix:
30+
@echo run \"fixversion fix\" to fix versions and dates to $(VER)
31+
2032
## make var Show makefile variables
2133
var:
22-
@echo Operating System = $(OS)
2334
@echo Latest Git tag {Version} = $(VER)
35+
@echo Operating System = $(OS)
2436
@echo Tarball Location = $(TARBALLLOC)
2537
@echo Package Name = $(PKGNAME)
2638
@echo Tarball Name = $(TARBALL)
@@ -50,9 +62,8 @@ manpages:
5062

5163
clean:
5264
@echo clean up after build
53-
-rm tmp/notes.1.gz
54-
-rm tmp/notebook.1.gz
55-
-rm tmp/journal.1.gz
65+
-rm -rf tmp/*
66+
-rm -rf tests/*
5667

5768
## make uninstall Uninstall the application
5869
uninstall:

notes

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# The idea came from 'pass' the standard Unix password manager
88

99
# VARIABLES
10-
VERSION=2.1
10+
VERSION=2.5
1111
#NOTES_UMASK='077'
1212
# Handle $XDG_DATA_DIR -or- NOTESDIR being set in environment
1313
if [ -n "$XDG_DATA_DIR" -a -z "$NOTESDIR" ] ; then
@@ -43,23 +43,17 @@ else
4343
SHREDCMD="rm"
4444
fi
4545

46-
USEGIT=`grep git ${CONFIGFILE}| cut -d'=' -f 2`
46+
USEGIT="`grep git ${CONFIGFILE}| cut -d'=' -f 2`"
4747

48-
SPELLCHECK=`grep spelling $CONFIGFILE | cut -d'=' -f 2`
49-
spellcheck () {
48+
spell_check () {
49+
SPELLCHECK="`grep spelling ${CONFIGFILE} | cut -d '=' -f 2`"
5050
case ${SPELLCHECK} in
5151
aspell)
52-
SPELLINGCMD="aspell -x -c "
53-
${SPELLINGCMD} ${notefile}
52+
aspell -x -c ${notefile}
5453
;;
5554
ispell)
56-
SPELLINGCMD="ispell -x "
57-
${SPELLINGCMD} ${notefile}
55+
ispell -x ${notefile}
5856
;;
59-
none)
60-
;;
61-
*)
62-
echo Invalid config option `grep "spellcheck" ${CONFIGFILE}`
6357
esac
6458
}
6559

@@ -93,10 +87,6 @@ cmd_init (){ # setup directories and GPG key to be used
9387

9488
echo "Creating Journal directory ${JOURNALDIR} "
9589
mkdir -p $JOURNALDIR
96-
97-
echo params $1
98-
99-
10090
}
10191

10292
create_config () {
@@ -124,7 +114,7 @@ create_config () {
124114
echo Do you want spellchecking enabled?
125115
echo "1) Use aspell"
126116
echo "2) Use ispell"
127-
echo "3) Do not spellcheck"
117+
echo "3) Do not spell check"
128118
read -p "Choose 1,2,or 3: " choosespell
129119
case $choosespell in
130120
1)
@@ -209,7 +199,12 @@ note_add () {
209199
filen="$@"
210200
notefile="${USE_POINTER}/`echo ${filen} | tr ' ' '_'`"
211201

212-
if [ -f "$notefile.asc" ] ; then
202+
if [ "$filen" = "" ] ; then
203+
echo No notefile name given ... exiting
204+
exit 1
205+
fi
206+
207+
if [ -f "${notefile}.asc" ] ; then
213208
echo File exists ... cannot create. Try 'notes edit' instead.
214209
exit 1
215210
else
@@ -220,7 +215,7 @@ note_add () {
220215
# create temporary note file
221216
$EDITOR "$notefile"
222217

223-
spellcheck
218+
spell_check
224219

225220
# encrypt note file
226221
$GPG -ear $KEY $GPG_OPTS "$notefile"
@@ -278,13 +273,13 @@ note_edit () {
278273
if [ -f "$notefile" ]; then
279274
gpg -d -o "${decrypted}" "${notefile}"
280275
${EDITOR} "${decrypted}"
281-
spellcheck
276+
spell_check
282277
$GPG -ear $KEY $GPG_OPTS "${decrypted}"
283278
${SHREDCMD} ${decrypted}
284279
elif [ -f "${notefile}.asc" ]; then
285280
gpg -d -o "${decrypted}" "${notefile}.asc"
286281
${EDITOR} "${decrypted}"
287-
spellcheck
282+
spell_check
288283
$GPG -ear $KEY $GPG_OPTS "${decrypted}"
289284
${SHREDCMD} ${decrypted}
290285
else
@@ -390,15 +385,7 @@ notebook_delete () {
390385
echo Error: Notebook \'$notebook\' does not exist
391386
exit 1
392387
else
393-
echo Deleting files from $notebook
394-
${SHREDCMD} ${notebook}/*.asc
395-
396-
if [ $? = 0 ] ; then
397-
rmdir "$notebook"
398-
else
399-
echo Deleting files aborted ... aborting deleting notebook $notebook
400-
exit 1
401-
fi
388+
rm -rf $notebook
402389
fi
403390

404391
if [ "$USEGIT" = "y" ]; then
@@ -468,7 +455,7 @@ GPG encrypted notes system for BSD and Linux systems
468455
469456
notes init initialise notes system
470457
notes config display config file
471-
notes backup backup $NOTESDIR to GPG encrypted tar file
458+
notes backup backup NOTESDIR to GPG encrypted tar file
472459
notes newkey email change GPG key
473460
notes help show help
474461
notes version show version
@@ -638,7 +625,7 @@ cmd_default () {
638625

639626
if [ "$nb" = "" ] ;then
640627
echo Default notebook = "`readlink -f $DEFAULT_POINTER`"
641-
exit 0
628+
return 0
642629
fi
643630
if [ -d "$notebook" ] ; then
644631
unlink "$DEFAULT_POINTER"
@@ -664,7 +651,7 @@ cmd_use () {
664651
echo no notebook specified using default notebook
665652
unlink "$USE_POINTER"
666653
ln -s "`basename $defaultnbval`" "$USE_POINTER"
667-
exit 0
654+
return 0
668655
fi
669656
if [ -d "$notebook" ] ; then
670657
unlink "$USE_POINTER"
@@ -779,6 +766,5 @@ case "$1" in
779766
git) shift; cmd_git "$@" ;;
780767
*) cmd_extension_or_show "$@" ;;
781768
esac
782-
exit 0
783769

784770

0 commit comments

Comments
 (0)