aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiquel Sabaté <mikisabate@gmail.com>2015-08-01 23:45:55 +0200
committerMiquel Sabaté <mikisabate@gmail.com>2015-08-01 23:45:55 +0200
commit112819777c7f77a47a97474dee21bbe1cfe531ec (patch)
treeef19201173696b0d7e4e2aad518b22dab8d1e35a
parent0c254aded5a945a2bba1ab30265c344392a7f4fa (diff)
downloadg-112819777c7f77a47a97474dee21bbe1cfe531ec.tar.gz
g-112819777c7f77a47a97474dee21bbe1cfe531ec.zip
The test suite is working just fine
-rw-r--r--.travis.yml1
-rw-r--r--Dockerfile8
-rw-r--r--g.sh2
-rwxr-xr-xrun-tests.sh29
-rw-r--r--t/expected.txt26
-rw-r--r--t/tests.sh66
6 files changed, 91 insertions, 41 deletions
diff --git a/.travis.yml b/.travis.yml
index ff68d06..1530789 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,7 +1,6 @@
language: bash
before_script:
- - source g.sh
- sudo apt-get install -y zsh
script:
diff --git a/Dockerfile b/Dockerfile
deleted file mode 100644
index 227634b..0000000
--- a/Dockerfile
+++ /dev/null
@@ -1,8 +0,0 @@
-FROM opensuse:latest
-MAINTAINER Miquel Sabaté Solà <mikisabate@gmail.com>
-
-RUN mkdir /g
-WORKDIR /g
-ADD . /g
-
-ENTRYPOINT ["bash", "t/tests.sh"]
diff --git a/g.sh b/g.sh
index 85498e0..09ff810 100644
--- a/g.sh
+++ b/g.sh
@@ -116,7 +116,7 @@ g() {
return 1
fi
__g_get_shortcuts
- __g_shortcuts[$2]=$path
+ __g_shortcuts[$2]=$(realpath $path)
__g_save_shortcuts
;;
rm)
diff --git a/run-tests.sh b/run-tests.sh
deleted file mode 100755
index 1135351..0000000
--- a/run-tests.sh
+++ /dev/null
@@ -1,29 +0,0 @@
-# Copyright (C) 2013-2015 Miquel Sabaté Solà <mikisabate@gmail.com>
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License along
-# with this program; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
-set -e
-
-if [ -z "$(pidof docker)" ]; then
- echo "Docker has to be running!"
- exit 1
-fi
-if [ ! -z "$(docker images g | grep latest)" ]; then
- id="$(docker images g | grep latest | awk '{ print $3 }')"
- docker rmi $id
-fi
-
-docker build -t g:latest .
-docker run --rm -it g:latest
diff --git a/t/expected.txt b/t/expected.txt
new file mode 100644
index 0000000..d78dcb8
--- /dev/null
+++ b/t/expected.txt
@@ -0,0 +1,26 @@
+g version 0.3.8
+g version 0.3.8
+usage: g [-h | --help] [-v | --version] <command> [<args>]
+
+The g commands are:
+ add Add a new shortcut.
+ rm Remove a shorcut.
+ list List all the available shortcuts.
+usage: g [-h | --help] [-v | --version] <command> [<args>]
+
+The g commands are:
+ add Add a new shortcut.
+ rm Remove a shorcut.
+ list List all the available shortcuts.
+Cannot use 'add': keyword.
+usage: g add <name> [path]
+usage: g rm <name>
+usage: g rm <name>
+b root
+b root
+b
+t
+c
+Unknown shortcut `unknown'.
+
+usage: g [-h | --help] [-v | --version] <command> [<args>]
diff --git a/t/tests.sh b/t/tests.sh
index 79c635f..a0d32e2 100644
--- a/t/tests.sh
+++ b/t/tests.sh
@@ -15,5 +15,67 @@
set -e
-echo "Hello World"
-exit 0
+# Cleanup previous tests and setup some special variables.
+d="$(realpath $(dirname $0))"
+rm -f $d/output.txt
+HOME="$d"
+
+# Setup the test file system.
+mkdir -p $d/a/b/c
+mkdir -p $d/a/d
+
+source $d/../g.sh
+
+# First check that the basic commands are there.
+g -v &>> $d/output.txt
+g --version &>> $d/output.txt
+g -h &>> $d/output.txt
+g --help &>> $d/output.txt
+
+# Let's add some shortcuts.
+cd $d
+g add root
+g add b a/b
+g add c a/b/c
+
+# Errors on the `add` command.
+set +e
+g add add &>> $d/output.txt
+g add lala lala lala &>> $d/output.txt
+set -e
+
+# Removing shortcuts.
+g rm c
+g rm d
+
+# Errors on the `rm` command.
+set +e
+g rm &>> $d/output.txt
+g rm lala lala &>> $d/output.txt
+set -e
+
+# The list command.
+g list --keys &>> $d/output.txt
+g list | awk '{ print $1 }' | xargs &>> $d/output.txt
+
+# Bare g command.
+original=`pwd`
+cd /
+g b
+basename $(pwd) &>> $d/output.txt
+g root
+basename $(pwd) &>> $d/output.txt
+g root/a/b/c
+basename $(pwd) &>> $d/output.txt
+cd $original
+
+# Unknown shortcut.
+set +e
+g unknown &>> $d/output.txt
+set -e
+
+# Teardown
+diff $d/output.txt $d/expected.txt
+rm $d/output.txt
+rm -rf a
+rm -rf $d/.gfile