annotate src/testdir/test_assert.vim @ 8550:56d0eb96c25a v7.4.1565

commit https://github.com/vim/vim/commit/f1551964448607f8222de2d8f0992ea43eb2fe67 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Mar 15 12:55:58 2016 +0100 patch 7.4.1565 Problem: Crash when assert_equal() runs into a NULL string. Solution: Check for NULL. (Dominique) Add a test.
author Christian Brabandt <cb@256bit.org>
date Tue, 15 Mar 2016 13:00:11 +0100
parents 03e716299680
children 7d3548ae729d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7277
6600871bb38c commit https://github.com/vim/vim/commit/43345546ae63710441f066648b8485fb545b3801
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Test that the methods used for testing work.
6600871bb38c commit https://github.com/vim/vim/commit/43345546ae63710441f066648b8485fb545b3801
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2
7279
b5e9810b389d commit https://github.com/vim/vim/commit/683fa185a4b4ed7595e5942901548b8239ed5cdb
Christian Brabandt <cb@256bit.org>
parents: 7277
diff changeset
3 func Test_assert_false()
b5e9810b389d commit https://github.com/vim/vim/commit/683fa185a4b4ed7595e5942901548b8239ed5cdb
Christian Brabandt <cb@256bit.org>
parents: 7277
diff changeset
4 call assert_false(0)
7951
03e716299680 commit https://github.com/vim/vim/commit/3712792637516aea7acf76a11533be1066952820
Christian Brabandt <cb@256bit.org>
parents: 7852
diff changeset
5 call assert_false(v:false)
7277
6600871bb38c commit https://github.com/vim/vim/commit/43345546ae63710441f066648b8485fb545b3801
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 endfunc
6600871bb38c commit https://github.com/vim/vim/commit/43345546ae63710441f066648b8485fb545b3801
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7
7279
b5e9810b389d commit https://github.com/vim/vim/commit/683fa185a4b4ed7595e5942901548b8239ed5cdb
Christian Brabandt <cb@256bit.org>
parents: 7277
diff changeset
8 func Test_assert_true()
b5e9810b389d commit https://github.com/vim/vim/commit/683fa185a4b4ed7595e5942901548b8239ed5cdb
Christian Brabandt <cb@256bit.org>
parents: 7277
diff changeset
9 call assert_true(1)
b5e9810b389d commit https://github.com/vim/vim/commit/683fa185a4b4ed7595e5942901548b8239ed5cdb
Christian Brabandt <cb@256bit.org>
parents: 7277
diff changeset
10 call assert_true(123)
7951
03e716299680 commit https://github.com/vim/vim/commit/3712792637516aea7acf76a11533be1066952820
Christian Brabandt <cb@256bit.org>
parents: 7852
diff changeset
11 call assert_true(v:true)
7277
6600871bb38c commit https://github.com/vim/vim/commit/43345546ae63710441f066648b8485fb545b3801
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 endfunc
6600871bb38c commit https://github.com/vim/vim/commit/43345546ae63710441f066648b8485fb545b3801
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13
7279
b5e9810b389d commit https://github.com/vim/vim/commit/683fa185a4b4ed7595e5942901548b8239ed5cdb
Christian Brabandt <cb@256bit.org>
parents: 7277
diff changeset
14 func Test_assert_equal()
7277
6600871bb38c commit https://github.com/vim/vim/commit/43345546ae63710441f066648b8485fb545b3801
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 let s = 'foo'
7279
b5e9810b389d commit https://github.com/vim/vim/commit/683fa185a4b4ed7595e5942901548b8239ed5cdb
Christian Brabandt <cb@256bit.org>
parents: 7277
diff changeset
16 call assert_equal('foo', s)
7277
6600871bb38c commit https://github.com/vim/vim/commit/43345546ae63710441f066648b8485fb545b3801
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 let n = 4
7279
b5e9810b389d commit https://github.com/vim/vim/commit/683fa185a4b4ed7595e5942901548b8239ed5cdb
Christian Brabandt <cb@256bit.org>
parents: 7277
diff changeset
18 call assert_equal(4, n)
7277
6600871bb38c commit https://github.com/vim/vim/commit/43345546ae63710441f066648b8485fb545b3801
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 let l = [1, 2, 3]
7279
b5e9810b389d commit https://github.com/vim/vim/commit/683fa185a4b4ed7595e5942901548b8239ed5cdb
Christian Brabandt <cb@256bit.org>
parents: 7277
diff changeset
20 call assert_equal([1, 2, 3], l)
7277
6600871bb38c commit https://github.com/vim/vim/commit/43345546ae63710441f066648b8485fb545b3801
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 endfunc
7412
bc5de65e499a commit https://github.com/vim/vim/commit/2d820808cda15b3ad9fe674393d1f1e997453d9e
Christian Brabandt <cb@256bit.org>
parents: 7279
diff changeset
22
7675
eb9cc96138a3 commit https://github.com/vim/vim/commit/da5dcd936656f524dd0ae7cb2685245f07f5720f
Christian Brabandt <cb@256bit.org>
parents: 7412
diff changeset
23 func Test_assert_exception()
eb9cc96138a3 commit https://github.com/vim/vim/commit/da5dcd936656f524dd0ae7cb2685245f07f5720f
Christian Brabandt <cb@256bit.org>
parents: 7412
diff changeset
24 try
eb9cc96138a3 commit https://github.com/vim/vim/commit/da5dcd936656f524dd0ae7cb2685245f07f5720f
Christian Brabandt <cb@256bit.org>
parents: 7412
diff changeset
25 nocommand
eb9cc96138a3 commit https://github.com/vim/vim/commit/da5dcd936656f524dd0ae7cb2685245f07f5720f
Christian Brabandt <cb@256bit.org>
parents: 7412
diff changeset
26 catch
eb9cc96138a3 commit https://github.com/vim/vim/commit/da5dcd936656f524dd0ae7cb2685245f07f5720f
Christian Brabandt <cb@256bit.org>
parents: 7412
diff changeset
27 call assert_exception('E492:')
eb9cc96138a3 commit https://github.com/vim/vim/commit/da5dcd936656f524dd0ae7cb2685245f07f5720f
Christian Brabandt <cb@256bit.org>
parents: 7412
diff changeset
28 endtry
eb9cc96138a3 commit https://github.com/vim/vim/commit/da5dcd936656f524dd0ae7cb2685245f07f5720f
Christian Brabandt <cb@256bit.org>
parents: 7412
diff changeset
29
eb9cc96138a3 commit https://github.com/vim/vim/commit/da5dcd936656f524dd0ae7cb2685245f07f5720f
Christian Brabandt <cb@256bit.org>
parents: 7412
diff changeset
30 try
eb9cc96138a3 commit https://github.com/vim/vim/commit/da5dcd936656f524dd0ae7cb2685245f07f5720f
Christian Brabandt <cb@256bit.org>
parents: 7412
diff changeset
31 nocommand
eb9cc96138a3 commit https://github.com/vim/vim/commit/da5dcd936656f524dd0ae7cb2685245f07f5720f
Christian Brabandt <cb@256bit.org>
parents: 7412
diff changeset
32 catch
eb9cc96138a3 commit https://github.com/vim/vim/commit/da5dcd936656f524dd0ae7cb2685245f07f5720f
Christian Brabandt <cb@256bit.org>
parents: 7412
diff changeset
33 try
eb9cc96138a3 commit https://github.com/vim/vim/commit/da5dcd936656f524dd0ae7cb2685245f07f5720f
Christian Brabandt <cb@256bit.org>
parents: 7412
diff changeset
34 " illegal argument, get NULL for error
eb9cc96138a3 commit https://github.com/vim/vim/commit/da5dcd936656f524dd0ae7cb2685245f07f5720f
Christian Brabandt <cb@256bit.org>
parents: 7412
diff changeset
35 call assert_exception([])
eb9cc96138a3 commit https://github.com/vim/vim/commit/da5dcd936656f524dd0ae7cb2685245f07f5720f
Christian Brabandt <cb@256bit.org>
parents: 7412
diff changeset
36 catch
eb9cc96138a3 commit https://github.com/vim/vim/commit/da5dcd936656f524dd0ae7cb2685245f07f5720f
Christian Brabandt <cb@256bit.org>
parents: 7412
diff changeset
37 call assert_exception('E730:')
eb9cc96138a3 commit https://github.com/vim/vim/commit/da5dcd936656f524dd0ae7cb2685245f07f5720f
Christian Brabandt <cb@256bit.org>
parents: 7412
diff changeset
38 endtry
eb9cc96138a3 commit https://github.com/vim/vim/commit/da5dcd936656f524dd0ae7cb2685245f07f5720f
Christian Brabandt <cb@256bit.org>
parents: 7412
diff changeset
39 endtry
eb9cc96138a3 commit https://github.com/vim/vim/commit/da5dcd936656f524dd0ae7cb2685245f07f5720f
Christian Brabandt <cb@256bit.org>
parents: 7412
diff changeset
40 endfunc
eb9cc96138a3 commit https://github.com/vim/vim/commit/da5dcd936656f524dd0ae7cb2685245f07f5720f
Christian Brabandt <cb@256bit.org>
parents: 7412
diff changeset
41
7852
8818755d8326 commit https://github.com/vim/vim/commit/a542c680a8b42cb766e64d4ee7374ef4dacb7832
Christian Brabandt <cb@256bit.org>
parents: 7675
diff changeset
42 func Test_wrong_error_type()
8818755d8326 commit https://github.com/vim/vim/commit/a542c680a8b42cb766e64d4ee7374ef4dacb7832
Christian Brabandt <cb@256bit.org>
parents: 7675
diff changeset
43 let save_verrors = v:errors
8818755d8326 commit https://github.com/vim/vim/commit/a542c680a8b42cb766e64d4ee7374ef4dacb7832
Christian Brabandt <cb@256bit.org>
parents: 7675
diff changeset
44 let v:['errors'] = {'foo': 3}
8818755d8326 commit https://github.com/vim/vim/commit/a542c680a8b42cb766e64d4ee7374ef4dacb7832
Christian Brabandt <cb@256bit.org>
parents: 7675
diff changeset
45 call assert_equal('yes', 'no')
8818755d8326 commit https://github.com/vim/vim/commit/a542c680a8b42cb766e64d4ee7374ef4dacb7832
Christian Brabandt <cb@256bit.org>
parents: 7675
diff changeset
46 let verrors = v:errors
8818755d8326 commit https://github.com/vim/vim/commit/a542c680a8b42cb766e64d4ee7374ef4dacb7832
Christian Brabandt <cb@256bit.org>
parents: 7675
diff changeset
47 let v:errors = save_verrors
8818755d8326 commit https://github.com/vim/vim/commit/a542c680a8b42cb766e64d4ee7374ef4dacb7832
Christian Brabandt <cb@256bit.org>
parents: 7675
diff changeset
48 call assert_equal(type([]), type(verrors))
8818755d8326 commit https://github.com/vim/vim/commit/a542c680a8b42cb766e64d4ee7374ef4dacb7832
Christian Brabandt <cb@256bit.org>
parents: 7675
diff changeset
49 endfunc
8818755d8326 commit https://github.com/vim/vim/commit/a542c680a8b42cb766e64d4ee7374ef4dacb7832
Christian Brabandt <cb@256bit.org>
parents: 7675
diff changeset
50
8550
56d0eb96c25a commit https://github.com/vim/vim/commit/f1551964448607f8222de2d8f0992ea43eb2fe67
Christian Brabandt <cb@256bit.org>
parents: 7951
diff changeset
51 func Test_compare_fail()
56d0eb96c25a commit https://github.com/vim/vim/commit/f1551964448607f8222de2d8f0992ea43eb2fe67
Christian Brabandt <cb@256bit.org>
parents: 7951
diff changeset
52 let s:v = {}
56d0eb96c25a commit https://github.com/vim/vim/commit/f1551964448607f8222de2d8f0992ea43eb2fe67
Christian Brabandt <cb@256bit.org>
parents: 7951
diff changeset
53 let s:x = {"a": s:v}
56d0eb96c25a commit https://github.com/vim/vim/commit/f1551964448607f8222de2d8f0992ea43eb2fe67
Christian Brabandt <cb@256bit.org>
parents: 7951
diff changeset
54 let s:v["b"] = s:x
56d0eb96c25a commit https://github.com/vim/vim/commit/f1551964448607f8222de2d8f0992ea43eb2fe67
Christian Brabandt <cb@256bit.org>
parents: 7951
diff changeset
55 let s:w = {"c": s:x, "d": ''}
56d0eb96c25a commit https://github.com/vim/vim/commit/f1551964448607f8222de2d8f0992ea43eb2fe67
Christian Brabandt <cb@256bit.org>
parents: 7951
diff changeset
56 try
56d0eb96c25a commit https://github.com/vim/vim/commit/f1551964448607f8222de2d8f0992ea43eb2fe67
Christian Brabandt <cb@256bit.org>
parents: 7951
diff changeset
57 call assert_equal(s:w, '')
56d0eb96c25a commit https://github.com/vim/vim/commit/f1551964448607f8222de2d8f0992ea43eb2fe67
Christian Brabandt <cb@256bit.org>
parents: 7951
diff changeset
58 catch
56d0eb96c25a commit https://github.com/vim/vim/commit/f1551964448607f8222de2d8f0992ea43eb2fe67
Christian Brabandt <cb@256bit.org>
parents: 7951
diff changeset
59 call assert_exception('E724:')
56d0eb96c25a commit https://github.com/vim/vim/commit/f1551964448607f8222de2d8f0992ea43eb2fe67
Christian Brabandt <cb@256bit.org>
parents: 7951
diff changeset
60 call assert_true(v:errors[0] =~ "Expected NULL but got ''")
56d0eb96c25a commit https://github.com/vim/vim/commit/f1551964448607f8222de2d8f0992ea43eb2fe67
Christian Brabandt <cb@256bit.org>
parents: 7951
diff changeset
61 call remove(v:errors, 0)
56d0eb96c25a commit https://github.com/vim/vim/commit/f1551964448607f8222de2d8f0992ea43eb2fe67
Christian Brabandt <cb@256bit.org>
parents: 7951
diff changeset
62 endtry
56d0eb96c25a commit https://github.com/vim/vim/commit/f1551964448607f8222de2d8f0992ea43eb2fe67
Christian Brabandt <cb@256bit.org>
parents: 7951
diff changeset
63 endfunc
56d0eb96c25a commit https://github.com/vim/vim/commit/f1551964448607f8222de2d8f0992ea43eb2fe67
Christian Brabandt <cb@256bit.org>
parents: 7951
diff changeset
64
56d0eb96c25a commit https://github.com/vim/vim/commit/f1551964448607f8222de2d8f0992ea43eb2fe67
Christian Brabandt <cb@256bit.org>
parents: 7951
diff changeset
65
7412
bc5de65e499a commit https://github.com/vim/vim/commit/2d820808cda15b3ad9fe674393d1f1e997453d9e
Christian Brabandt <cb@256bit.org>
parents: 7279
diff changeset
66 func Test_user_is_happy()
bc5de65e499a commit https://github.com/vim/vim/commit/2d820808cda15b3ad9fe674393d1f1e997453d9e
Christian Brabandt <cb@256bit.org>
parents: 7279
diff changeset
67 smile
bc5de65e499a commit https://github.com/vim/vim/commit/2d820808cda15b3ad9fe674393d1f1e997453d9e
Christian Brabandt <cb@256bit.org>
parents: 7279
diff changeset
68 sleep 300m
bc5de65e499a commit https://github.com/vim/vim/commit/2d820808cda15b3ad9fe674393d1f1e997453d9e
Christian Brabandt <cb@256bit.org>
parents: 7279
diff changeset
69 endfunc