Luigi Santivetti | 0fdd470 | 2020-06-22 19:00:32 +0100 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # holder.sh - test |
| 4 | # |
| 5 | # Copyright 2019 Luigi Santivetti <luigi.santivetti@gmail.com> |
| 6 | |
| 7 | # Permission is hereby granted, free of charge, to any person obtaining a |
| 8 | # copy of this software and associated documentation files (the "Software"), |
| 9 | # to deal in the Software without restriction, including without limitation |
| 10 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 11 | # and/or sell copies of the Software, and to permit persons to whom the |
| 12 | # Software is furnished to do so, subject to the following conditions: |
| 13 | |
| 14 | # The above copyright notice and this permission notice (including the next |
| 15 | # paragraph) shall be included in all copies or substantial portions of the |
| 16 | # Software. |
| 17 | |
| 18 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 21 | # ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
| 22 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 23 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 24 | |
| 25 | # Test plain variable |
| 26 | _TEST1_VAR0_HOLDER_="test1_var0_holder" |
| 27 | |
| 28 | # Test variable externally defined within test1 module |
| 29 | _TEST1_VAR1_MODULE_="$mod_name_clash" |
| 30 | |
| 31 | # Test variable externally defined in foreign holder and composite |
| 32 | _TEST1_VAR2_EXTREF_="${_TEST2_VAR0_HOLDER_}-notnull" |
| 33 | |
| 34 | # Test variable externally defined in foreign module and composite |
| 35 | _TEST1_VAR3_EXTREF_="${_TEST2_VAR1_MODULE_}-notnull" |
| 36 | |
| 37 | # Test circular dependencies. Uncomment will cause validation to detect a loop |
| 38 | #_TEST1_VAR4_EXTREF_="${_TEST2_VAR4_HOLDER_}" |
| 39 | #_TEST1_VAR5_EXTREF_="${_TEST2_VAR5_MODULE_}" |
| 40 | |
| 41 | # Test variable externally defined in foreign holder |
| 42 | _TEST1_VAR6_EXTREF_="${_TEST2_VAR0_HOLDER_}" |
| 43 | |
| 44 | # Test variable externally defined in foreign module |
| 45 | _TEST1_VAR7_EXTREF_="${_TEST2_VAR1_MODULE_}" |
| 46 | |
| 47 | # Test command substitution with unescaped quote symbols |
| 48 | _TEST1_VAR8_CMDSUB_="text $(dirname "$(basename "$(dirname "$(pwd)")")")" |
| 49 | |
| 50 | # Test LHS validation. Uncomment will cause validation to detect invalid LHS |
| 51 | #_NOVALID_VAR9_LHS_="invalid LHS. First token must match module's name" |
| 52 | |
| 53 | # Test RHS validation. Uncomment will cause validation to detect multiple |
| 54 | # commands in line. |
| 55 | #_TEST1_VAR10_MULTIPLE_CMD_="legal RHS"; echo "Illegal continuation" |
| 56 | #_TEST1_VAR11_MULTIPLE_CMD_="legal RHS" && _TEST1_VAR12_="illegal continuation" |
| 57 | #_TEST1_VAR13_MULTIPLE_CMD_="legal RHS"; if :;then echo "true"; fi |
| 58 | |
| 59 | # Test if/else |
| 60 | if true; then |
| 61 | _TEST1_VAR14_="true" |
| 62 | else |
| 63 | _TEST1_VAR15_="false" |
| 64 | fi |
| 65 | |
| 66 | # Test incremental assignment |
| 67 | _TEST1_VAR16_="var15" |
| 68 | _TEST1_VAR16_+=" + var15" |
| 69 | |
| 70 | # FIXME: test for null value. Validation does not pick this up if in the same |
| 71 | # module. holder.sh will never trigger an error cause RHS isn't checked for |
| 72 | # local holder variables. |
| 73 | _TEST1_VAR17_="" |
| 74 | |
| 75 | # Test for reference null value. Uncomment will cause validation to detect a null |
| 76 | # value for a referenced variable. |
| 77 | #_TEST1_VAR17_="${_TEST2_VAR6_EXTREF_}" |
| 78 | |
| 79 | # Test for reference unbound. Uncomment will cause validation to detect an unbound |
| 80 | # variable. |
| 81 | #_TEST1_VAR18_="${_TEST2_VAR6_EXTREF_}" |
| 82 | |
| 83 | # Test for unknown variable name. Uncomment will cause validation to detect an |
| 84 | # unknown variable name on the RHS. |
| 85 | #_TEST1_VAR19_="${this_isn_t_a_valid_reference_name}" |
| 86 | |
| 87 | # Test for invalid module name. Uncomment will cause validation to detect an |
| 88 | # invalid module name. |
| 89 | #_TEST1_VAR20_="${_MODULEFOO_DOES_NOT_EXISTS_}" |