Import LinuxCNC source tree
This commit is contained in:
5
tests/inifile/README
Normal file
5
tests/inifile/README
Normal file
@@ -0,0 +1,5 @@
|
||||
Tests for the library `liblinuxcncini.so.1`.
|
||||
|
||||
This is the library created from the files `src/emc/ini/inifile.*`.
|
||||
The application `inivar` is used for compatibility. The new utility
|
||||
`inivalue` is tested in a separate extensive test script.
|
||||
4
tests/inifile/comments/README
Normal file
4
tests/inifile/comments/README
Normal file
@@ -0,0 +1,4 @@
|
||||
Test the INI parser with regards to comments, both inline and on it's own line.
|
||||
|
||||
After 2.7.x, the INI parser in LinuxCNC does not support inline comments.
|
||||
See: https://github.com/LinuxCNC/linuxcnc/issues/991
|
||||
4
tests/inifile/comments/expected
Normal file
4
tests/inifile/comments/expected
Normal file
@@ -0,0 +1,4 @@
|
||||
value1
|
||||
value2 ; inline not comment
|
||||
value3
|
||||
value4 # another inline not comment
|
||||
6
tests/inifile/comments/test.sh
Executable file
6
tests/inifile/comments/test.sh
Executable file
@@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
inivar -ini with_comments.ini -var key1
|
||||
inivar -ini with_comments.ini -var key2
|
||||
inivar -ini with_comments.ini -var key3
|
||||
inivar -ini with_comments.ini -var key4
|
||||
8
tests/inifile/comments/with_comments.ini
Normal file
8
tests/inifile/comments/with_comments.ini
Normal file
@@ -0,0 +1,8 @@
|
||||
; This is a comment
|
||||
[section1]
|
||||
key1=value1
|
||||
; Another comment
|
||||
key2=value2 ; inline not comment
|
||||
# different comment style
|
||||
key3=value3
|
||||
key4=value4 # another inline not comment
|
||||
7
tests/inifile/continuation_lines/continuation_lines.ini
Normal file
7
tests/inifile/continuation_lines/continuation_lines.ini
Normal file
@@ -0,0 +1,7 @@
|
||||
[section1]
|
||||
key1=value1
|
||||
key2=value2 \
|
||||
value3 \
|
||||
value4 \
|
||||
value5
|
||||
key3=value6
|
||||
1
tests/inifile/continuation_lines/expected
Normal file
1
tests/inifile/continuation_lines/expected
Normal file
@@ -0,0 +1 @@
|
||||
value2 value3 value4 value5
|
||||
3
tests/inifile/continuation_lines/test.sh
Executable file
3
tests/inifile/continuation_lines/test.sh
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
inivar -ini continuation_lines.ini -var key2
|
||||
7
tests/inifile/duplicated_keys/duplicated_keys.ini
Normal file
7
tests/inifile/duplicated_keys/duplicated_keys.ini
Normal file
@@ -0,0 +1,7 @@
|
||||
[section1]
|
||||
key1=value1
|
||||
key1=value2
|
||||
|
||||
[section2]
|
||||
key1=value3
|
||||
key1=value4
|
||||
4
tests/inifile/duplicated_keys/expected
Normal file
4
tests/inifile/duplicated_keys/expected
Normal file
@@ -0,0 +1,4 @@
|
||||
value1
|
||||
value1
|
||||
value4
|
||||
value3
|
||||
6
tests/inifile/duplicated_keys/test.sh
Executable file
6
tests/inifile/duplicated_keys/test.sh
Executable file
@@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
inivar -ini duplicated_keys.ini -var key1
|
||||
inivar -ini duplicated_keys.ini -var key1 -sec section1 -num 1
|
||||
inivar -ini duplicated_keys.ini -var key1 -sec section2 -num 2
|
||||
inivar -ini duplicated_keys.ini -var key1 -num 3
|
||||
82
tests/inifile/ini_api_c/expected
Normal file
82
tests/inifile/ini_api_c/expected
Normal file
@@ -0,0 +1,82 @@
|
||||
+++ Running test program for 'initest' +++
|
||||
--- test integer/unsigned value
|
||||
42
|
||||
-42
|
||||
42
|
||||
xtest.ini:7: warning: Unsigned integer conversion detected a leading minus sign (-)
|
||||
18446744073709551574
|
||||
42
|
||||
-42
|
||||
42
|
||||
-42
|
||||
42
|
||||
xtest.ini:8: warning: Unsigned integer conversion detected a leading minus sign (-)
|
||||
18446744073709551574
|
||||
42
|
||||
-42
|
||||
42
|
||||
-42
|
||||
42
|
||||
xtest.ini:9: warning: Unsigned integer conversion detected a leading minus sign (-)
|
||||
18446744073709551574
|
||||
42
|
||||
-42
|
||||
42
|
||||
-42
|
||||
42
|
||||
xtest.ini:10: warning: Unsigned integer conversion detected a leading minus sign (-)
|
||||
18446744073709551574
|
||||
42
|
||||
-42
|
||||
--- test real value
|
||||
42
|
||||
-42
|
||||
--- test boolean value
|
||||
true
|
||||
false
|
||||
true
|
||||
false
|
||||
true
|
||||
false
|
||||
true
|
||||
false
|
||||
true
|
||||
false
|
||||
true
|
||||
false
|
||||
true
|
||||
false
|
||||
--- test bad integer/unsigned value
|
||||
xtest.ini:14: error: Invalid signed integer [SECTION]VARBadNum='BadInt42'
|
||||
iniFindSInt: Entry not found
|
||||
xtest.ini:14: error: Invalid unsigned integer [SECTION]VARBadNum='BadInt42'
|
||||
iniFindUInt: Entry not found
|
||||
xtest.ini:14: error: Invalid floating point [SECTION]VARBadNum='BadInt42'
|
||||
iniFindDouble: Entry not found
|
||||
--- test warn integer/unsigned trailing context
|
||||
xtest.ini:15: warning: Trailing character(s) in signed integer conversion ([SECTION]VARWarnNum='42Warn')
|
||||
42
|
||||
xtest.ini:15: warning: Trailing character(s) in unsigned integer conversion ([SECTION]VARWarnNum='42Warn')
|
||||
42
|
||||
xtest.ini:15: warning: Trailing character(s) in floating point conversion ([SECTION]VARWarnNum='42Warn')
|
||||
42
|
||||
--- test bad boolean value
|
||||
xtest.ini:13: error: Invalid boolean value [SECTION]VARBadBool='BadBool'
|
||||
iniFindBool: Entry not found
|
||||
--- test string value
|
||||
BadInt42
|
||||
42Warn
|
||||
--- test missing value
|
||||
iniFindString: Entry not found
|
||||
iniFindSInt: Entry not found
|
||||
iniFindUInt: Entry not found
|
||||
iniFindBool: Entry not found
|
||||
iniFindInt: Entry not found
|
||||
--- test missing section
|
||||
value to check the rest is missing
|
||||
iniFindString: Entry not found
|
||||
iniFindSInt: Entry not found
|
||||
iniFindUInt: Entry not found
|
||||
iniFindBool: Entry not found
|
||||
iniFindInt: Entry not found
|
||||
+++ all done +++
|
||||
136
tests/inifile/ini_api_c/initest.c
Normal file
136
tests/inifile/ini_api_c/initest.c
Normal file
@@ -0,0 +1,136 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <getopt.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <inifile.h>
|
||||
|
||||
void myerror(const char *pfx, int err)
|
||||
{
|
||||
fprintf(stderr, "%s: ", pfx);
|
||||
switch(err) {
|
||||
case -EINVAL: fprintf(stderr, "Invalid argument or ini-file"); break;
|
||||
case -ENOSPC: fprintf(stderr, "Buffer too small"); break;
|
||||
case -ENOENT: fprintf(stderr, "Entry not found"); break;
|
||||
default: fprintf(stderr, "Unknown error: %d", err); break;
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int lose = 0;
|
||||
int optc;
|
||||
const char *var = NULL;
|
||||
const char *sec = NULL;
|
||||
char typ = 's';
|
||||
|
||||
while(-1 != (optc = getopt(argc, argv, "v:s:t:"))) {
|
||||
switch(optc) {
|
||||
case 'v':
|
||||
var = strdup(optarg);
|
||||
break;
|
||||
case 's':
|
||||
sec = strdup(optarg);
|
||||
break;
|
||||
case 't':
|
||||
switch(*optarg) {
|
||||
case 'b':
|
||||
case 'i':
|
||||
case 'n':
|
||||
case 'u':
|
||||
case 'r':
|
||||
case 's':
|
||||
typ = *optarg;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Invalid type specifier '%c'\n", isprint(*optarg & 0xff) ? *optarg : '?');
|
||||
lose++;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
lose++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(optind >= argc) {
|
||||
fprintf(stderr, "Missing ini file\n");
|
||||
lose++;
|
||||
}
|
||||
|
||||
if(lose)
|
||||
return 1;
|
||||
|
||||
int rv;
|
||||
char buf[PATH_MAX];
|
||||
double r;
|
||||
int n;
|
||||
rtapi_s64 i;
|
||||
rtapi_u64 u;
|
||||
bool b;
|
||||
|
||||
switch(typ) {
|
||||
case 'b':
|
||||
rv = iniFindBool(argv[optind], var, sec, &b);
|
||||
if(!rv) {
|
||||
printf("%s\n", b ? "true" : "false");
|
||||
} else {
|
||||
myerror("iniFindBool", rv);
|
||||
return -rv;
|
||||
}
|
||||
break;
|
||||
case 'n':
|
||||
rv = iniFindInt(argv[optind], var, sec, &n);
|
||||
if(!rv) {
|
||||
printf("%d\n", n);
|
||||
} else {
|
||||
myerror("iniFindInt", rv);
|
||||
return -rv;
|
||||
}
|
||||
break;
|
||||
case 'i':
|
||||
rv = iniFindSInt(argv[optind], var, sec, &i);
|
||||
if(!rv) {
|
||||
printf("%ld\n", i);
|
||||
} else {
|
||||
myerror("iniFindSInt", rv);
|
||||
return -rv;
|
||||
}
|
||||
break;
|
||||
case 'u':
|
||||
rv = iniFindUInt(argv[optind], var, sec, &u);
|
||||
if(!rv) {
|
||||
printf("%lu\n", u);
|
||||
} else {
|
||||
myerror("iniFindUInt", rv);
|
||||
return -rv;
|
||||
}
|
||||
break;
|
||||
case 'r':
|
||||
rv = iniFindDouble(argv[optind], var, sec, &r);
|
||||
if(!rv) {
|
||||
printf("%.15lg\n", r);
|
||||
} else {
|
||||
myerror("iniFindDouble", rv);
|
||||
return -rv;
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
rv = iniFindString(argv[optind], var, sec, buf, sizeof(buf));
|
||||
if(!rv) {
|
||||
printf("%s\n", buf);
|
||||
} else {
|
||||
myerror("iniFindString", rv);
|
||||
return -rv;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// vim: ts=4 sw=4
|
||||
95
tests/inifile/ini_api_c/test.sh
Executable file
95
tests/inifile/ini_api_c/test.sh
Executable file
@@ -0,0 +1,95 @@
|
||||
#!/bin/bash
|
||||
FLGS=( -O2 -Wall -Wextra -Werror -I"${HEADERS}" -DULAPI -L"${LIBDIR}" )
|
||||
gcc "${FLGS[@]}" -o initest initest.c -llinuxcncini || { echo "Failed compile"; exit 1; }
|
||||
|
||||
[ -x ./initest ] || { echo "initest program not present or executable"; exit 1; }
|
||||
|
||||
r() { echo "$@" >> result; }
|
||||
f() { echo "***" "$@" "failed" >> result; }
|
||||
t() { echo "***" "$@" "did not fail" >> result; }
|
||||
tst() { ./initest "$@" xtest.ini >> result 2>&1; }
|
||||
|
||||
true > result
|
||||
r "+++ Running test program for 'initest' +++"
|
||||
|
||||
( echo "[SECTION]"
|
||||
echo "VAR=value to check the rest is missing"
|
||||
echo "VARdp=42"
|
||||
echo "VARxp=0x2a"
|
||||
echo "VARop=0o52"
|
||||
echo "VARbp=0b101010"
|
||||
echo "VARdm=-42"
|
||||
echo "VARxm=-0x2a"
|
||||
echo "VARom=-0o52"
|
||||
echo "VARbm=-0b101010"
|
||||
echo "VARrp=+4.2e1"
|
||||
echo "VARrm=-4.2e1"
|
||||
echo "VARBadBool=BadBool"
|
||||
echo "VARBadNum=BadInt42"
|
||||
echo "VARWarnNum=42Warn"
|
||||
echo "VARBt1=TRUE"
|
||||
echo "VARBt2=true"
|
||||
echo "VARBt3=True"
|
||||
echo "VARBt4=yes"
|
||||
echo "VARBt5=YeS"
|
||||
echo "VARBt6=1"
|
||||
echo "VARBt7=oN"
|
||||
echo "VARBf1=FALSE"
|
||||
echo "VARBf2=false"
|
||||
echo "VARBf3=FalSe"
|
||||
echo "VARBf4=no"
|
||||
echo "VARBf5=nO"
|
||||
echo "VARBf6=0"
|
||||
echo "VARBf7=oFf" ) > xtest.ini
|
||||
r "--- test integer/unsigned value"
|
||||
for i in d x o b; do
|
||||
tst -v"VAR${i}p" -ti || f "Integer VAR${i}p variable"
|
||||
tst -v"VAR${i}m" -ti || f "Integer VAR${i}m variable"
|
||||
tst -v"VAR${i}p" -tu || f "Unsigned VAR${i}p variable"
|
||||
tst -v"VAR${i}m" -tu || f "Unsigned VAR${i}m variable"
|
||||
tst -v"VAR${i}p" -tn || f "Integer VAR${i}p variable"
|
||||
tst -v"VAR${i}m" -tn || f "Integer VAR${i}m variable"
|
||||
done
|
||||
r "--- test real value"
|
||||
tst -vVARrp -tr || f "Real variable"
|
||||
tst -vVARrm -tr || f "Real variable"
|
||||
r "--- test boolean value"
|
||||
for i in 1 2 3 4 5 6 7; do
|
||||
tst -v"VARBt${i}" -tb || f "Boolean variable VARBt${i}"
|
||||
tst -v"VARBf${i}" -tb || f "Boolean variable VARBf${i}"
|
||||
done
|
||||
|
||||
r "--- test bad integer/unsigned value"
|
||||
tst -v"VARBadNum" -ti && t "Bad integer VARBadNum"
|
||||
tst -v"VARBadNum" -tu && t "Bad unsigned VARBadNum"
|
||||
tst -v"VARBadNum" -tr && t "Bad real VARBadNum"
|
||||
r "--- test warn integer/unsigned trailing context"
|
||||
tst -v"VARWarnNum" -ti || f "Bad integer VARWarnNum"
|
||||
tst -v"VARWarnNum" -tu || f "Bad unsigned VARWarnNum"
|
||||
tst -v"VARWarnNum" -tr || f "Bad real VARWarnNum"
|
||||
r "--- test bad boolean value"
|
||||
tst -v"VARBadBool" -tb && t "Bad boolean VARBadBool"
|
||||
|
||||
r "--- test string value"
|
||||
tst -v"VARBadNum" -ts || f "String VARBadNum"
|
||||
tst -v"VARWarnNum" -ts || f "String VARWarnNum"
|
||||
|
||||
r "--- test missing value"
|
||||
tst -v"MissingVAR" -ts && t "MissingVAR string"
|
||||
tst -v"MissingVAR" -ti && t "MissingVAR sint"
|
||||
tst -v"MissingVAR" -tu && t "MissingVAR uint"
|
||||
tst -v"MissingVAR" -tb && t "MissingVAR bool"
|
||||
tst -v"MissingVAR" -tn && t "MissingVAR int"
|
||||
|
||||
r "--- test missing section"
|
||||
tst -v"VAR" -s"SECTION" -ts || f "Section string"
|
||||
tst -v"VAR" -s"MISSING" -ts && t "Missing section string"
|
||||
tst -v"VAR" -s"MISSING" -ti && t "Missing section sint"
|
||||
tst -v"VAR" -s"MISSING" -tu && t "Missing section uint"
|
||||
tst -v"VAR" -s"MISSING" -tb && t "Missing section bool"
|
||||
tst -v"VAR" -s"MISSING" -tn && t "Missing section int"
|
||||
|
||||
r "+++ all done +++"
|
||||
|
||||
rm -f initest xtest.ini
|
||||
exit 0
|
||||
229
tests/inifile/inivalue/expected
Normal file
229
tests/inifile/inivalue/expected
Normal file
@@ -0,0 +1,229 @@
|
||||
+++ Running test program for 'inivalue' +++
|
||||
--- test ini-file does not exist
|
||||
this_file_does_not_exist_and_will_never_be_here.ini: error: Cannot open ini-file (errno=2 (No such file or directory))
|
||||
--- test missing include filename (without blank)
|
||||
xtest.ini:1: error: Missing filename after #INCLUDE
|
||||
--- test missing include filename (with blank)
|
||||
xtest.ini:1: error: Missing filename after #INCLUDE
|
||||
--- test include file not found
|
||||
this_file_does_not_exist.inc: error: Cannot open ini-file (errno=2 (No such file or directory))
|
||||
--- test include file recursion
|
||||
xtest.inc:1: error: Include file recursion on loading 'xtest.ini'
|
||||
--- test invalid section, missing ']'
|
||||
xtest.ini:1: error: Invalid section. Missing ']'
|
||||
--- test invalid section, no content
|
||||
xtest.ini:1: error: Invalid section. No content between '[' and ']'
|
||||
xtest.ini:1: error: Invalid section. No content between '[' and ']'
|
||||
--- test invalid section, invalid identifier
|
||||
xtest.ini:1: error: Invalid section '0SECTION'. Cannot start with a digit
|
||||
xtest.ini:1: error: Invalid section 'xæøåz'. Identifier contains invalid character(s)
|
||||
--- test duplicate section merge warning
|
||||
xtest.ini:2: warning: Section 'SECTION' already exists. Merging...
|
||||
val
|
||||
--- test section trailing junk warning
|
||||
xtest.ini:1: warning: Section header has trailing content, ignored
|
||||
val
|
||||
--- test invalid variable name missing '='
|
||||
xtest.ini:2: error: Invalid tag 'VAR'. Expected '=' after tag identifier
|
||||
--- test invalid variable name missing identifier
|
||||
xtest.ini:2: error: Invalid tag. Missing identifier before '='
|
||||
--- test invalid variable name missing '='
|
||||
xtest.ini:2: error: Invalid tag 'VAR x'. Expected '=' after tag identifier
|
||||
--- test invalid variable name identifier
|
||||
xtest.ini:2: error: Invalid tag '0VAR'. Tag identifiers cannot start with a digit
|
||||
xtest.ini:2: error: Invalid tag name 'VÅR'. Identifier contains invalid character(s)
|
||||
xtest.ini:2: error: Invalid tag name 'VAR x'. Identifier contains invalid character(s)
|
||||
--- test invalid variable outside section
|
||||
xtest.ini:1: error: Tag 'VAR' found without prior section definition
|
||||
--- test continuation
|
||||
val more val
|
||||
--- test last line has continuation without newline
|
||||
xtest.ini:2: error: Last line has a continuation
|
||||
--- test last line has continuation with newline
|
||||
xtest.ini:2: error: Last line has a continuation
|
||||
--- test getting all sections
|
||||
S1
|
||||
S2
|
||||
S3
|
||||
--- test get all variable of a name
|
||||
s1
|
||||
s2a
|
||||
s2b
|
||||
s2c
|
||||
s3
|
||||
--- test get all variable of a name from the 3'rd
|
||||
s2b
|
||||
s2c
|
||||
s3
|
||||
--- test get all variable of a name from unexisting number
|
||||
error: No instance 42 or more of '[]VAR'
|
||||
--- test get the 2'nd variable of global name VAR
|
||||
s2a
|
||||
--- test get the 2'nd variable of name VAR in section
|
||||
s2b
|
||||
--- test get the unexisting number variable of name VAR in section
|
||||
error: Cannot find instance 42 of '[S2]VAR'
|
||||
--- test integer/unsigned value
|
||||
42
|
||||
-42
|
||||
42
|
||||
xtest.ini:6: warning: Unsigned integer conversion detected a leading minus sign (-)
|
||||
18446744073709551574
|
||||
42
|
||||
-42
|
||||
42
|
||||
xtest.ini:7: warning: Unsigned integer conversion detected a leading minus sign (-)
|
||||
18446744073709551574
|
||||
42
|
||||
-42
|
||||
42
|
||||
xtest.ini:8: warning: Unsigned integer conversion detected a leading minus sign (-)
|
||||
18446744073709551574
|
||||
42
|
||||
-42
|
||||
42
|
||||
xtest.ini:9: warning: Unsigned integer conversion detected a leading minus sign (-)
|
||||
18446744073709551574
|
||||
--- test real value
|
||||
4.200000000000000e+01
|
||||
-4.200000000000000e+01
|
||||
--- test boolean value
|
||||
true
|
||||
false
|
||||
1
|
||||
0
|
||||
True
|
||||
False
|
||||
true
|
||||
false
|
||||
1
|
||||
0
|
||||
True
|
||||
False
|
||||
true
|
||||
false
|
||||
1
|
||||
0
|
||||
True
|
||||
False
|
||||
true
|
||||
false
|
||||
1
|
||||
0
|
||||
True
|
||||
False
|
||||
true
|
||||
false
|
||||
1
|
||||
0
|
||||
True
|
||||
False
|
||||
true
|
||||
false
|
||||
1
|
||||
0
|
||||
True
|
||||
False
|
||||
true
|
||||
false
|
||||
1
|
||||
0
|
||||
True
|
||||
False
|
||||
--- test bad integer/unsigned value
|
||||
xtest.ini:13: error: Invalid signed integer [SECTION]VARBadNum='BadInt42'
|
||||
error: Invalid integer []VARBadNum='BadInt42' or out of range [-9223372036854775808,9223372036854775807]
|
||||
xtest.ini:13: error: Invalid unsigned integer [SECTION]VARBadNum='BadInt42'
|
||||
error: Invalid unsigned []VARBadNum='BadInt42' or out of range [0,18446744073709551615]
|
||||
xtest.ini:13: error: Invalid floating point [SECTION]VARBadNum='BadInt42'
|
||||
error: Invalid real []VARBadNum='BadInt42' or out of range [-1.79769e+308,1.79769e+308]
|
||||
--- test warn integer/unsigned trailing context
|
||||
xtest.ini:14: warning: Trailing character(s) in signed integer conversion ([SECTION]VARWarnNum='42Warn')
|
||||
42
|
||||
xtest.ini:14: warning: Trailing character(s) in unsigned integer conversion ([SECTION]VARWarnNum='42Warn')
|
||||
42
|
||||
xtest.ini:14: warning: Trailing character(s) in floating point conversion ([SECTION]VARWarnNum='42Warn')
|
||||
4.200000000000000e+01
|
||||
--- test bad boolean value
|
||||
xtest.ini:12: error: Invalid boolean value [SECTION]VARBadBool='BadBool'
|
||||
--- test bad range
|
||||
error: Invalid integer range min '0' > max '-1'
|
||||
error: Invalid unsigned range min '1' > max '0'
|
||||
error: Invalid real range min '0' > max '-1'
|
||||
--- test range tested value
|
||||
error: Invalid integer []VARdm='-42' or out of range [-1,0]
|
||||
-42
|
||||
xtest.ini:6: warning: Unsigned integer conversion detected a leading minus sign (-)
|
||||
error: Invalid unsigned []VARdm='-42' or out of range [0,0]
|
||||
42
|
||||
xtest.ini:6: warning: Unsigned integer conversion detected a leading minus sign (-)
|
||||
18446744073709551574
|
||||
error: Invalid real []VARrp='+4.2e1' or out of range [8,9.999]
|
||||
4.200000000000000e+01
|
||||
error: Invalid real []VARrm='-4.2e1' or out of range [-1.21,0]
|
||||
-4.200000000000000e+01
|
||||
--- test tilde expansion without HOME
|
||||
error: Tilde expansion failed on '~/xyz'
|
||||
--- test tilde expansion with HOME
|
||||
/we/control/home/xyz
|
||||
--- reproduce ini-file content
|
||||
ini-file reproduction success
|
||||
--- comment removal processing
|
||||
xtest.ini:3: error: Invalid section. Missing ']'
|
||||
blabla # comment not ignored
|
||||
blabla ; comment not ignored
|
||||
--- string processing single/double quote
|
||||
'foo'
|
||||
"bar"
|
||||
--- string processing single/double in normal text
|
||||
foo 'quote' bar
|
||||
bar "quote" foo
|
||||
--- string continuations escaped newlines
|
||||
"some
|
||||
string
|
||||
separated on
|
||||
lines"
|
||||
--- embedded nul in values
|
||||
xtest.ini:2: error: Embedded literal NUL character not supported
|
||||
xtest.ini:2: error: Embedded literal NUL character not supported
|
||||
xtest.ini:2: error: Embedded octal NUL character not supported
|
||||
xtest.ini:2: error: Embedded hex NUL character not supported
|
||||
xtest.ini:2: error: Embedded UTF-16 NUL character not supported
|
||||
xtest.ini:2: error: Embedded UTF-32 NUL character not supported
|
||||
--- escape invalid and improper hex
|
||||
xtest.ini:2: error: Invalid hex 'YZ' in hex escape
|
||||
xtest.ini:2: error: Improper hex escape
|
||||
xtest.ini:2: error: Invalid hex 'Y ' in hex escape
|
||||
xtest.ini:2: error: Invalid hex value 'VWZY' in UTF-16 escape
|
||||
xtest.ini:2: error: Improper UTF-16 escape
|
||||
xtest.ini:2: error: Invalid hex value 'VWZ ' in UTF-16 escape
|
||||
xtest.ini:2: error: Invalid hex value 'vwxyijkl' in UTF-32 escape
|
||||
xtest.ini:2: error: Improper UTF-32 escape
|
||||
xtest.ini:2: error: Invalid hex value 'vwxyijk ' in UTF-32 escape
|
||||
--- UTF-16 surrogates, sigh
|
||||
xtest.ini:2: error: Missing low surrogate in UTF-16
|
||||
xtest.ini:2: error: Invalid high surrogate value uDC00 in UTF-16
|
||||
xtest.ini:2: error: Invalid low surrogate value uD800 in UTF-16
|
||||
xtest.ini:2: error: Invalid hex 'dc0 ' in UTF-16 low surrogate escape
|
||||
😀
|
||||
--- invalid code points
|
||||
xtest.ini:2: error: Invalid code point U00110000 in UTF-32 escape
|
||||
--- valid code points
|
||||
AAAA
|
||||
--- invalid UTF-8
|
||||
xtest.ini:2: error: Value contains invalid UTF-8 sequence
|
||||
xtest.ini:2: error: Value contains invalid UTF-8 sequence
|
||||
xtest.ini:2: error: Value contains invalid UTF-8 sequence
|
||||
xtest.ini:2: error: Value contains invalid UTF-8 sequence
|
||||
xtest.ini:2: error: Value contains invalid UTF-8 sequence
|
||||
xtest.ini:2: error: Value contains invalid UTF-8 sequence
|
||||
xtest.ini:2: error: Value contains invalid UTF-8 sequence
|
||||
xtest.ini:2: error: Value contains invalid UTF-8 sequence
|
||||
xtest.ini:2: error: Value contains invalid UTF-8 sequence
|
||||
xtest.ini:2: error: Value contains invalid UTF-8 sequence
|
||||
xtest.ini:2: error: Value contains invalid UTF-8 sequence
|
||||
xtest.ini:2: error: Value contains invalid UTF-8 sequence
|
||||
xtest.ini:2: error: Value contains invalid UTF-8 sequence
|
||||
xtest.ini:2: error: Value contains invalid UTF-8 sequence
|
||||
😀
|
||||
+++ all done +++
|
||||
411
tests/inifile/inivalue/test.sh
Executable file
411
tests/inifile/inivalue/test.sh
Executable file
@@ -0,0 +1,411 @@
|
||||
#!/bin/bash
|
||||
|
||||
# We have many special echo statements with carefully planned good and bad
|
||||
# escapes that are flagged. This directive disables the message and applies to
|
||||
# the entire script.
|
||||
# shellcheck disable=2028
|
||||
true
|
||||
|
||||
INIVALUE=inivalue
|
||||
[ -x ./inivalue ] && INIVALUE=./inivalue
|
||||
|
||||
command -v "$INIVALUE" > /dev/null 2>&1 || { r "*** Missing inivalue executable"; exit 1; }
|
||||
|
||||
r() { echo "$@" >> result; }
|
||||
f() { echo "***" "$@" "failed" >> result; }
|
||||
t() { echo "***" "$@" "did not fail" >> result; }
|
||||
tst() { "$INIVALUE" "$@" xtest.ini >> result 2>&1; }
|
||||
|
||||
true > result
|
||||
r "+++ Running test program for 'inivalue' +++"
|
||||
|
||||
r "--- test ini-file does not exist"
|
||||
"$INIVALUE" --var=dontcare this_file_does_not_exist_and_will_never_be_here.ini >> result 2>&1 && t "Missing ini-file"
|
||||
|
||||
r "--- test missing include filename (without blank)"
|
||||
echo "#INCLUDE" > xtest.ini
|
||||
tst --var=dontcare && t "Missing include"
|
||||
|
||||
r "--- test missing include filename (with blank)"
|
||||
echo "#INCLUDE " > xtest.ini
|
||||
tst --var=dontcare && t "Missing include"
|
||||
|
||||
r "--- test include file not found"
|
||||
echo "#INCLUDE this_file_does_not_exist.inc" > xtest.ini
|
||||
tst --var=dontcare && t "Nonexistent include file"
|
||||
|
||||
r "--- test include file recursion"
|
||||
echo "#INCLUDE xtest.inc" > xtest.ini
|
||||
echo "#INCLUDE xtest.ini" > xtest.inc
|
||||
tst --var=dontcare && t "Include recursion"
|
||||
# we /could/ test max include depth, but that is a pain...
|
||||
|
||||
r "--- test invalid section, missing ']'"
|
||||
echo "[SECTION" > xtest.ini
|
||||
tst --var=VAR && t "Invalid section"
|
||||
|
||||
r "--- test invalid section, no content"
|
||||
echo "[]" > xtest.ini
|
||||
tst --var=VAR && t "Invalid section"
|
||||
echo "[ ]" > xtest.ini
|
||||
tst --var=VAR && t "Invalid section"
|
||||
|
||||
r "--- test invalid section, invalid identifier"
|
||||
echo "[0SECTION]" > xtest.ini
|
||||
tst --var=VAR && t "Invalid section"
|
||||
echo "[xæøåz]" > xtest.ini
|
||||
tst --var=VAR && t "Invalid section"
|
||||
|
||||
r "--- test duplicate section merge warning"
|
||||
( echo "[SECTION]"
|
||||
echo "[SECTION]"
|
||||
echo "VAR=val" ) > xtest.ini
|
||||
tst --var=VAR || f "Merging duplicate section"
|
||||
|
||||
r "--- test section trailing junk warning"
|
||||
( echo "[SECTION] This is junk"
|
||||
echo "VAR=val" ) > xtest.ini
|
||||
tst --var=VAR || f "Trailing section junk"
|
||||
|
||||
r "--- test invalid variable name missing '='"
|
||||
( echo "[SECTION]"
|
||||
echo "VAR" ) > xtest.ini
|
||||
tst --var=VAR && t "Invalid variable missing '='"
|
||||
|
||||
r "--- test invalid variable name missing identifier"
|
||||
( echo "[SECTION]"
|
||||
echo " = value" ) > xtest.ini
|
||||
tst --var=VAR && t "Invalid variable missing identifier"
|
||||
|
||||
r "--- test invalid variable name missing '='"
|
||||
( echo "[SECTION]"
|
||||
echo "VAR x" ) > xtest.ini
|
||||
tst --var=VAR && t "Invalid variable missing '='"
|
||||
|
||||
r "--- test invalid variable name identifier"
|
||||
( echo "[SECTION]"
|
||||
echo "0VAR=val" ) > xtest.ini
|
||||
tst --var=0VAR && t "Invalid variable name"
|
||||
( echo "[SECTION]"
|
||||
echo "VÅR=val" ) > xtest.ini
|
||||
tst --var=VAR && t "Invalid variable name"
|
||||
( echo "[SECTION]"
|
||||
echo "VAR x=val" ) > xtest.ini
|
||||
tst --var=VAR && t "Invalid variable name"
|
||||
|
||||
|
||||
r "--- test invalid variable outside section"
|
||||
echo "VAR=val" > xtest.ini
|
||||
tst --var=VAR && t "Invalid variable outside section"
|
||||
|
||||
r "--- test continuation"
|
||||
( echo "[SECTION]"
|
||||
echo "VAR=val \\"
|
||||
echo " more val" ) > xtest.ini
|
||||
tst --var=VAR || f "Variable/line continuation"
|
||||
|
||||
r "--- test last line has continuation without newline"
|
||||
( echo "[SECTION]"
|
||||
echo -n "VAR=val \\" ) > xtest.ini
|
||||
tst --var=VAR && t "Variable/line continuation"
|
||||
|
||||
r "--- test last line has continuation with newline"
|
||||
( echo "[SECTION]"
|
||||
echo "VAR=val \\" ) > xtest.ini
|
||||
tst --var=VAR && t "Variable/line continuation"
|
||||
|
||||
r "--- test getting all sections"
|
||||
( echo "[S1]"
|
||||
echo "VAR=s1"
|
||||
echo "[S2]"
|
||||
echo "VAR=s2a"
|
||||
echo "VAR=s2b"
|
||||
echo "VAR=s2c"
|
||||
echo "[S3]"
|
||||
echo "VAR=s3" ) > xtest.ini
|
||||
tst --sections || f "Getting sections"
|
||||
|
||||
r "--- test get all variable of a name"
|
||||
tst --var=VAR --all || f "Getting [*]VAR[1,-]"
|
||||
r "--- test get all variable of a name from the 3'rd"
|
||||
tst --var=VAR --all --num=3 || f "Getting [*]VAR[3,-]"
|
||||
r "--- test get all variable of a name from unexisting number"
|
||||
tst --var=VAR --all --num=42 && t "Getting [*]VAR[42,-]"
|
||||
|
||||
r "--- test get the 2'nd variable of global name VAR"
|
||||
tst --var=VAR --num=2 || f "Getting [*]VAR[2]"
|
||||
r "--- test get the 2'nd variable of name VAR in section"
|
||||
tst --var=VAR --num=2 --sec=S2 || f "Getting [S2]VAR[2]"
|
||||
r "--- test get the unexisting number variable of name VAR in section"
|
||||
tst --var=VAR --num=42 --sec=S2 && t "Getting [S2]VAR[42]"
|
||||
|
||||
( echo "[SECTION]"
|
||||
echo "VARdp=42"
|
||||
echo "VARxp=0x2a"
|
||||
echo "VARop=0o52"
|
||||
echo "VARbp=0b101010"
|
||||
echo "VARdm=-42"
|
||||
echo "VARxm=-0x2a"
|
||||
echo "VARom=-0o52"
|
||||
echo "VARbm=-0b101010"
|
||||
echo "VARrp=+4.2e1"
|
||||
echo "VARrm=-4.2e1"
|
||||
echo "VARBadBool=BadBool"
|
||||
echo "VARBadNum=BadInt42"
|
||||
echo "VARWarnNum=42Warn"
|
||||
echo "VARBt1=TRUE"
|
||||
echo "VARBt2=true"
|
||||
echo "VARBt3=True"
|
||||
echo "VARBt4=yes"
|
||||
echo "VARBt5=YeS"
|
||||
echo "VARBt6=1"
|
||||
echo "VARBt7=oN"
|
||||
echo "VARBf1=FALSE"
|
||||
echo "VARBf2=false"
|
||||
echo "VARBf3=FalSe"
|
||||
echo "VARBf4=no"
|
||||
echo "VARBf5=nO"
|
||||
echo "VARBf6=0"
|
||||
echo "VARBf7=oFf" ) > xtest.ini
|
||||
r "--- test integer/unsigned value"
|
||||
for i in d x o b; do
|
||||
tst --var="VAR${i}p" --type=i || f "Integer VAR${i}p variable"
|
||||
tst --var="VAR${i}m" --type=i || f "Integer VAR${i}m variable"
|
||||
tst --var="VAR${i}p" --type=u || f "Unsigned VAR${i}p variable"
|
||||
tst --var="VAR${i}m" --type=u || f "Unsigned VAR${i}m variable"
|
||||
done
|
||||
r "--- test real value"
|
||||
tst --var=VARrp --type=r || f "Real variable"
|
||||
tst --var=VARrm --type=r || f "Real variable"
|
||||
r "--- test boolean value"
|
||||
for i in 1 2 3 4 5 6 7; do
|
||||
tst --var="VARBt${i}" --type=b || f "Boolean variable VARBt${i}"
|
||||
tst --var="VARBf${i}" --type=b || f "Boolean variable VARBf${i}"
|
||||
tst --var="VARBt${i}" --type=b -b || f "Boolean variable VARBt${i}"
|
||||
tst --var="VARBf${i}" --type=b -b || f "Boolean variable VARBf${i}"
|
||||
tst --var="VARBt${i}" --type=b -B || f "Boolean variable VARBt${i}"
|
||||
tst --var="VARBf${i}" --type=b -B || f "Boolean variable VARBf${i}"
|
||||
done
|
||||
|
||||
r "--- test bad integer/unsigned value"
|
||||
tst --var="VARBadNum" --type=i && t "Bad integer VARBadNum"
|
||||
tst --var="VARBadNum" --type=u && t "Bad unsigned VARBadNum"
|
||||
tst --var="VARBadNum" --type=r && t "Bad real VARBadNum"
|
||||
r "--- test warn integer/unsigned trailing context"
|
||||
tst --var="VARWarnNum" --type=i || f "Bad integer VARWarnNum"
|
||||
tst --var="VARWarnNum" --type=u || f "Bad unsigned VARWarnNum"
|
||||
tst --var="VARWarnNum" --type=r || f "Bad real VARWarnNum"
|
||||
r "--- test bad boolean value"
|
||||
tst --var="VARBadBool" --type=b && t "Bad boolean VARBadBool"
|
||||
|
||||
r "--- test bad range"
|
||||
tst --var=VARdm --type=i -m 0 -M -1 && t "Integer range"
|
||||
tst --var=VARdm --type=u -m 1 -M 0 && t "Integer range"
|
||||
tst --var=VARdm --type=r -m 0 -M -1 && t "Integer range"
|
||||
|
||||
r "--- test range tested value"
|
||||
tst --var=VARdm --type=i -m -1 -M 0 && t "Integer range"
|
||||
tst --var=VARdm --type=i -m -50 -M -40 || f "Integer range"
|
||||
tst --var=VARdm --type=u -m 0 -M -0 && t "Unsigned range"
|
||||
tst --var=VARdp --type=u -m 42 -M 42 || f "Unsigned range"
|
||||
tst --var=VARdm --type=u -m -50 -M -40 || f "Unsigned range"
|
||||
tst --var=VARrp --type=r -m 8.0 -M 9.999 && t "Real range"
|
||||
tst --var=VARrp --type=r -m 3.14 -M 45.0 || f "Real range"
|
||||
tst --var=VARrm --type=r -m -1.21 -M 0.0 && t "Real range"
|
||||
tst --var=VARrm --type=r -m -50.1 -M -40 || f "Real range"
|
||||
|
||||
r "--- test tilde expansion without HOME"
|
||||
XHOME="$HOME"
|
||||
export -n HOME
|
||||
( echo "[SECTION]"
|
||||
echo "VAR=~/xyz" ) > xtest.ini
|
||||
tst --var=VAR --sec=SECTION --tildeexpand && t "Missing HOME"
|
||||
|
||||
r "--- test tilde expansion with HOME"
|
||||
HOME="/we/control/home"
|
||||
export HOME
|
||||
tst --var=VAR --sec=SECTION --tildeexpand || f "Using HOME"
|
||||
HOME="$XHOME"
|
||||
export HOME
|
||||
unset XHOME
|
||||
|
||||
r "--- reproduce ini-file content"
|
||||
( echo "[QUINE]"
|
||||
echo "VAR=42"
|
||||
echo "VAR=0x2a"
|
||||
echo "VAR=0o52"
|
||||
echo "VAR=0b101010"
|
||||
echo "[QUOTED]"
|
||||
echo "S='\"single surrounding \\\\ double\"'"
|
||||
echo "D=\"'double surrounding \\\\ single'\""
|
||||
echo "E=embedded \"double\" and 'single'"
|
||||
echo "C=\" spaces and \\x1f newline\\n\""
|
||||
echo "U=\\x20 start spaces"
|
||||
echo "V=end spaces \\x20"
|
||||
echo "W=\\x20 all spaces \\x20"
|
||||
echo "[NOTQUINE]"
|
||||
echo "This=-42"
|
||||
echo "iS=-0x2a"
|
||||
echo "a=-0o52"
|
||||
echo "sTrAnGe=-0b101010"
|
||||
echo "Variable=Variable" ) > xtest.ini
|
||||
true > quine.ini
|
||||
for s in $("$INIVALUE" --sections xtest.ini); do
|
||||
echo "[$s]" >> quine.ini
|
||||
"$INIVALUE" --variables --content --sec "$s" xtest.ini >> quine.ini
|
||||
done
|
||||
if diff -u xtest.ini quine.ini >> result 2>&1; then
|
||||
r "ini-file reproduction success"
|
||||
else
|
||||
f "quine diff"
|
||||
fi
|
||||
|
||||
r "--- comment removal processing"
|
||||
( echo " ; comment ignored"
|
||||
echo " # comment ignored"
|
||||
echo "[MUSTFAILHERE" ) > xtest.ini
|
||||
tst --var=VAR --sec=SECTION && t "Must fail @line 3"
|
||||
( echo " [SECTION] ; comment ignored"
|
||||
echo " VARa=blabla # comment not ignored"
|
||||
echo " VARb=blabla ; comment not ignored"
|
||||
) > xtest.ini
|
||||
tst --var=VARa --sec=SECTION || f "Comment VARa removal"
|
||||
tst --var=VARb --sec=SECTION || f "Comment VARb removal"
|
||||
|
||||
r "--- string processing single/double quote"
|
||||
( echo "[SECTION]"
|
||||
echo "VARs='foo'"
|
||||
echo "VARq=\"bar\"" ) > xtest.ini
|
||||
tst --var=VARs --sec=SECTION || f "Single quote string"
|
||||
tst --var=VARq --sec=SECTION || f "Double quote string"
|
||||
|
||||
r "--- string processing single/double in normal text"
|
||||
( echo "[SECTION]"
|
||||
echo "VARs=foo 'quote' bar"
|
||||
echo "VARq=bar \"quote\" foo" ) > xtest.ini
|
||||
tst --var=VARs --sec=SECTION || f "Embedded single quote string"
|
||||
tst --var=VARq --sec=SECTION || f "Embedded double quote string"
|
||||
|
||||
r "--- string continuations escaped newlines"
|
||||
( echo "[SECTION]"
|
||||
echo "VAR=\"some\n \\"
|
||||
echo " string\n \\"
|
||||
echo " separated on\n \\"
|
||||
echo " lines\"" ) > xtest.ini
|
||||
tst --var=VAR --sec=SECTION || f "String collection and continuation"
|
||||
|
||||
r "--- embedded nul in values"
|
||||
( echo "[SECTION]"
|
||||
echo -e "VAR=val\0val" ) > xtest.ini
|
||||
tst --var=VAR --sec=SECTION && t "Embedded NUL in value"
|
||||
( echo "[SECTION]"
|
||||
echo -e "VAR=val\0val" ) > xtest.ini
|
||||
tst --var=VAR --sec=SECTION && t "Embedded literal NUL"
|
||||
( echo "[SECTION]"
|
||||
echo "VAR=\\0" ) > xtest.ini
|
||||
tst --var=VAR --sec=SECTION && t "Embedded octal NUL"
|
||||
( echo "[SECTION]"
|
||||
echo "VAR=\\x00" ) > xtest.ini
|
||||
tst --var=VAR --sec=SECTION && t "Embedded hex NUL"
|
||||
( echo "[SECTION]"
|
||||
echo "VAR=\\u0000" ) > xtest.ini
|
||||
tst --var=VAR --sec=SECTION && t "Embedded UTF-16 NUL"
|
||||
( echo "[SECTION]"
|
||||
echo "VAR=\\U00000000" ) > xtest.ini
|
||||
tst --var=VAR --sec=SECTION && t "Embedded UTF-32 NUL"
|
||||
|
||||
r "--- escape invalid and improper hex"
|
||||
( echo "[SECTION]"
|
||||
echo "VAR=\\xYZ" ) > xtest.ini
|
||||
tst --var=VAR --sec=SECTION && t "Invalid hex escape"
|
||||
( echo "[SECTION]"
|
||||
echo "VAR=\\xY" ) > xtest.ini
|
||||
tst --var=VAR --sec=SECTION && t "Improper short hex escape"
|
||||
( echo "[SECTION]"
|
||||
echo "VAR=\"\\xY \"" ) > xtest.ini
|
||||
tst --var=VAR --sec=SECTION && t "Invalid short hex escape"
|
||||
( echo "[SECTION]"
|
||||
echo "VAR=\\uVWZY" ) > xtest.ini
|
||||
tst --var=VAR --sec=SECTION && t "Invalid hex UTF-16"
|
||||
( echo "[SECTION]"
|
||||
echo "VAR=\\uVWZ" ) > xtest.ini
|
||||
tst --var=VAR --sec=SECTION && t "Improper short hex UTF-16"
|
||||
( echo "[SECTION]"
|
||||
echo "VAR=\"\\uVWZ \"" ) > xtest.ini
|
||||
tst --var=VAR --sec=SECTION && t "Invalid short hex UTF-16"
|
||||
( echo "[SECTION]"
|
||||
echo "VAR=\\Uvwxyijkl" ) > xtest.ini
|
||||
tst --var=VAR --sec=SECTION && t "Invalid hex UTF-32"
|
||||
( echo "[SECTION]"
|
||||
echo "VAR=\\Uvwxyijk" ) > xtest.ini
|
||||
tst --var=VAR --sec=SECTION && t "Improper short hex UTF-32"
|
||||
( echo "[SECTION]"
|
||||
echo "VAR=\"\\Uvwxyijk \"" ) > xtest.ini
|
||||
tst --var=VAR --sec=SECTION && t "Invalid short hex UTF-32"
|
||||
|
||||
r "--- UTF-16 surrogates, sigh"
|
||||
( echo "[SECTION]"
|
||||
echo "VAR=\\ud800" ) > xtest.ini
|
||||
tst --var=VAR --sec=SECTION && t "Missing UTF-16 low surrogate"
|
||||
( echo "[SECTION]"
|
||||
echo "VAR=\\udc00" ) > xtest.ini
|
||||
tst --var=VAR --sec=SECTION && t "Invalid UTF-16 high surrogate"
|
||||
( echo "[SECTION]"
|
||||
echo "VAR=\\ud800\\ud800" ) > xtest.ini
|
||||
tst --var=VAR --sec=SECTION && t "Invalid UTF-16 low surrogate"
|
||||
( echo "[SECTION]"
|
||||
echo "VAR=\"\\ud800\\udc0 \"" ) > xtest.ini
|
||||
tst --var=VAR --sec=SECTION && t "Invalid UTF-16 low surrogate"
|
||||
( echo "[SECTION]"
|
||||
# f600; smiley
|
||||
echo "VAR=\\ud83d\\ude00" ) > xtest.ini
|
||||
tst --var=VAR --sec=SECTION || f "Valid UTF-16"
|
||||
|
||||
r "--- invalid code points"
|
||||
( echo "[SECTION]"
|
||||
echo "VAR=\\U00110000" ) > xtest.ini
|
||||
tst --var=VAR --sec=SECTION && t "Invalid code point UTF-32"
|
||||
|
||||
r "--- valid code points"
|
||||
( echo "[SECTION]"
|
||||
# AAAA
|
||||
echo "VAR=\\101\\x41\\u0041\\U00000041" ) > xtest.ini
|
||||
tst --var=VAR --sec=SECTION || f "Valid code points"
|
||||
|
||||
r "--- invalid UTF-8"
|
||||
echo -e '[SECTION]\nVAR="\\xc0 "' > xtest.ini
|
||||
tst --var=VAR --sec=SECTION && t "Invalid UTF-8 c0 overlap"
|
||||
echo -e '[SECTION]\nVAR="\\xc1 "' > xtest.ini
|
||||
tst --var=VAR --sec=SECTION && t "Invalid UTF-8 c1 overlap"
|
||||
echo -e '[SECTION]\nVAR="\\xc2"' > xtest.ini
|
||||
tst --var=VAR --sec=SECTION && t "Invalid UTF-8 c2 short seq"
|
||||
echo -e '[SECTION]\nVAR="\\xe0\\x8f"' > xtest.ini
|
||||
tst --var=VAR --sec=SECTION && t "Invalid UTF-8 e08f overlap"
|
||||
echo -e '[SECTION]\nVAR="\\xed\\xa0"' > xtest.ini
|
||||
tst --var=VAR --sec=SECTION && t "Invalid UTF-8 surrogate"
|
||||
echo -e '[SECTION]\nVAR="\\xed\\x9f"' > xtest.ini
|
||||
tst --var=VAR --sec=SECTION && t "Invalid UTF-8 ed9f short seq"
|
||||
echo -e '[SECTION]\nVAR="\\xf0\\x8f"' > xtest.ini
|
||||
tst --var=VAR --sec=SECTION && t "Invalid UTF-8 f08f overlap"
|
||||
echo -e '[SECTION]\nVAR="\\xf0\\x90\\x80"' > xtest.ini
|
||||
tst --var=VAR --sec=SECTION && t "Invalid UTF-8 f09080 short seq"
|
||||
echo -e '[SECTION]\nVAR="\\xf4\\x90"' > xtest.ini
|
||||
tst --var=VAR --sec=SECTION && t "Invalid UTF-8 f490 code point"
|
||||
echo -e '[SECTION]\nVAR="\\xf5 "' > xtest.ini
|
||||
tst --var=VAR --sec=SECTION && t "Invalid UTF-8 f5 code point"
|
||||
echo -e '[SECTION]\nVAR="\\xf6 "' > xtest.ini
|
||||
tst --var=VAR --sec=SECTION && t "Invalid UTF-8 f6 code point"
|
||||
echo -e '[SECTION]\nVAR="\\xf7 "' > xtest.ini
|
||||
tst --var=VAR --sec=SECTION && t "Invalid UTF-8 f7 code point"
|
||||
echo -e '[SECTION]\nVAR="\\xf8 "' > xtest.ini
|
||||
tst --var=VAR --sec=SECTION && t "Invalid UTF-8 f8 code point"
|
||||
echo -e '[SECTION]\nVAR="\\xff "' > xtest.ini
|
||||
tst --var=VAR --sec=SECTION && t "Invalid UTF-8 ff code point"
|
||||
# f600; smiley: 11110 000 10 011111 10 011000 10 000000
|
||||
echo -e '[SECTION]\nVAR=\\xf0\\x9f\\x98\\x80' > xtest.ini
|
||||
tst --var=VAR --sec=SECTION || f "UTF-8 Smiley"
|
||||
|
||||
r "+++ all done +++"
|
||||
|
||||
rm -f xtest.ini xtest.inc quine.ini
|
||||
# vim: ts=4 sw=4
|
||||
5
tests/inifile/line_endings/README
Normal file
5
tests/inifile/line_endings/README
Normal file
@@ -0,0 +1,5 @@
|
||||
The INI parser in LinuxCNC handles UNIX line endings, '\n' and DOS '\r\n', with
|
||||
a warning. The parser aborts when it encounters classic MAC OS line endings '\r'.
|
||||
|
||||
The INI files is created in the test script, since several tools automatically
|
||||
fixes the line endings.
|
||||
2
tests/inifile/line_endings/expected
Normal file
2
tests/inifile/line_endings/expected
Normal file
@@ -0,0 +1,2 @@
|
||||
value1
|
||||
value1
|
||||
16
tests/inifile/line_endings/test.sh
Executable file
16
tests/inifile/line_endings/test.sh
Executable file
@@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Manually create INI files with different line endings.
|
||||
lf="[section1]\nkey1=value1\n"
|
||||
cr="[section1]\rkey1=value1\r"
|
||||
crlf="[section1]\r\nkey1=value1\r\n"
|
||||
|
||||
echo -e "$lf" > "lf.ini"
|
||||
echo -e "$cr" > "cr.ini"
|
||||
echo -e "$crlf" > "crlf.ini"
|
||||
|
||||
inivar -ini lf.ini -var key1 # Should be successful.
|
||||
inivar -ini cr.ini -var key1 # Should fail.
|
||||
inivar -ini crlf.ini -var key1 # Should be successful.
|
||||
|
||||
rm -f lf.ini cr.ini crlf.ini
|
||||
3
tests/inifile/missing_values/expected
Normal file
3
tests/inifile/missing_values/expected
Normal file
@@ -0,0 +1,3 @@
|
||||
missing_section.ini:1: error: Tag 'key1' found without prior section definition
|
||||
|
||||
missing_section.ini:1: error: Tag 'key1' found without prior section definition
|
||||
1
tests/inifile/missing_values/missing_section.ini
Normal file
1
tests/inifile/missing_values/missing_section.ini
Normal file
@@ -0,0 +1 @@
|
||||
key1=value1
|
||||
2
tests/inifile/missing_values/missing_value.ini
Normal file
2
tests/inifile/missing_values/missing_value.ini
Normal file
@@ -0,0 +1,2 @@
|
||||
[section1]
|
||||
key1=
|
||||
9
tests/inifile/missing_values/test.sh
Executable file
9
tests/inifile/missing_values/test.sh
Executable file
@@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
# We don't want a single redirect because the output must be very specific.
|
||||
# shellcheck disable=SC2129
|
||||
true > result
|
||||
inivar -ini missing_section.ini -sec section1 -var key1 >> result 2>&1
|
||||
inivar -ini missing_value.ini -var key1 >> result 2>&1
|
||||
inivar -ini missing_section.ini -var key1 >> result 2>&1
|
||||
exit 0
|
||||
109
tests/inifile/python_bindings/expected
Normal file
109
tests/inifile/python_bindings/expected
Normal file
@@ -0,0 +1,109 @@
|
||||
Missing section was missing
|
||||
Present section was present
|
||||
Missing variable was missing
|
||||
Present [section]variable was present
|
||||
Bool 1: True
|
||||
Bool 2: True
|
||||
Bool 3: True
|
||||
Bool 4: True
|
||||
Bool 5: False
|
||||
Bool 6: False
|
||||
Bool 7: False
|
||||
Bool 8: False
|
||||
Bool 9: None
|
||||
Int 1: 42
|
||||
Int 2: -42
|
||||
Int 3: 42
|
||||
Int 4: -42
|
||||
Int 5: 42
|
||||
Int 6: -42
|
||||
Int 7: 42
|
||||
Int 8: -42
|
||||
Int 9: None
|
||||
Unsigned 1: 42
|
||||
Unsigned 2: 18446744073709551574
|
||||
Unsigned 3: 42
|
||||
Unsigned 4: 42
|
||||
Unsigned 5: 42
|
||||
Unsigned 6: None
|
||||
Real 1: 0.1
|
||||
Real 2: 4.2e-06
|
||||
Real 3: 42.0
|
||||
Real 4: -42.0
|
||||
Real 5: None
|
||||
String 1: 'String without quotes'
|
||||
String 2: '"String with double quotes"'
|
||||
String 3: ''String with single quotes''
|
||||
String 4: '"String concat " "with" ' mixed ' 'quotes' " and so"'
|
||||
String 5: '# not empty'
|
||||
String 6: '"" # not empty too'
|
||||
String 7: '" " # a space, don't know why you'd want that...'
|
||||
String 8: '"Smile! 😀😀😀"'
|
||||
String 9: None
|
||||
Sections:
|
||||
-> section
|
||||
-> booleans
|
||||
-> integers
|
||||
-> unsigneds
|
||||
-> reals
|
||||
-> strings
|
||||
-> section2
|
||||
Variables of [section]:
|
||||
-> ('variable', 'value')
|
||||
-> ('key2', 'value 2')
|
||||
-> ('key3', 'a value with continuation and nothing more')
|
||||
-> ('a_long_key_that_spans_a_whole_lot_of_characters_and_is_practically_useless', 'value4')
|
||||
-> ('number', '0.000001')
|
||||
Variables of all sections:
|
||||
-> ('variable', 'value')
|
||||
-> ('key2', 'value 2')
|
||||
-> ('key3', 'a value with continuation and nothing more')
|
||||
-> ('a_long_key_that_spans_a_whole_lot_of_characters_and_is_practically_useless', 'value4')
|
||||
-> ('number', '0.000001')
|
||||
-> ('bool', 'true')
|
||||
-> ('bool', 'yes')
|
||||
-> ('bool', '1')
|
||||
-> ('bool', 'on')
|
||||
-> ('bool', 'false')
|
||||
-> ('bool', 'no')
|
||||
-> ('bool', '0')
|
||||
-> ('bool', 'off')
|
||||
-> ('bool', 'invalid')
|
||||
-> ('int', '42')
|
||||
-> ('int', '-42')
|
||||
-> ('int', '0x2a')
|
||||
-> ('int', '-0x2a')
|
||||
-> ('int', '0o52')
|
||||
-> ('int', '-0o52')
|
||||
-> ('int', '0b101010')
|
||||
-> ('int', '-0b101010')
|
||||
-> ('int', 'invalid')
|
||||
-> ('unsigned', '42')
|
||||
-> ('unsigned', '-42')
|
||||
-> ('unsigned', '0x2a')
|
||||
-> ('unsigned', '0o52')
|
||||
-> ('unsigned', '0b101010')
|
||||
-> ('unsigned', 'invalid')
|
||||
-> ('real', '0.1')
|
||||
-> ('real', '0.0000042')
|
||||
-> ('real', '42')
|
||||
-> ('real', '-4.2e1')
|
||||
-> ('real', 'invalid')
|
||||
-> ('string', 'String without quotes')
|
||||
-> ('string', '"String with double quotes"')
|
||||
-> ('string', "'String with single quotes'")
|
||||
-> ('string', '"String concat " "with" \' mixed \' \'quotes\' " and so"')
|
||||
-> ('string', '# not empty')
|
||||
-> ('string', '"" # not empty too')
|
||||
-> ('string', '" " # a space, don\'t know why you\'d want that...')
|
||||
-> ('string', '"Smile! 😀😀😀"')
|
||||
-> ('key1', 'value1')
|
||||
-> ('key1', 'value2')
|
||||
-> ('key1', 'value3')
|
||||
-> ('key4', 'value4')
|
||||
Variables of non-existent section: []
|
||||
values.ini:22: [integers]int='42'
|
||||
values.ini:50: [strings]string=''String with single quotes''
|
||||
None:None: [missing]missing=None
|
||||
findall [section2]key1: value1, value2, value3
|
||||
findall [section2]: value1, value2, value3, value4
|
||||
101
tests/inifile/python_bindings/test
Executable file
101
tests/inifile/python_bindings/test
Executable file
@@ -0,0 +1,101 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import linuxcnc
|
||||
|
||||
ini = linuxcnc.ini("values.ini")
|
||||
|
||||
# Test availability testing
|
||||
if ini.hassection("notasection"):
|
||||
print("Missing section was wrongfully detected")
|
||||
else:
|
||||
print("Missing section was missing")
|
||||
|
||||
if ini.hassection("section"):
|
||||
print("Present section was present")
|
||||
else:
|
||||
print("Present section was wrongfully detected as not present")
|
||||
|
||||
if ini.hasvariable("section", "missing"):
|
||||
print("Missing variable was detected to be present")
|
||||
else:
|
||||
print("Missing variable was missing")
|
||||
|
||||
if ini.hasvariable("section", "variable"):
|
||||
print("Present [section]variable was present")
|
||||
else:
|
||||
print("Present [section]variable was wrongfully detected as not present")
|
||||
|
||||
# Test booleans
|
||||
for n in range(1, 9+1):
|
||||
print("Bool {}: {}".format(n, ini.getbool("booleans", "bool", n)))
|
||||
if True != ini.getbool("booleans", "missing", fallback=True):
|
||||
print("Bool default True failed")
|
||||
if False != ini.getbool("booleans", "missing", fallback=False):
|
||||
print("Bool default False failed")
|
||||
if "hello" != ini.getbool("booleans", "missing", fallback="hello"):
|
||||
print("Bool default 'hello' failed")
|
||||
|
||||
# Test integers
|
||||
for n in range(1, 9+1):
|
||||
print("Int {}: {}".format(n, ini.getsint("integers", "int", n)))
|
||||
if 42 != ini.getsint("integers", "missing", fallback=42):
|
||||
print("Int default 42 failed")
|
||||
if "_42" != ini.getsint("integers", "missing", fallback="_42"): # any fallback type is returned
|
||||
print("Int default '_42' failed")
|
||||
if ini.getsint("integers", "int") != ini.getint("integers", "int"):
|
||||
print("getsint/getint alias error")
|
||||
|
||||
# Test unsigneds
|
||||
for n in range(1, 6+1):
|
||||
print("Unsigned {}: {}".format(n, ini.getuint("unsigneds", "unsigned", n)))
|
||||
if 42 != ini.getuint("unsigneds", "missing", fallback=42):
|
||||
print("Unsigned default 42 failed")
|
||||
if "_42" != ini.getuint("unsigneds", "missing", fallback="_42"): # any fallback type is returned
|
||||
print("Unsigned default '_42' failed")
|
||||
|
||||
# Test reals
|
||||
for n in range(1, 5+1):
|
||||
print("Real {}: {}".format(n, ini.getreal("reals", "real", n)))
|
||||
if 42 != ini.getreal("reals", "missing", fallback=4.2e1):
|
||||
print("Real default 4.2e1 failed")
|
||||
if "_42" != ini.getreal("reals", "missing", fallback="_42"): # any fallback type is returned
|
||||
print("Real default '_42' failed")
|
||||
if ini.getreal("reals", "real") != ini.getfloat("reals", "real"):
|
||||
print("getreal/getfloat alias error")
|
||||
|
||||
# Test strings
|
||||
for n in range(1, 8+1):
|
||||
print("String {}: '{}'".format(n, ini.getstring("strings", "string", n)))
|
||||
# One more to get None back, but we don't want the quotes
|
||||
print("String {}: {}".format(n+1, ini.getstring("strings", "string", n+1)))
|
||||
if None != ini.getstring("strings", "missing"):
|
||||
print("String not found failed")
|
||||
if "|_-42-_|" != ini.getstring("strings", "missing", fallback="|_-42-_|"):
|
||||
print("String default '|_-42-_|' failed")
|
||||
|
||||
# Test sections and variables
|
||||
print("Sections:")
|
||||
for s in ini.getsections():
|
||||
print("-> {}".format(s))
|
||||
print("Variables of [section]:")
|
||||
for v in ini.getvariables("section"):
|
||||
print("-> {}".format(v))
|
||||
print("Variables of all sections:")
|
||||
for v in ini.getvariables():
|
||||
print("-> {}".format(v))
|
||||
print("Variables of non-existent section:", ini.getvariables("not_a_section_we_know_of"))
|
||||
|
||||
# Test find/findall
|
||||
if None != ini.find("section", "missing"):
|
||||
print("find: Missing value was not missing")
|
||||
|
||||
# Test lineof
|
||||
f, l = ini.lineof("integers", "int")
|
||||
print("{}:{}: [integers]int='{}'".format(f, l, ini.getint("integers", "int")))
|
||||
f, l = ini.lineof("strings", "string", 3)
|
||||
print("{}:{}: [strings]string='{}'".format(f, l, ini.getstring("strings", "string", 3)))
|
||||
f, l = ini.lineof("missing", "missing")
|
||||
print("{}:{}: [missing]missing={}".format(f, l, ini.getstring("missing", "missing")))
|
||||
|
||||
print("findall [section2]key1:", ", ".join(ini.findall("section2", "key1")))
|
||||
print("findall [section2]:", ", ".join(ini.findall("section2", "")))
|
||||
61
tests/inifile/python_bindings/values.ini
Normal file
61
tests/inifile/python_bindings/values.ini
Normal file
@@ -0,0 +1,61 @@
|
||||
[section]
|
||||
variable=value
|
||||
key2=value 2
|
||||
key3 = a value \
|
||||
with continuation \
|
||||
and nothing more
|
||||
a_long_key_that_spans_a_whole_lot_of_characters_and_is_practically_useless = value4
|
||||
number = 0.000001
|
||||
|
||||
[booleans]
|
||||
bool = true
|
||||
bool = yes
|
||||
bool = 1
|
||||
bool = on
|
||||
bool = false
|
||||
bool = no
|
||||
bool = 0
|
||||
bool = off
|
||||
bool = invalid
|
||||
|
||||
[integers]
|
||||
int = 42
|
||||
int = -42
|
||||
int = 0x2a
|
||||
int = -0x2a
|
||||
int = 0o52
|
||||
int = -0o52
|
||||
int = 0b101010
|
||||
int = -0b101010
|
||||
int = invalid
|
||||
|
||||
[unsigneds]
|
||||
unsigned = 42
|
||||
unsigned = -42
|
||||
unsigned = 0x2a
|
||||
unsigned = 0o52
|
||||
unsigned = 0b101010
|
||||
unsigned = invalid
|
||||
|
||||
[reals]
|
||||
real = 0.1
|
||||
real = 0.0000042
|
||||
real = 42
|
||||
real = -4.2e1
|
||||
real = invalid
|
||||
|
||||
[strings]
|
||||
string = String without quotes
|
||||
string = "String with double quotes"
|
||||
string = 'String with single quotes'
|
||||
string = "String concat " "with" ' mixed ' 'quotes' " and so"
|
||||
string = # not empty
|
||||
string = "" # not empty too
|
||||
string = " " # a space, don't know why you'd want that...
|
||||
string = "Smile! \U0001F600\ud83d\ude00\xf0\x9f\x98\x80"
|
||||
|
||||
[section2]
|
||||
key1=value1
|
||||
key1=value2
|
||||
key1=value3
|
||||
key4=value4
|
||||
5
tests/inifile/values/expected
Normal file
5
tests/inifile/values/expected
Normal file
@@ -0,0 +1,5 @@
|
||||
value1
|
||||
value 2
|
||||
a long value
|
||||
value4
|
||||
0.000001
|
||||
7
tests/inifile/values/test.sh
Executable file
7
tests/inifile/values/test.sh
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
inivar -ini values.ini -var key1
|
||||
inivar -ini values.ini -var key2
|
||||
inivar -ini values.ini -var key3
|
||||
inivar -ini values.ini -var "alongkey"
|
||||
inivar -ini values.ini -var number
|
||||
6
tests/inifile/values/values.ini
Normal file
6
tests/inifile/values/values.ini
Normal file
@@ -0,0 +1,6 @@
|
||||
[section1]
|
||||
key1=value1
|
||||
key2=value 2
|
||||
key3 = a long value
|
||||
alongkey = value4
|
||||
number = 0.000001
|
||||
5
tests/inifile/whitespace/expected
Normal file
5
tests/inifile/whitespace/expected
Normal file
@@ -0,0 +1,5 @@
|
||||
value1
|
||||
value1
|
||||
value1
|
||||
value1
|
||||
value2
|
||||
2
tests/inifile/whitespace/leading_whitespace.ini
Normal file
2
tests/inifile/whitespace/leading_whitespace.ini
Normal file
@@ -0,0 +1,2 @@
|
||||
[section1]
|
||||
key1=value1
|
||||
2
tests/inifile/whitespace/space_between_equal.ini
Normal file
2
tests/inifile/whitespace/space_between_equal.ini
Normal file
@@ -0,0 +1,2 @@
|
||||
[section1]
|
||||
key1 = value1
|
||||
13
tests/inifile/whitespace/test.sh
Executable file
13
tests/inifile/whitespace/test.sh
Executable file
@@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Manually create INI file with trailing whitespace.
|
||||
ini_content="[section1] \nkey1=value1\t\nkey2=value2 \n"
|
||||
echo -e "$ini_content" > "trailing_whitespace.ini"
|
||||
|
||||
inivar -ini leading_whitespace.ini -var key1
|
||||
inivar -ini leading_whitespace.ini -sec section1 -var key1
|
||||
inivar -ini space_between_equal.ini -var key1
|
||||
inivar -ini trailing_whitespace.ini -var key1
|
||||
inivar -ini trailing_whitespace.ini -var key2
|
||||
|
||||
rm -f trailing_whitespace.ini
|
||||
Reference in New Issue
Block a user