Denis Vlasenko | 2e157dd | 2008-07-19 09:27:19 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | # Copyright 2008 by Denys Vlasenko <vda.linux@googlemail.com> |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 4 | # Licensed under GPLv2, see file LICENSE in this source tree. |
Denis Vlasenko | 2e157dd | 2008-07-19 09:27:19 +0000 | [diff] [blame] | 5 | |
Mike Frysinger | caa7940 | 2009-11-04 18:41:22 -0500 | [diff] [blame] | 6 | . ./testing.sh |
Denis Vlasenko | 2e157dd | 2008-07-19 09:27:19 +0000 | [diff] [blame] | 7 | |
Denys Vlasenko | 9cf89cd | 2017-08-05 13:45:22 +0200 | [diff] [blame] | 8 | COLLAPSE=$(( 0x00010000)) |
| 9 | TRIM=$(( 0x00020000)) |
| 10 | GREEDY=$(( 0x00040000)) |
| 11 | MIN_DIE=$(( 0x00100000)) |
| 12 | KEEP_COPY=$(( 0x00200000)) |
| 13 | EOL_COMMENTS=$((0x00400000)) |
| 14 | NORMAL=$(( COLLAPSE | TRIM | GREEDY | EOL_COMMENTS)) |
Denis Vlasenko | 2e157dd | 2008-07-19 09:27:19 +0000 | [diff] [blame] | 15 | |
| 16 | # testing "description" "command" "result" "infile" "stdin" |
| 17 | |
Denis Vlasenko | 084266e | 2008-07-26 23:08:31 +0000 | [diff] [blame] | 18 | testing "parse mdev.conf" \ |
| 19 | "parse -n 4 -m 3 -f $((NORMAL)) -" \ |
Denis Vlasenko | 2e157dd | 2008-07-19 09:27:19 +0000 | [diff] [blame] | 20 | "[sda][0:0][644][@echo @echo TEST]\n" \ |
| 21 | "-" \ |
| 22 | " sda 0:0 644 @echo @echo TEST # echo trap\n" |
| 23 | |
Denis Vlasenko | 084266e | 2008-07-26 23:08:31 +0000 | [diff] [blame] | 24 | testing "parse notrim" \ |
| 25 | "parse -n 4 -m 3 -f $((NORMAL - TRIM - COLLAPSE)) -" \ |
Denis Vlasenko | 2e157dd | 2008-07-19 09:27:19 +0000 | [diff] [blame] | 26 | "[][sda][0:0][644 @echo @echo TEST ]\n" \ |
| 27 | "-" \ |
| 28 | " sda 0:0 644 @echo @echo TEST \n" |
| 29 | |
Denys Vlasenko | 9cf89cd | 2017-08-05 13:45:22 +0200 | [diff] [blame] | 30 | testing "parse comments" \ |
| 31 | "parse -n 4 -m 3 -f $((NORMAL - EOL_COMMENTS)) -" \ |
| 32 | "[sda][0:0][644][@echo @echo TEST #this is not eaten]\n" \ |
| 33 | "-" \ |
| 34 | "\ |
| 35 | # sda 0:0 644 @echo @echo TEST - this gets eaten |
| 36 | sda 0:0 644 @echo @echo TEST #this is not eaten |
| 37 | " |
| 38 | |
| 39 | testing "parse bad comment" \ |
| 40 | "parse -n 2 -m 2 -d '#=' -f $((GREEDY)) - 2>&1" \ |
| 41 | "\ |
| 42 | [var][val] |
| 43 | parse: bad line 3: 1 tokens found, 2 needed |
| 44 | [ #this][ok] |
| 45 | [ #this][=ok] |
| 46 | [ #this][=ok=ok=ok=] |
| 47 | " \ |
| 48 | "-" \ |
| 49 | "\ |
| 50 | # this gets eaten |
| 51 | var=val |
| 52 | #this causes error msg |
| 53 | #this=ok |
| 54 | #this==ok |
| 55 | #this==ok=ok=ok= |
| 56 | " |
| 57 | |
Denis Vlasenko | 9b366f4 | 2008-07-20 17:50:58 +0000 | [diff] [blame] | 58 | FILE=__parse |
Denis Vlasenko | 2e157dd | 2008-07-19 09:27:19 +0000 | [diff] [blame] | 59 | cat >$FILE <<EOF |
| 60 | # |
| 61 | # Device Point System Options |
| 62 | #_______________________________________________________________ |
| 63 | /dev/hdb3 / ext2 defaults 1 0 |
| 64 | /dev/hdb1 /dosc hpfs ro 1 0 |
| 65 | /dev/fd0 /dosa vfat rw,user,noauto,nohide 0 0 |
| 66 | /dev/fd1 /dosb vfat rw,user,noauto,nohide 0 0 |
| 67 | # |
| 68 | /dev/cdrom /cdrom iso9660 ro,user,noauto,nohide 0 0 |
| 69 | /dev/hdb5 /redhat ext2 rw,root,noauto,nohide 0 0 #sssd |
| 70 | /dev/hdb6 /win2home ntfs rw,root,noauto,nohide 0 0# ssdsd |
| 71 | /dev/hdb7 /win2skul ntfs rw,root,noauto,nohide none 0 0 |
| 72 | none /dev/pts devpts gid=5,mode=620 0 0 |
| 73 | none /proc proc defaults 0 0 |
| 74 | EOF |
| 75 | |
| 76 | cat >$FILE.res <<EOF |
| 77 | [/dev/hdb3][/][ext2][defaults][1][0] |
| 78 | [/dev/hdb1][/dosc][hpfs][ro][1][0] |
| 79 | [/dev/fd0][/dosa][vfat][rw,user,noauto,nohide][0][0] |
| 80 | [/dev/fd1][/dosb][vfat][rw,user,noauto,nohide][0][0] |
| 81 | [/dev/cdrom][/cdrom][iso9660][ro,user,noauto,nohide][0][0] |
| 82 | [/dev/hdb5][/redhat][ext2][rw,root,noauto,nohide][0][0] |
| 83 | [/dev/hdb6][/win2home][ntfs][rw,root,noauto,nohide][0][0] |
Denis Vlasenko | 084266e | 2008-07-26 23:08:31 +0000 | [diff] [blame] | 84 | [/dev/hdb7][/win2skul][ntfs][rw,root,noauto,nohide][none][0 0] |
Denis Vlasenko | 2e157dd | 2008-07-19 09:27:19 +0000 | [diff] [blame] | 85 | [none][/dev/pts][devpts][gid=5,mode=620][0][0] |
| 86 | [none][/proc][proc][defaults][0][0] |
| 87 | EOF |
| 88 | |
Denis Vlasenko | 084266e | 2008-07-26 23:08:31 +0000 | [diff] [blame] | 89 | testing "parse polluted fstab" \ |
Denis Vlasenko | 2e157dd | 2008-07-19 09:27:19 +0000 | [diff] [blame] | 90 | "parse -n 6 -m 6 $FILE" \ |
| 91 | "`cat $FILE.res`\n" \ |
| 92 | "" \ |
| 93 | "" |
Denis Vlasenko | 9b366f4 | 2008-07-20 17:50:58 +0000 | [diff] [blame] | 94 | cp ../examples/inittab $FILE |
| 95 | cat >$FILE.res <<EOF |
| 96 | [][][sysinit][/etc/init.d/rcS] |
| 97 | [][][askfirst][-/bin/sh] |
| 98 | [tty2][][askfirst][-/bin/sh] |
| 99 | [tty3][][askfirst][-/bin/sh] |
| 100 | [tty4][][askfirst][-/bin/sh] |
| 101 | [tty4][][respawn][/sbin/getty 38400 tty5] |
| 102 | [tty5][][respawn][/sbin/getty 38400 tty6] |
| 103 | [][][restart][/sbin/init] |
| 104 | [][][ctrlaltdel][/sbin/reboot] |
| 105 | [][][shutdown][/bin/umount -a -r] |
| 106 | [][][shutdown][/sbin/swapoff -a] |
| 107 | EOF |
| 108 | |
Denis Vlasenko | 084266e | 2008-07-26 23:08:31 +0000 | [diff] [blame] | 109 | testing "parse inittab from examples" \ |
| 110 | "parse -n 4 -m 4 -f $((NORMAL - TRIM - COLLAPSE)) -d'#:' $FILE" \ |
Denis Vlasenko | 9b366f4 | 2008-07-20 17:50:58 +0000 | [diff] [blame] | 111 | "`cat $FILE.res`\n" \ |
| 112 | "" \ |
| 113 | "" |
| 114 | |
| 115 | cp ../examples/udhcp/udhcpd.conf $FILE |
| 116 | cat >$FILE.res <<EOF |
| 117 | [start][192.168.0.20] |
| 118 | [end][192.168.0.254] |
| 119 | [interface][eth0] |
| 120 | [opt][dns][192.168.10.2][192.168.10.10] |
| 121 | [option][subnet][255.255.255.0] |
| 122 | [opt][router][192.168.10.2] |
| 123 | [opt][wins][192.168.10.10] |
| 124 | [option][dns][129.219.13.81] |
| 125 | [option][domain][local] |
| 126 | [option][lease][864000] |
Denys Vlasenko | 9cf89cd | 2017-08-05 13:45:22 +0200 | [diff] [blame] | 127 | [option][msstaticroutes][10.0.0.0/8][10.127.0.1] |
| 128 | [option][staticroutes][10.0.0.0/8][10.127.0.1,][10.11.12.0/24][10.11.12.1] |
Denys Vlasenko | da94760 | 2011-06-18 09:29:21 +0200 | [diff] [blame] | 129 | [option][0x08][01020304] |
Denis Vlasenko | 9b366f4 | 2008-07-20 17:50:58 +0000 | [diff] [blame] | 130 | EOF |
| 131 | |
Denis Vlasenko | 084266e | 2008-07-26 23:08:31 +0000 | [diff] [blame] | 132 | testing "parse udhcpd.conf from examples" \ |
Denis Vlasenko | 9b366f4 | 2008-07-20 17:50:58 +0000 | [diff] [blame] | 133 | "parse -n 127 $FILE" \ |
| 134 | "`cat $FILE.res`\n" \ |
| 135 | "" \ |
| 136 | "" |
| 137 | |
Denis Vlasenko | 2e157dd | 2008-07-19 09:27:19 +0000 | [diff] [blame] | 138 | rm -f $FILE $FILE.res |
| 139 | |
| 140 | exit $FAILCOUNT |