|
| 1 | +Go Replace tests: |
| 2 | + |
| 3 | + $ CURRENT="$(pwd)" |
| 4 | + $ cd "$TESTDIR/../" |
| 5 | + $ go build -o goreplace |
| 6 | + $ cd "$CURRENT" |
| 7 | + $ alias goreplace="$TESTDIR/../goreplace" |
| 8 | + |
| 9 | +Exec test: |
| 10 | + |
| 11 | + $ goreplace -h > /dev/null |
| 12 | + [1] |
| 13 | + |
| 14 | + |
| 15 | +Testing template mode: |
| 16 | + |
| 17 | + $ cat > test.txt <<EOF |
| 18 | + > {{23 -}} < {{- 45}} |
| 19 | + > {{.Arg.Foobar}} |
| 20 | + > this is a testline |
| 21 | + > this is the second line |
| 22 | + > this is the third foobar line |
| 23 | + > this is the last line |
| 24 | + > EOF |
| 25 | + $ goreplace --mode=template -s Foobar -r ___xxx test.txt |
| 26 | + $ cat test.txt |
| 27 | + 23<45 |
| 28 | + ___xxx |
| 29 | + this is a testline |
| 30 | + this is the second line |
| 31 | + this is the third foobar line |
| 32 | + this is the last line |
| 33 | + |
| 34 | +Testing template mode with only env: |
| 35 | + |
| 36 | + $ cat > test.txt <<EOF |
| 37 | + > {{23 -}} < {{- 45}} |
| 38 | + > {{.Env.Foobar}} |
| 39 | + > this is a testline |
| 40 | + > this is the second line |
| 41 | + > this is the third foobar line |
| 42 | + > this is the last line |
| 43 | + > EOF |
| 44 | + $ Foobar=barfoo goreplace --mode=template test.txt |
| 45 | + $ cat test.txt |
| 46 | + 23<45 |
| 47 | + barfoo |
| 48 | + this is a testline |
| 49 | + this is the second line |
| 50 | + this is the third foobar line |
| 51 | + this is the last line |
| 52 | + |
| 53 | +Testing template mode with only env and empty var: |
| 54 | + |
| 55 | + $ cat > test.txt <<EOF |
| 56 | + > {{23 -}} < {{- 45}} |
| 57 | + > begin{{.Env.Foobar}}end |
| 58 | + > this is a testline |
| 59 | + > this is the second line |
| 60 | + > this is the third foobar line |
| 61 | + > this is the last line |
| 62 | + > EOF |
| 63 | + $ Foobar= goreplace --mode=template test.txt |
| 64 | + $ cat test.txt |
| 65 | + 23<45 |
| 66 | + beginend |
| 67 | + this is a testline |
| 68 | + this is the second line |
| 69 | + this is the third foobar line |
| 70 | + this is the last line |
| 71 | + |
| 72 | + |
| 73 | +Testing template mode with only env and empty var: |
| 74 | + |
| 75 | + $ cat > test.txt <<EOF |
| 76 | + > {{23 -}} < {{- 45}} |
| 77 | + > {{.Env.Foobar}} |
| 78 | + > this is a testline |
| 79 | + > this is the second line |
| 80 | + > this is the third foobar line |
| 81 | + > this is the last line |
| 82 | + > EOF |
| 83 | + $ Foobar="bar=foo" goreplace --mode=template test.txt |
| 84 | + $ cat test.txt |
| 85 | + 23<45 |
| 86 | + bar=foo |
| 87 | + this is a testline |
| 88 | + this is the second line |
| 89 | + this is the third foobar line |
| 90 | + this is the last line |
| 91 | + |
| 92 | +Testing template mode with stdin: |
| 93 | + |
| 94 | + $ cat > test.txt <<EOF |
| 95 | + > {{23 -}} < {{- 45}} |
| 96 | + > {{.Arg.Foobar}} |
| 97 | + > this is a testline |
| 98 | + > this is the second line |
| 99 | + > this is the third foobar line |
| 100 | + > this is the last line |
| 101 | + > EOF |
| 102 | + $ cat test.txt | goreplace --mode=template --stdin -s Foobar -r ___xxx |
| 103 | + 23<45 |
| 104 | + ___xxx |
| 105 | + this is a testline |
| 106 | + this is the second line |
| 107 | + this is the third foobar line |
| 108 | + this is the last line |
| 109 | + |
| 110 | +Testing template mode with stdin: |
| 111 | + |
| 112 | + $ cat > test.txt.tmpl <<EOF |
| 113 | + > {{23 -}} < {{- 45}} |
| 114 | + > {{.Arg.Foobar}} |
| 115 | + > this is a testline |
| 116 | + > this is the second line |
| 117 | + > this is the third foobar line |
| 118 | + > this is the last line |
| 119 | + > EOF |
| 120 | + $ goreplace --mode=template -s Foobar -r ___xxx --output-strip-ext=.tmpl test.txt.tmpl |
| 121 | + $ cat test.txt |
| 122 | + 23<45 |
| 123 | + ___xxx |
| 124 | + this is a testline |
| 125 | + this is the second line |
| 126 | + this is the third foobar line |
| 127 | + this is the last line |
| 128 | + |
| 129 | +Testing template with functions: |
| 130 | + |
| 131 | + $ cat > test.txt <<EOF |
| 132 | + > {{env "FOO"}} |
| 133 | + > {{env "bar"}} |
| 134 | + > EOF |
| 135 | + $ FOO=bar bar=FOO goreplace --mode=template -s Foobar -r ___xxx test.txt |
| 136 | + $ cat test.txt |
| 137 | + bar |
| 138 | + FOO |
0 commit comments