blob: 183394a2095067bdbe619fee52efbb504adba58b [file] [log] [blame]
Tomas Heinrichd2b04052010-03-09 14:09:24 +01001#!/bin/sh
2#
3# These are not ash tests, we use ash as a way to test lineedit!
4#
5# Copyright 2010 by Denys Vlasenko
6# Licensed under GPL v2, see file LICENSE for details.
7
8. ./testing.sh
9
Tomas Heinricha659b812010-04-29 13:43:39 +020010test -f "$bindir/.config" && . "$bindir/.config"
11
Denys Vlasenkoff0e8752010-05-10 04:16:43 +020012test x"CONFIG_SCRIPT" = x"y" || exit 0
13test x"CONFIG_HEXDUMP" = x"y" || exit 0
14test x"CONFIG_FEATURE_DEVPTS" = x"y" || exit 0
15
Tomas Heinrichd2b04052010-03-09 14:09:24 +010016# testing "test name" "options" "expected result" "file input" "stdin"
17
Tomas Heinricha659b812010-04-29 13:43:39 +020018if test x"$CONFIG_UNICODE_PRESERVE_BROKEN" = x"y"; then
19testing "One byte which is not valid unicode char followed by valid input" \
20 "script -q -c 'ash' /dev/null >/dev/null; cat ash.output" \
21 "\
2200000000 ff 2d 0a |.-.|
2300000003
24" \
25 "" \
26 "echo \xff- | hexdump -C >ash.output; exit; exit; exit; exit\n"
27
28testing "30 bytes which are not valid unicode chars followed by valid input" \
29 "script -q -c 'ash' /dev/null >/dev/null; cat ash.output" \
30 "\
3100000000 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
3200000010 ff ff ff ff ff ff ff ff ff ff ff ff ff ff 2d 0a |..............-.|
3300000020
34" \
35 "" \
36 "echo \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff- | hexdump -C >ash.output; exit; exit; exit; exit\n"
37else
Tomas Heinrichd2b04052010-03-09 14:09:24 +010038testing "One byte which is not valid unicode char followed by valid input" \
Denys Vlasenko58f108e2010-03-11 21:17:55 +010039 "script -q -c 'ash' /dev/null >/dev/null; cat ash.output" \
Tomas Heinrichd2b04052010-03-09 14:09:24 +010040 "\
4100000000 3f 2d 0a |?-.|
4200000003
43" \
44 "" \
Denys Vlasenko58f108e2010-03-11 21:17:55 +010045 "echo \xff- | hexdump -C >ash.output; exit; exit; exit; exit\n"
Tomas Heinrichd2b04052010-03-09 14:09:24 +010046
47testing "30 bytes which are not valid unicode chars followed by valid input" \
Denys Vlasenko58f108e2010-03-11 21:17:55 +010048 "script -q -c 'ash' /dev/null >/dev/null; cat ash.output" \
Tomas Heinrichd2b04052010-03-09 14:09:24 +010049 "\
5000000000 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f |????????????????|
5100000010 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 2d 0a |??????????????-.|
5200000020
53" \
54 "" \
Denys Vlasenko58f108e2010-03-11 21:17:55 +010055 "echo \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff- | hexdump -C >ash.output; exit; exit; exit; exit\n"
Tomas Heinricha659b812010-04-29 13:43:39 +020056fi
57
Tomas Heinrichd2b04052010-03-09 14:09:24 +010058
59# Not sure this behavior is perfect: we lose all invalid input which precedes
60# arrow keys and such. In this example, \xff\xff are lost
61testing "2 bytes which are not valid unicode chars followed by left arrow key" \
Denys Vlasenko58f108e2010-03-11 21:17:55 +010062 "script -q -c 'ash' /dev/null >/dev/null; cat ash.output" \
Tomas Heinrichd2b04052010-03-09 14:09:24 +010063 "\
6400000000 3d 2d 0a |=-.|
6500000003
66" \
67 "" \
Denys Vlasenko58f108e2010-03-11 21:17:55 +010068 "echo =+\xff\xff\x1b\x5b\x44- | hexdump -C >ash.output; exit; exit; exit; exit\n"
69
70# ash should see "echo \xff\n",pause -> execute it as "echo ?" (which is
71# not checked by the test), then read and execute the rest: "echo A | ..."
72# The bug was that ash was eating the beginning of "echo A" despite the pause.
73testing "Invalid unicode chars followed by a pause do not eat next chars" \
74 "{ echo -ne 'echo \xff\n'; sleep 1; echo -ne 'echo A | hexdump -C >ash.output; exit; exit; exit; exit\n'; } \
75 | script -q -c 'ash' /dev/null >/dev/null; cat ash.output" \
76 "\
7700000000 41 0a |A.|
7800000002
79" \
80 "" ""
81
82rm ash.output
Tomas Heinrichd2b04052010-03-09 14:09:24 +010083
84exit $FAILCOUNT