3
0

parse.tests 4.1 KB

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