File: example_tests.sh

package info (click to toggle)
ssshtest 0.0%2Bgit20220105.0d6df3d-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 224 kB
  • sloc: sh: 496; makefile: 3
file content (105 lines) | stat: -rwxr-xr-x 2,994 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash

source ssshtest

STOP_ON_FAIL=0

#--- assert_in_stdout
# Success
run test_in_stdout python3 -c "print('example assert_in_stdout success')"
assert_in_stdout "example"

# Fails because there is nothing in stdout
run test_in_stdout python3 -c "import sys; sys.stderr.write('example assert_in_stdout failure')"
assert_in_stdout "example"

# Fails because "simple test" is not in stdout
run test_in_stdout python3 -c "print('example assert_in_stdout success')"
assert_in_stdout "simple test"


#--- assert_in_stderr
# Success
run test_in_stderr python3 -c "import sys; sys.stderr.write('example assert_in_stderr success')"
assert_in_stderr "example" 

# Fails because there is nothing in stderr
run test_in_stderr python3 -c "print('example assert_in_stderr failure')"
assert_in_stderr "example" 

# Fails because "simple test" is not in stderr
run test_in_stderr python3 -c "import sys; sys.stderr.write('example assert_in_stderr success')"
assert_in_stderr "simple test" 

#--- assert_stdout
# Success
run test_stdout python3 -c "print('example assert_stdout success')"
assert_stdout 

# Fails because there is nothing in stdout
run test_stdout python3 -c "import sys; sys.stderr.write('example assert_stdout failure')"
assert_stdout 

#--- assert_stderr
# Success
run test_stderr python3 -c "import sys; sys.stderr.write('example assert_stderr success')"
assert_stderr 

# Fails because there is nothing in stderr
run test_stderr python3 -c "print('example assert_stderr failure')"
assert_stderr 

#assert_no_stdout
# Success
run test_no_stdout python3 -c "import sys; sys.stderr.write('example assert_no_stdout success')"
assert_no_stdout 

# Fails because there is something in stdout
run test_no_stdout python3 -c "print('example assert_no_stdout failure')"
assert_no_stdout 

#-- assert_no_stderr
# Success
run test_no_stderr python3 -c "print('example assert_no_stderr success')"
assert_no_stderr 

# Fails because there is something in stderr
run test_no_stderr python3 -c "import sys; sys.stderr.write('example assert_no_stderr failure')"
assert_no_stderr 

#--assert_exit_code
# Success
run test_exit_code python3 -c "print(1);"
assert_exit_code $EX_OK 

run test_exit_code python3 -c "import sys; sys.exit(66);"
assert_exit_code $EX_NOINPUT 

# Fails because the error code is wrong
run test_exit_code python3 -c "import sys; sys.exit(66);"
assert_exit_code $EX_USAGE 

#assert_equal - numbers
# Success
touch test.out
run test_assert_equal python3 -c "f = open('test.out','w'); f.write('1\n2\n3\n');f.close();"
assert_equal "$(cat test.out | wc -l)" 3 
assert_equal "$(cat test.out | wc -l | awk '{print $1;}')" 3 
# Failture
assert_equal "$(cat test.out | wc -l | awk '{print $1;}')" 4 
rm -f test.out

#using STDOUT_FILE
run use_stdout_file python3 -c "print('1\n2\n3');"
assert_equal "$(cat $STDOUT_FILE | wc -l)" 3 
assert_no_stderr
#assert_no_stdout

fn() {
	echo "hello" | head
	echo "err22" 1>&2
}

run use_pipes fn
assert_in_stderr "err22"
assert_in_stdout "hello"