kopia lustrzana https://github.com/weetmuts/wmbusmeters
Add tests for cmdline.
rodzic
9b77efbc89
commit
0184dfa88a
|
@ -0,0 +1 @@
|
||||||
|
telegram=|2A442D2C998734761B168D2091D37CAC21576C78_02FF207100041308190000441308190000615B7F616713|
|
|
@ -796,16 +796,16 @@ shared_ptr<Configuration> parseCommandLineWithUseConfig(Configuration *c, int ar
|
||||||
c->pid_file = argv[i];
|
c->pid_file = argv[i];
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
if (i+1 < argc)
|
if (i < argc)
|
||||||
{
|
{
|
||||||
error("Usage error: you must supply the pid file as the last argument to wmbusmetersd.\n");
|
error("Usage error: you must supply the pid file as the last argument to wmbusmetersd.\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (i+1 < argc)
|
if (i < argc)
|
||||||
{
|
{
|
||||||
error("Usage error: too many arguments \"%s\".\n", argv[i]);
|
error("Usage error: too many arguments \"%s\" with --useconfig=...\n", argv[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return shared_ptr<Configuration>(c);
|
return shared_ptr<Configuration>(c);
|
||||||
|
|
3
test.sh
3
test.sh
|
@ -99,6 +99,9 @@ if [ "$?" != "0" ]; then RC="1"; fi
|
||||||
tests/test_linkmodes.sh $PROG
|
tests/test_linkmodes.sh $PROG
|
||||||
if [ "$?" != "0" ]; then RC="1"; fi
|
if [ "$?" != "0" ]; then RC="1"; fi
|
||||||
|
|
||||||
|
tests/test_cmdline.sh $PROG
|
||||||
|
if [ "$?" != "0" ]; then RC="1"; fi
|
||||||
|
|
||||||
tests/test_additional_json.sh $PROG
|
tests/test_additional_json.sh $PROG
|
||||||
if [ "$?" != "0" ]; then RC="1"; fi
|
if [ "$?" != "0" ]; then RC="1"; fi
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,114 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
PROG="$1"
|
||||||
|
TEST=testoutput
|
||||||
|
mkdir -p $TEST
|
||||||
|
|
||||||
|
TESTNAME="Test cmdline --overridedevice and --useconfig"
|
||||||
|
TESTRESULT="ERROR"
|
||||||
|
|
||||||
|
$PROG --overridedevice=simulations/simulation_single_telegram.txt --useconfig=tests/config12 > $TEST/test_output.txt 2> $TEST/test_stderr.txt
|
||||||
|
|
||||||
|
if [ "$?" = "0" ]
|
||||||
|
then
|
||||||
|
echo 6.408 > $TEST/test_expected.txt
|
||||||
|
diff $TEST/test_expected.txt $TEST/test_output.txt
|
||||||
|
if [ "$?" = "0" ]
|
||||||
|
then
|
||||||
|
echo "OK: $TESTNAME"
|
||||||
|
TESTRESULT="OK"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$TESTRESULT" = "ERROR" ]; then echo ERROR: $TESTNAME; exit 1; fi
|
||||||
|
|
||||||
|
TESTNAME="Test cmdline --overridedevice without --useconfig"
|
||||||
|
TESTRESULT="ERROR"
|
||||||
|
|
||||||
|
$PROG --overridedevice=rtlwmbus > $TEST/test_output.txt 2>&1
|
||||||
|
|
||||||
|
if [ "$?" != "0" ]
|
||||||
|
then
|
||||||
|
echo "You can only use --overridedevice=xyz with --useconfig=xyz" > $TEST/test_expected.txt
|
||||||
|
diff $TEST/test_expected.txt $TEST/test_output.txt
|
||||||
|
if [ "$?" = "0" ]
|
||||||
|
then
|
||||||
|
echo "OK: $TESTNAME"
|
||||||
|
TESTRESULT="OK"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$TESTRESULT" = "ERROR" ]; then echo ERROR: $TESTNAME; exit 1; fi
|
||||||
|
|
||||||
|
|
||||||
|
TESTNAME="Test cmdline --overridedevice with --useconfig and surplus argument"
|
||||||
|
TESTRESULT="ERROR"
|
||||||
|
|
||||||
|
$PROG --overridedevice=rtlwmbus --useconfig=tests/config12 gurka > $TEST/test_output.txt 2>&1
|
||||||
|
|
||||||
|
if [ "$?" != "0" ]
|
||||||
|
then
|
||||||
|
echo "Usage error: too many arguments \"gurka\" with --useconfig=..." > $TEST/test_expected.txt
|
||||||
|
diff $TEST/test_expected.txt $TEST/test_output.txt
|
||||||
|
if [ "$?" = "0" ]
|
||||||
|
then
|
||||||
|
echo "OK: $TESTNAME"
|
||||||
|
TESTRESULT="OK"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$TESTRESULT" = "ERROR" ]; then echo ERROR: $TESTNAME; exit 1; fi
|
||||||
|
|
||||||
|
TESTNAME="Test cmdline --overridedevice with --useconfig and surplus arguments"
|
||||||
|
TESTRESULT="ERROR"
|
||||||
|
|
||||||
|
$PROG --overridedevice=rtlwmbus --useconfig=tests/config12 gurka banan > $TEST/test_output.txt 2>&1
|
||||||
|
|
||||||
|
if [ "$?" != "0" ]
|
||||||
|
then
|
||||||
|
echo "Usage error: too many arguments \"gurka\" with --useconfig=..." > $TEST/test_expected.txt
|
||||||
|
diff $TEST/test_expected.txt $TEST/test_output.txt
|
||||||
|
if [ "$?" = "0" ]
|
||||||
|
then
|
||||||
|
echo "OK: $TESTNAME"
|
||||||
|
TESTRESULT="OK"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$TESTRESULT" = "ERROR" ]; then echo ERROR: $TESTNAME; exit 1; fi
|
||||||
|
|
||||||
|
TESTNAME="Test cmdline --overridedevice with --useconfig and surplus argument prefixed"
|
||||||
|
TESTRESULT="ERROR"
|
||||||
|
|
||||||
|
$PROG banan --overridedevice=rtlwmbus --useconfig=tests/config12 > $TEST/test_output.txt 2>&1
|
||||||
|
|
||||||
|
if [ "$?" != "0" ]
|
||||||
|
then
|
||||||
|
echo "Usage error: too many arguments \"banan\" with --useconfig=..." > $TEST/test_expected.txt
|
||||||
|
diff $TEST/test_expected.txt $TEST/test_output.txt
|
||||||
|
if [ "$?" = "0" ]
|
||||||
|
then
|
||||||
|
echo "OK: $TESTNAME"
|
||||||
|
TESTRESULT="OK"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$TESTRESULT" = "ERROR" ]; then echo ERROR: $TESTNAME; exit 1; fi
|
||||||
|
|
||||||
|
TESTNAME="Test cmdline --overridedevice with --useconfig and surplus argument infixed"
|
||||||
|
TESTRESULT="ERROR"
|
||||||
|
|
||||||
|
$PROG --overridedevice=rtlwmbus apple --useconfig=tests/config12 > $TEST/test_output.txt 2>&1
|
||||||
|
|
||||||
|
if [ "$?" != "0" ]
|
||||||
|
then
|
||||||
|
echo "Usage error: too many arguments \"apple\" with --useconfig=..." > $TEST/test_expected.txt
|
||||||
|
diff $TEST/test_expected.txt $TEST/test_output.txt
|
||||||
|
if [ "$?" = "0" ]
|
||||||
|
then
|
||||||
|
echo "OK: $TESTNAME"
|
||||||
|
TESTRESULT="OK"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$TESTRESULT" = "ERROR" ]; then echo ERROR: $TESTNAME; exit 1; fi
|
Ładowanie…
Reference in New Issue