Skip to content

Commit a8d23a7

Browse files
committed
Move template tests to template.test
1 parent efefcbc commit a8d23a7

File tree

3 files changed

+139
-114
lines changed

3 files changed

+139
-114
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ build: clean test $(ALL)
1313

1414
# cram is a python app, so 'easy_install/pip install cram' to run tests
1515
test:
16-
cram tests/main.test
16+
cram tests/*.test
1717

1818
clean:
1919
rm -f $(ALL)

tests/main.test

Lines changed: 0 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -364,119 +364,6 @@ Testing replace mode with path option:
364364
this is the last line
365365

366366

367-
Testing template mode:
368-
369-
$ cat > test.txt <<EOF
370-
> {{23 -}} < {{- 45}}
371-
> {{.Arg.Foobar}}
372-
> this is a testline
373-
> this is the second line
374-
> this is the third foobar line
375-
> this is the last line
376-
> EOF
377-
$ goreplace --mode=template -s Foobar -r ___xxx test.txt
378-
$ cat test.txt
379-
23<45
380-
___xxx
381-
this is a testline
382-
this is the second line
383-
this is the third foobar line
384-
this is the last line
385-
386-
Testing template mode with only env:
387-
388-
$ cat > test.txt <<EOF
389-
> {{23 -}} < {{- 45}}
390-
> {{.Env.Foobar}}
391-
> this is a testline
392-
> this is the second line
393-
> this is the third foobar line
394-
> this is the last line
395-
> EOF
396-
$ Foobar=barfoo goreplace --mode=template test.txt
397-
$ cat test.txt
398-
23<45
399-
barfoo
400-
this is a testline
401-
this is the second line
402-
this is the third foobar line
403-
this is the last line
404-
405-
Testing template mode with only env and empty var:
406-
407-
$ cat > test.txt <<EOF
408-
> {{23 -}} < {{- 45}}
409-
> begin{{.Env.Foobar}}end
410-
> this is a testline
411-
> this is the second line
412-
> this is the third foobar line
413-
> this is the last line
414-
> EOF
415-
$ Foobar= goreplace --mode=template test.txt
416-
$ cat test.txt
417-
23<45
418-
beginend
419-
this is a testline
420-
this is the second line
421-
this is the third foobar line
422-
this is the last line
423-
424-
425-
Testing template mode with only env and empty var:
426-
427-
$ cat > test.txt <<EOF
428-
> {{23 -}} < {{- 45}}
429-
> {{.Env.Foobar}}
430-
> this is a testline
431-
> this is the second line
432-
> this is the third foobar line
433-
> this is the last line
434-
> EOF
435-
$ Foobar="bar=foo" goreplace --mode=template test.txt
436-
$ cat test.txt
437-
23<45
438-
bar=foo
439-
this is a testline
440-
this is the second line
441-
this is the third foobar line
442-
this is the last line
443-
444-
Testing template mode with stdin:
445-
446-
$ cat > test.txt <<EOF
447-
> {{23 -}} < {{- 45}}
448-
> {{.Arg.Foobar}}
449-
> this is a testline
450-
> this is the second line
451-
> this is the third foobar line
452-
> this is the last line
453-
> EOF
454-
$ cat test.txt | goreplace --mode=template --stdin -s Foobar -r ___xxx
455-
23<45
456-
___xxx
457-
this is a testline
458-
this is the second line
459-
this is the third foobar line
460-
this is the last line
461-
462-
Testing template mode with stdin:
463-
464-
$ cat > test.txt.tmpl <<EOF
465-
> {{23 -}} < {{- 45}}
466-
> {{.Arg.Foobar}}
467-
> this is a testline
468-
> this is the second line
469-
> this is the third foobar line
470-
> this is the last line
471-
> EOF
472-
$ goreplace --mode=template -s Foobar -r ___xxx --output-strip-ext=.tmpl test.txt.tmpl
473-
$ cat test.txt
474-
23<45
475-
___xxx
476-
this is a testline
477-
this is the second line
478-
this is the third foobar line
479-
this is the last line
480367

481368

482369

tests/template.test

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
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

Comments
 (0)