Show More
@@ -31,3 +31,62 b' writing tests:' | |||
|
31 | 31 | use hg diff | sed -e "s/\(+++ [a-zA-Z0-9_/.-]*\).*/\1/" \ |
|
32 | 32 | -e "s/\(--- [a-zA-Z0-9_/.-]*\).*/\1/" |
|
33 | 33 | to strip dates |
|
34 | ||
|
35 | You also need to be careful that the tests are portable from one platform | |
|
36 | to another. You're probably working on Linux, where the GNU toolchain has | |
|
37 | more (or different) functionality than on MacOS, *BSD, Solaris, AIX, etc. | |
|
38 | While testing on all platforms is the only sure-fire way to make sure that | |
|
39 | you've written portable code, here's a list of problems that have been | |
|
40 | found and fixed in the tests. Another, more comprehensive list may be | |
|
41 | found in the GNU Autoconf manual, online here: | |
|
42 | ||
|
43 | http://www.gnu.org/software/autoconf/manual/html_node/Portable-Shell.html | |
|
44 | ||
|
45 | sh: | |
|
46 | ||
|
47 | The Bourne shell is a very basic shell. /bin/sh on Linux is typically | |
|
48 | bash, which even in Bourne-shell mode has many features that Bourne shells | |
|
49 | on other Unix systems don't have (and even on Linux /bin/sh isn't | |
|
50 | guaranteed to be bash). You'll need to be careful about constructs that | |
|
51 | seem ubiquitous, but are actually not available in the least common | |
|
52 | denominator. While using another shell (ksh, bash explicitly, posix shell, | |
|
53 | etc.) explicitly may seem like another option, these may not exist in a | |
|
54 | portable location, and so are generally probably not a good idea. You may | |
|
55 | find that rewriting the test in python will be easier. | |
|
56 | ||
|
57 | - don't use pushd/popd; save the output of "pwd" and use "cd" in place of | |
|
58 | the pushd, and cd back to the saved pwd instead of popd. | |
|
59 | ||
|
60 | - don't use math expressions like let, (( ... )), or $(( ... )); use "expr" | |
|
61 | instead. | |
|
62 | ||
|
63 | grep: | |
|
64 | ||
|
65 | - don't use the -q option; redirect stdout to /dev/null instead. | |
|
66 | ||
|
67 | - don't use extended regular expressions with grep; use egrep instead, and | |
|
68 | don't escape any regex operators. | |
|
69 | ||
|
70 | sed: | |
|
71 | ||
|
72 | - make sure that the beginning-of-line matcher ("^") is at the very | |
|
73 | beginning of the expression -- it may not be supported inside parens. | |
|
74 | ||
|
75 | echo: | |
|
76 | ||
|
77 | - echo may interpret "\n" and print a newline; use printf instead if you | |
|
78 | want a literal "\n" (backslash + n). | |
|
79 | ||
|
80 | false: | |
|
81 | ||
|
82 | - false is guaranteed only to return a non-zero value; you cannot depend on | |
|
83 | it being 1. On Solaris in particular, /bin/false returns 255. Rewrite | |
|
84 | your test to not depend on a particular return value, or create a | |
|
85 | temporary "false" executable, and call that instead. | |
|
86 | ||
|
87 | diff: | |
|
88 | ||
|
89 | - don't use the -N option. There's no particularly good workaround short | |
|
90 | of writing a reasonably complicated replacement script, but substituting | |
|
91 | gdiff for diff if you can't rewrite the test not to need -N will probably | |
|
92 | do. |
General Comments 0
You need to be logged in to leave comments.
Login now