[LTP] [PATCH v2 4/4] doc: Update shell API examples
Petr Vorel
pvorel@suse.cz
Fri Apr 22 16:41:41 CEST 2022
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
Changes v1->v2:
* Updates related to 1st and 2nd commit.
doc/library-api-writing-guidelines.txt | 11 +++++++----
doc/shell-test-api.txt | 8 ++++++++
2 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/doc/library-api-writing-guidelines.txt b/doc/library-api-writing-guidelines.txt
index 9e926e9713..06b617e693 100644
--- a/doc/library-api-writing-guidelines.txt
+++ b/doc/library-api-writing-guidelines.txt
@@ -67,17 +67,20 @@ Changes in the shell API should not introduce uncommon dependencies
Besides shell API libraries in 'testcases/lib' it's worth to put common code
for particular tests into shell library. The filename should end '_lib.sh',
-they should load 'tst_test.sh' or 'tst_net.sh'.
+they should load 'tst_test.sh' or 'tst_net.sh' at the end of the file.
Shell libraries should have conditional expansion for 'TST_SETUP' or 'TST_CLEANUP',
to avoid surprises when test specific setup/cleanup function is redefined by
-shell library.
+shell library. Although there is not an optimal general solution because
+usually test which have specific setup/cleanup also needs to call library
+setup/cleanup, but it's better not to require 'TST_SETUP' or 'TST_CLEANUP' to
+be on specific place.
[source,sh]
-------------------------------------------------------------------------------
# ipsec_lib.sh
# SPDX-License-Identifier: GPL-2.0-or-later
-TST_SETUP=${TST_SETUP:-ipsec_lib_setup}
-. tst_test.sh
+TST_SETUP="${TST_SETUP:-ipsec_lib_setup}"
...
+. tst_test.sh
-------------------------------------------------------------------------------
diff --git a/doc/shell-test-api.txt b/doc/shell-test-api.txt
index 4c16f36250..df5ebbdf0d 100644
--- a/doc/shell-test-api.txt
+++ b/doc/shell-test-api.txt
@@ -40,6 +40,7 @@ do_test()
fi
}
+. tst_test.sh
tst_run
-------------------------------------------------------------------------------
@@ -90,6 +91,7 @@ test2()
tst_res TPASS "Test $1 passed"
}
+. tst_test.sh
tst_run
# output:
# foo 1 TPASS: Test 1 passed
@@ -118,6 +120,7 @@ do_test()
esac
}
+. tst_test.sh
tst_run
# output:
# foo 1 TPASS: Test 1 passed
@@ -145,6 +148,7 @@ do_test()
tst_res TPASS "Test $1 passed with data '$2'"
}
+. tst_test.sh
tst_run
# output:
# foo 1 TPASS: Test 1 passed with data 'foo'
@@ -174,6 +178,7 @@ do_test()
esac
}
+. tst_test.sh
tst_run
# output:
# foo 1 TPASS: Test 1 passed with data 'foo'
@@ -278,6 +283,7 @@ do_test()
...
}
+. tst_test.sh
tst_run
-------------------------------------------------------------------------------
@@ -337,6 +343,7 @@ do_test()
...
}
+. tst_test.sh
tst_run
-------------------------------------------------------------------------------
@@ -379,6 +386,7 @@ do_test()
...
}
+. tst_test.sh
tst_run
-------------------------------------------------------------------------------
--
2.35.3
More information about the ltp
mailing list