Skip to content

Commit

Permalink
getting a bit better
Browse files Browse the repository at this point in the history
  • Loading branch information
bitplane committed Dec 22, 2024
1 parent 032b75b commit e2d2a9a
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 38 deletions.
3 changes: 2 additions & 1 deletion src/lifecap-topic
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ Topics are channels where data flows."

. $(dirname $0)/lifecap_lib.sh


echo $HELP >&2
exit 1
8 changes: 1 addition & 7 deletions src/lifecap-topic-ls
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,9 @@ fi
# CASE 1: No partial path -> list all top-level topics
# ------------------------------------------------------------
if [ -z "$partial_path" ]; then
# If the directory for topics doesn't exist at all
if [ ! -d "$data_dir/topics" ]; then
echo "No topics found." >&2
exit 0
fi

found="false"
# List only directories at one level (i.e., topic names)
for d in "$data_dir/topics"/*/ 2>/dev/null; do
for d in "$data_dir/topics"/*/; do
[ -d "$d" ] || continue
found="true"
echo "$(basename "$d")"
Expand Down
4 changes: 2 additions & 2 deletions src/lifecap-topic-write
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ topic_name="$1"
shift

if [ -z "$topic_name" ]; then
echo "Error: No topic name specified."
echo "$HELP"
echo "Error: No topic name specified." >&2
echo "$HELP" >&2
exit 1
fi

Expand Down
10 changes: 9 additions & 1 deletion test/_setup.sh
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
PATH=$(dirname "$0")/../src:$PATH
export PATH=$(dirname "$0")/../src:$PATH

export test_tempdir="/tmp/lifecap-tests-$$"
mkdir -p "$test_tempdir"

export HOME="$test_tempdir"
export XDG_CONFIG_HOME=$HOME/.config
export XDG_DATA_HOME=$HOME/.local/share
export XDG_CACHE_HOME=$HOME/.cache
1 change: 1 addition & 0 deletions test/_teardown.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rm -rf "/tmp/lifecap-tests-$$"
56 changes: 33 additions & 23 deletions test/_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -127,37 +127,42 @@ $front"
# Start from RUN_DIR
cd "$RUN_DIR" || return 1

# Descend directories, sourcing any _setup.sh
oldIFS="$IFS"
IFS='
(
# Descend directories, sourcing any _setup.sh
oldIFS="$IFS"
IFS='
'
for d in $path_dirs; do
[ -z "$d" ] && continue
if ! __test_pushd "$d" >/dev/null; then
echo "ERROR: cannot push into '$d' (from path $file)" >&2
for d in $path_dirs; do
[ -z "$d" ] && continue
if ! __test_pushd "$d" >/dev/null; then
echo "ERROR: cannot push into '$d' (from path $file)" >&2
__test_cleanup_dirs
IFS="$oldIFS"
return 1
fi

if [ -f "_setup.sh" ]; then
. "./_setup.sh"
fi
done
IFS="$oldIFS"

# Must exist
if [ ! -f "$script_name" ]; then
echo "ERROR: test script '$script_name' not found in $(pwd -P)" >&2
__test_cleanup_dirs
IFS="$oldIFS"
return 1
fi

if [ -f "_setup.sh" ]; then
. "./_setup.sh"
fi
done
IFS="$oldIFS"
# Run the test script in the current shell
set -e
. "./$script_name" || test_status=$?

# Must exist
if [ ! -f "$script_name" ]; then
echo "ERROR: test script '$script_name' not found in $(pwd -P)" >&2
__test_cleanup_dirs
return 1
fi

# Run the test script in the current shell
. "./$script_name" || test_status=$?

__test_cleanup_dirs
return $test_status
return $test_status
)
return $?
}

###############################################################################
Expand Down Expand Up @@ -220,3 +225,8 @@ __test_run_all() {

return $ret
}

__assert() {
[ "$1" "$2" "$3" ] && return 0
return 1
}
5 changes: 5 additions & 0 deletions test/cli/config/test_config_dirs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

res=$(lifecap config | grep $test_tempdir | wc -l)

__assert "$res" -eq "3"

5 changes: 5 additions & 0 deletions test/cli/topic/test_add_topic.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
lifecap topic add test-topic

find $test_tempdir*

__assert "$(lifecap topic ls)" "=" "test-topic"
2 changes: 0 additions & 2 deletions test/topic/file/_setup.sh

This file was deleted.

2 changes: 0 additions & 2 deletions test/topic/file/test_write.sh

This file was deleted.

0 comments on commit e2d2a9a

Please sign in to comment.