Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
bashopts
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mbedsys
bashopts
Commits
86300291
Commit
86300291
authored
Dec 17, 2018
by
Emeric Verschuur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip
parent
72fd4d7e
Pipeline
#108
failed with stage
in 0 seconds
Changes
3
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
197 additions
and
205 deletions
+197
-205
.gitlab-ci.yml
.gitlab-ci.yml
+8
-2
bashopts.sh
bashopts.sh
+177
-163
test.sh
test.sh
+12
-40
No files found.
.gitlab-ci.yml
View file @
86300291
stages
:
stages
:
-
test
-
test
tests
:
tests-bash-4.3
:
image
:
ubuntu:16.04
image
:
bash:4.3
script
:
-
./test.sh
stage
:
test
tests-bash-4.4
:
image
:
bash:4.4
script
:
script
:
-
./test.sh
-
./test.sh
stage
:
test
stage
:
test
bashopts.sh
View file @
86300291
This diff is collapsed.
Click to expand it.
test.sh
View file @
86300291
#!/
bin/bash -e
#!/
usr/bin/env bash
# Copyright 2017-2018 Emeric Verschuur <emeric@mbedsys.org>
# Copyright 2017-2018 Emeric Verschuur <emeric@mbedsys.org>
#
#
# Licensed to the Apache Software Foundation (ASF) under one
# Licensed to the Apache Software Foundation (ASF) under one
...
@@ -18,6 +18,8 @@
...
@@ -18,6 +18,8 @@
# specific language governing permissions and limitations
# specific language governing permissions and limitations
# under the License.
# under the License.
set
-e
.
bashopts.sh
.
bashopts.sh
trap
'bashopts_exit_handle'
ERR
trap
'bashopts_exit_handle'
ERR
...
@@ -47,14 +49,14 @@ _test_case_2() {
...
@@ -47,14 +49,14 @@ _test_case_2() {
bashopts_setup
-n
"
$0
"
-d
"Test case
$0
"
-s
/tmp/bashopts_testrc
bashopts_setup
-n
"
$0
"
-d
"Test case
$0
"
-s
/tmp/bashopts_testrc
bashopts_declare
-n
base_path
-l
base
-o
b
-d
"Base path"
-t
string
-v
"/opt/test"
-i
-s
bashopts_declare
-n
base_path
-l
base
-o
b
-d
"Base path"
-t
string
-v
"/opt/test"
-i
bashopts_declare
-n
config_path
-l
config
-o
c
-d
"Configuration path"
-t
string
-x
"
\$
base_path/myconf.cfg"
-s
bashopts_declare
-n
config_path
-l
config
-o
c
-d
"Configuration path"
-t
string
-x
"
\$
base_path/myconf.cfg"
-s
bashopts_parse_args
--base
/tmp
-n
bashopts_parse_args
--base
/tmp
-n
bashopts_process_opts
bashopts_process_opts
req_test_eq
"
$config_path
"
"/tmp/myconf.cfg"
req_test_eq
"
$config_path
"
"/tmp/myconf.cfg"
req_test_eq
"
$(
cat
/tmp/bashopts_testrc
)
"
"
base_path=/tmp
"
req_test_eq
"
$(
cat
/tmp/bashopts_testrc
)
"
"
config_path=/tmp/myconf.cfg
"
}
}
_test_case_3
()
{
_test_case_3
()
{
...
@@ -155,7 +157,7 @@ _test_case_10() {
...
@@ -155,7 +157,7 @@ _test_case_10() {
bashopts_declare
-n
simple_val
-s
-l
value
-d
"Simple value"
-t
string
-v
'val'
bashopts_declare
-n
simple_val
-s
-l
value
-d
"Simple value"
-t
string
-v
'val'
bashopts_parse_args
--value
=
test
bashopts_parse_args
--value
=
test
req_test_eq
"
$(
bashopts_process_opts 2>&1
)
"
"[WARN] No settings file specified"
req_test_eq
"
$(
bashopts_process_opts 2>&1
)
"
"[WARN]
Option simple_val:
No settings file specified"
}
}
_test_case_11
()
{
_test_case_11
()
{
...
@@ -164,7 +166,7 @@ _test_case_11() {
...
@@ -164,7 +166,7 @@ _test_case_11() {
bashopts_declare
-n
simple_val
-s
-l
value
-d
"Simple value"
-t
string
-v
'val'
bashopts_declare
-n
simple_val
-s
-l
value
-d
"Simple value"
-t
string
-v
'val'
bashopts_parse_args
--value
=
test
bashopts_parse_args
--value
=
test
req_test_eq
"
$(
bashopts_process_opts 2>&1 |
grep
'WARN'
)
"
"[WARN] Please check the settings file"
req_test_eq
"
$(
bashopts_process_opts 2>&1 |
grep
'WARN'
)
"
"[WARN]
Option simple_val:
Please check the settings file"
}
}
_test_case_12
()
{
_test_case_12
()
{
...
@@ -235,37 +237,6 @@ _test_case_15() {
...
@@ -235,37 +237,6 @@ _test_case_15() {
req_test_eq
"
$(
cat
/tmp/bashopts_testrc
)
"
'array_value=([0]="value 1" [1]="value 3")'
req_test_eq
"
$(
cat
/tmp/bashopts_testrc
)
"
'array_value=([0]="value 1" [1]="value 3")'
}
}
_test_case_16
()
{
rm
-f
/tmp/bashopts_testrc
bashopts_setup
-n
"
$0
"
-d
"Test case
$0
"
-s
/tmp/bashopts_testrc
bashopts_declare
-n
array_value
-l
value
-m
add
-d
"Array value"
-s
-i
-t
string
-x
'("value 1" "value 2")'
bashopts_parse_args
--value
""
bashopts_process_opts
>
/dev/null
<<<
'( "value 1" "value 2" )'
req_test_eq
"
${#
array_value
[@]
}
"
"2"
req_test_eq
"
${
array_value
[0]
}
"
"value 1"
req_test_eq
"
${
array_value
[1]
}
"
"value 2"
if
[
-f
/tmp/bashopts_testrc
]
;
then
echo
"file /tmp/bashopts_testrc should not be present"
exit
1
fi
}
_test_case_17
()
{
rm
-f
/tmp/bashopts_testrc
bashopts_setup
-n
"
$0
"
-d
"Test case
$0
"
-s
/tmp/bashopts_testrc
-p
bashopts_declare
-n
a_value
-l
value
-d
"A value"
-s
-i
-t
string
-v
"default value"
bashopts_parse_args
bashopts_process_opts
>
/dev/null
<<<
""
req_test_eq
"
$a_value
"
"default value"
req_test_eq
"
$(
cat
/tmp/bashopts_testrc
)
"
"a_value='default value'"
}
_test_case_18
()
{
_test_case_18
()
{
bashopts_setup
-n
"
$0
"
-d
"Test case
$0
"
bashopts_setup
-n
"
$0
"
-d
"Test case
$0
"
...
@@ -310,7 +281,7 @@ _test_case_20() {
...
@@ -310,7 +281,7 @@ _test_case_20() {
req_test_eq
"
$(
echo
"
$(
bashopts_process_option
-n
value
-k
is_eq_to_null
-r
2>&1
>
/dev/null
<<<
"na"
)
"
\
req_test_eq
"
$(
echo
"
$(
bashopts_process_option
-n
value
-k
is_eq_to_null
-r
2>&1
>
/dev/null
<<<
"na"
)
"
\
|
grep
'^\[ERR'
|
tail
-n
1
||
true
)
"
'[ERRO] Not equal to NULL'
|
grep
'^\[ERR'
|
tail
-n
1
||
true
)
"
'[ERRO] Not equal to NULL'
req_test_eq
"
$(
echo
"
$(
bashopts_process_option
-n
value
-k
is_eq_to_null
-r
2>&1
>
/dev/null
<<<
"()"
)
"
\
req_test_eq
"
$(
echo
"
$(
bashopts_process_option
-n
value
-k
is_eq_to_null
-r
2>&1
>
/dev/null
<<<
"()"
)
"
\
|
grep
'^\[ERR'
|
tail
-n
1
||
true
)
"
'[ERRO] At least one value required'
|
grep
'^\[ERR'
|
tail
-n
1
||
true
)
"
'[ERRO]
Option value:
At least one value required'
bashopts_process_option
-n
value
-k
is_eq_to_null
-r
>
/dev/null 2>&1
<<<
"NULL"
bashopts_process_option
-n
value
-k
is_eq_to_null
-r
>
/dev/null 2>&1
<<<
"NULL"
}
}
...
@@ -322,7 +293,7 @@ _test_case_21() {
...
@@ -322,7 +293,7 @@ _test_case_21() {
bashopts_parse_args
-n
bashopts_parse_args
-n
bashopts_process_opts
bashopts_process_opts
req_test_eq
"
$(
echo
"
$(
bashopts_process_option
-n
value
-k
is_not_empty
-r
2>&1
>
/dev/null
)
"
\
req_test_eq
"
$(
echo
"
$(
bashopts_process_option
-n
value
-k
is_not_empty
-r
2>&1
>
/dev/null
)
"
\
|
grep
'^\[ERR'
|
head
-n
1
)
"
'[ERRO] At least one value required'
|
grep
'^\[ERR'
|
head
-n
1
)
"
'[ERRO]
Option value:
At least one value required'
}
}
_test_case_22
()
{
_test_case_22
()
{
...
@@ -351,9 +322,10 @@ _test_case_24() {
...
@@ -351,9 +322,10 @@ _test_case_24() {
bashopts_parse_args
bashopts_parse_args
bashopts_process_opts
bashopts_process_opts
# NOTE: Fix answer again after a is_eq_to_null check failure
# NOTE: Fix answer again after a is_eq_to_null check failure
req_test_eq
"
$(
(
bashopts_process_option
-n
value
-k
is_eq_to_null
-r
2>&1
<<<
"NUL"
\
req_test_eq
"
$(
(
bashopts_process_option
-n
value
-k
is_eq_to_null
-r
2>&1
<<<
"NUL"
\
||
true
)
|
grep
-E
'^* A str value$'
|
wc
-l
)
"
"2"
||
true
)
|
grep
'^* A str value$'
|
wc
-l
)
"
"2"
}
}
_test_case_25
()
{
_test_case_25
()
{
...
@@ -362,7 +334,7 @@ _test_case_25() {
...
@@ -362,7 +334,7 @@ _test_case_25() {
bashopts_declare
-n
value
-l
value
-d
"A str value"
-t
string
-r
bashopts_declare
-n
value
-l
value
-d
"A str value"
-t
string
-r
req_test_eq
"
$(
(
bashopts_process_opts 2>&1
<<<
""
\
req_test_eq
"
$(
(
bashopts_process_opts 2>&1
<<<
""
\
||
true
)
|
grep
-E
'^* A str value$'
|
wc
-l
)
"
"2"
||
true
)
|
grep
'^* A str value$'
|
wc
-l
)
"
"2"
}
}
_test_case_26
()
{
_test_case_26
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment