Skip to content

Commit 53f31d2

Browse files
committed
fix: Clenup some TODO's
1 parent 729a558 commit 53f31d2

File tree

5 files changed

+24
-36
lines changed

5 files changed

+24
-36
lines changed

pkg/lib/parse.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,9 @@ bash_object.parse_filter() {
3636
done
3737
IFS="$old_ifs"
3838
elif [ "$flag_parser_type" = 'advanced' ]; then
39-
# TODO: scope
40-
declare char=
41-
declare mode='MODE_DEFAULT'
42-
declare -i PARSER_COLUMN_NUMBER=0
39+
local char=
40+
local mode='MODE_DEFAULT'
41+
local -i PARSER_COLUMN_NUMBER=0
4342

4443
# Append dot so parsing does not fail at end
4544
# This makes parsing a lot easier, since it always expects a dot after a ']'

pkg/lib/util/ensure.sh

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@ bash_object.ensure.variable_does_exist() {
1616

1717
if ! declare -p "$variable_name" &>/dev/null; then
1818
bash_object.util.die 'ERROR_INTERNAL' "Variable '$variable_name' does not exist, but it should"
19-
return
19+
return
2020
fi
2121
}
2222

23-
# TODO
24-
# @description Test if the variable already exists. Note that the variable _must_ be sanitized before using this function
23+
# @description Ensure the variable does not exist
2524
bash_object.ensure.variable_does_not_exist() {
2625
local variable_name="$1"
2726

@@ -30,20 +29,8 @@ bash_object.ensure.variable_does_not_exist() {
3029
return
3130
fi
3231

33-
if ((BASH_VERSINFO[0] >= 5)) || ((BASH_VERSINFO[0] == 4 && BASH_VERSINFO[1] >= 2)); then
34-
if [[ -v "$variable_name" ]]; then
35-
bash_object.util.die 'ERROR_INTERNAL' "Variable '$variable_name' exists, but it shouldn't"
36-
return
37-
fi
38-
else
39-
if ! eval "
40-
if ! [ -z \${$variable_name+x} ]; then
41-
bash_object.util.die 'ERROR_INTERNAL' \"Variable '$variable_name' exists, but it shouldn't\"
42-
return
43-
fi
44-
"; then
45-
bash_object.util.die 'ERROR_INTERNAL' 'Eval unset test'
46-
return
47-
fi
32+
if bash_object.ensure.variable_does_exist "$1"; then
33+
bash_object.util.die 'ERROR_INTERNAL' "Variable '$variable_name' exists, but it shouldn't"
34+
return
4835
fi
4936
}

pkg/lib/util/util.sh

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ bash_object.util.die() {
2121
local error_key="$1"
2222
local error_context="${2:-<empty>}"
2323

24-
# TODO: test
25-
# if [[ ! -v 'ERRORS_BASH_OBJECT["$error_key"]' ]]; then
26-
# return 77
27-
# fi
28-
2924
local error_output=
3025
case "$error_key" in
3126
ERROR_FILTER_INVALID)
@@ -60,7 +55,7 @@ bash_object.util.generate_vobject_name() {
6055
random_string="${RANDOM}_${RANDOM}_${RANDOM}_${RANDOM}_${RANDOM}"
6156
fi
6257

63-
REPLY="__bash_object_${root_object_name}_${root_object_query}_${random_string}"
58+
printf -v REPLY '%q' "__bash_object_${root_object_name}_${root_object_query}_${random_string}"
6459
}
6560

6661
# @description A stringified version of the filter

tests/get-errors-param.bats

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
load './util/init.sh'
88

99
# get
10+
@test "Error on invalid \$1" {
11+
run bobject get-blah
12+
13+
assert_failure
14+
assert_line -p "ERROR_ARGUMENTS_INVALID"
15+
assert_line -p "Subcommand 'get-blah' not recognized"
16+
}
17+
1018
@test "Error with \$# of 2" {
1119
run bobject get-string --as-value 'OBJECT'
1220

tests/set-errors-param.bats

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,13 @@ load './util/init.sh'
7777
assert_line -p ", but received '5'"
7878
}
7979

80-
# TODO?
81-
# @test "Error on empty \$1" {
82-
# run bobject
83-
84-
# assert_failure
85-
# assert_line -p "ERROR_ARGUMENTS_INVALID"
86-
# assert_line -p "'1' is empty"
87-
# }
80+
@test "Error on invalid \$1" {
81+
run bobject set-blah
82+
83+
assert_failure
84+
assert_line -p "ERROR_ARGUMENTS_INVALID"
85+
assert_line -p "Subcommand 'set-blah' not recognized"
86+
}
8887

8988
@test "Error on empty \$2" {
9089
run bobject set-string --by-ref "" '.obj' obj

0 commit comments

Comments
 (0)