Skip to content

Commit

Permalink
tst_test.sh: TCONF on basename error when setting TST_ID
Browse files Browse the repository at this point in the history
'basename $0' fails when loaded in command line with bash (at least)
as $0 is invalid ('-bash'):

    $ unset TST_ID; export TST_NO_DEFAULT_RUN=1; . tst_test.sh
    -bash: tst_ansi_color.sh: No such file or directory
    basename: invalid option -- 'b'
    Try 'basename --help' for more information.

It's better to TCONF than be without TST_ID.

NOTE: Sourcing tst_test.sh can be needed for network scripts: users
might want to set network variables with tst_net.sh, which itself
sources tst_test.sh.

Reviewed-by: Li Wang <liwang@redhat.com>
Signed-off-by: Petr Vorel <pvorel@suse.cz>
  • Loading branch information
pevik committed Jun 1, 2018
1 parent a936709 commit 298a984
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion testcases/lib/tst_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,8 @@ tst_run()
}

if [ -z "$TST_ID" ]; then
filename=$(basename $0)
filename=$(basename $0) || \
tst_brk TCONF "Failed to set TST_ID from \$0 ('$0'), fix it with setting TST_ID before sourcing tst_test.sh"
TST_ID=${filename%%.*}
fi
export TST_ID="$TST_ID"
Expand Down

0 comments on commit 298a984

Please sign in to comment.