public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [RFC PATCH 1/1] Add automated tests for shell lib
Date: Wed, 3 Oct 2018 12:46:20 +0200	[thread overview]
Message-ID: <20181003104620.GA21139@dell5510> (raw)
In-Reply-To: <20181003095107.GD23398@rei>

Hi,

> > +do_test()
> > +{
> > +	tst_res TPASS "Test $1 passed with data '$2': a: '$ALTERNATIVE', f: '$MODE'"
> > +}
> > +
> > +tst_run
> > +# output:
> > +# test 1 TPASS: Test 1 passed with data '': a: '0', f: 'foo'
> > +# 
> > +# Summary:
> > +# passed   1
> > +# failed   0
> > +# skipped  0
> > +# warnings 0

> We do need a way how to pass parameters to the tests so that we can test
> this functionality properly (and also the default options that are
> implemented in the test library).

> Obvious way how to do this is to allow to have several output: blocks at
> the end of the test with a different parameters, something as:

> # output:
> # test 1 TPASS: Test 1 passed with data '': a: '0', f: 'foo'

> # Summary:
> # passed   1
> # failed   0
> # skipped  0
> # warnings 0

> # output:
> # params: -a
> # test 1 TPASS: Test 1 passed with data '': a: '1', f: 'foo'

> # Summary:
> # passed   1
> # failed   0
> # skipped  0
> # warnings 0

> ...

Good idea!

...
> > +verify_output()
> > +{
> > +	[ -e "$sh_lib_tst_dir$tst" ] || { printf "$tst not found\n" && \
> > +			cleanup 1 ;}
> > +	# read all lines after line: `# output:`, and strip `# ` from beginning
> > +	sed -n -e '/^# output:/,$ p;' "$sh_lib_tst_dir$tst" | sed '1d; s/^# //'\
> > +			> "$tmp_dir$tst.wanted" || cleanup 1

> Usually doing more complex text manipulation is easier with awk

> In this case you can use gsub() function that will replace substring and
> print all lines that were replaced (i.e. print all comments without the
> hash and space):

> awk 'gsub("^# ", "", $0)' script.sh

> Then you can even get one of the output: blocks with:

> awk -vb=1 'gsub("^# ", "", $0) {if (/output:/) {p++}; if (p==b && !/output:/) {print $0}};' script.sh
>        ^
>        This gives you content of comments starting at first # output:
>        line up to the next # output: or end of line, which is exactly
>        what we need if we want to support passing parameters to
>        testcases. Then we can simply count how many # output: lines are
>        in a file and then run this command in a loop extracting one
>        example output after another.
I wonder whether "extracting one example output after another" is still good to
do in awk/sed/shell (with simple readable code). Probably yes, but I wouldn't
mind to have either python (pytest) or some perl code doing it.
Awk is everywhere and definitely more capable than sed or even shell, but not
everybody is fluent in it.


Kind regards,
Petr

  reply	other threads:[~2018-10-03 10:46 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-22 19:34 [LTP] [RFC PATCH v3 1/2] tst_test.sh: Add TST_TEST_DATA and TST_TEST_DATA_IFS Petr Vorel
2018-05-22 19:34 ` [LTP] [RFC PATCH v3 2/2] lib: Add tests Petr Vorel
2018-05-24 13:46   ` Cyril Hrubis
2018-05-24 14:00     ` Petr Vorel
2018-08-28 11:18   ` [LTP] [PATCH 1/2] Make shell lib tests standalone Christian Lanig
2018-08-28 11:18     ` [LTP] [PATCH 2/2] Add wanted output to shell lib test case Christian Lanig
2018-08-29 17:24     ` [LTP] [PATCH 1/2] Make shell lib tests standalone Petr Vorel
2018-08-29 17:30       ` Petr Vorel
2018-08-31 15:24       ` [LTP] [RFC PATCH 0/1] Add automated tests for shell lib Christian Lanig
2018-08-31 15:24         ` [LTP] [RFC PATCH 1/1] " Christian Lanig
2018-10-03  9:51           ` Cyril Hrubis
2018-10-03 10:46             ` Petr Vorel [this message]
2018-10-03 11:32           ` Petr Vorel
2019-08-22 19:12             ` [LTP] [RFC PATCH v2 0/1] " Christian Lanig
2019-08-22 19:12               ` [LTP] [RFC PATCH v2 1/1] " Christian Lanig
2019-09-19 16:41                 ` Petr Vorel
2019-09-30 18:27                   ` Christian Lanig
2019-09-20 14:21                 ` Clemens Famulla-Conrad
2019-09-19 14:26               ` [LTP] [RFC PATCH v2 0/1] " Petr Vorel
2018-08-31 11:46     ` [LTP] [PATCH 1/2] Make shell lib tests standalone Cyril Hrubis
2018-05-24 13:41 ` [LTP] [RFC PATCH v3 1/2] tst_test.sh: Add TST_TEST_DATA and TST_TEST_DATA_IFS Cyril Hrubis
2018-05-24 13:53   ` Petr Vorel
2018-05-24 14:00     ` Cyril Hrubis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181003104620.GA21139@dell5510 \
    --to=pvorel@suse.cz \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox