File: asserts.h

package info (click to toggle)
vifm 0.14.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,252 kB
  • sloc: ansic: 179,567; sh: 5,445; makefile: 723; perl: 347; python: 76; xml: 26
file content (97 lines) | stat: -rw-r--r-- 2,510 bytes parent folder | download | duplicates (2)
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
#ifndef VIFM_TESTS__LUA__ASSERTS_H__
#define VIFM_TESTS__LUA__ASSERTS_H__

#include "../../src/lua/vlua.h"
#include "../../src/ui/statusbar.h"

/*
 * Assumption: <stic.h> is already included.
 *
 * These are macros so that other tests can use them by just including the
 * header.
 *
 * Macros name structure:
 *  - GLUA_     prefix means Lua code execution should succeed (Good)
 *  - BLUA_     prefix means Lua code execution should fail (Bad)
 *  - _EQ       suffix checks output match exactly (use "" for no output)
 *  - _STARTS   suffix checks that output starts with a string
 *  - _CONTAINS suffix checks that output contains a string
 *  - _ENDS     suffix checks that output ends with a string
 */

#define GLUA_EQ(vlua, expected_output, code) \
	do \
	{ \
		ui_sb_msg(""); \
		assert_success(vlua_run_string(vlua, code)); \
		assert_string_equal(expected_output, ui_sb_last()); \
	} \
	while(0)

#define GLUA_STARTS(vlua, expected_prefix, code) \
	do \
	{ \
		ui_sb_msg(""); \
		assert_success(vlua_run_string(vlua, code)); \
		assert_string_starts_with(expected_prefix, ui_sb_last()); \
	} \
	while(0)

#define GLUA_CONTAINS(vlua, expected_substr, code) \
	do \
	{ \
		ui_sb_msg(""); \
		assert_success(vlua_run_string(vlua, code)); \
		assert_string_contains(expected_substr, ui_sb_last()); \
	} \
	while(0)

#define GLUA_ENDS(vlua, expected_suffix, code) \
	do \
	{ \
		ui_sb_msg(""); \
		assert_success(vlua_run_string(vlua, code)); \
		assert_string_ends_with(expected_suffix, ui_sb_last()); \
	} \
	while(0)

#define BLUA_EQ(vlua, expected_output, code) \
	do \
	{ \
		ui_sb_msg(""); \
		assert_failure(vlua_run_string(vlua, code)); \
		assert_string_equal(expected_output, ui_sb_last()); \
	} \
	while(0)

#define BLUA_STARTS(vlua, expected_prefix, code) \
	do \
	{ \
		ui_sb_msg(""); \
		assert_failure(vlua_run_string(vlua, code)); \
		assert_string_starts_with(expected_prefix, ui_sb_last()); \
	} \
	while(0)

#define BLUA_CONTAINS(vlua, expected_substr, code) \
	do \
	{ \
		ui_sb_msg(""); \
		assert_failure(vlua_run_string(vlua, code)); \
		assert_string_contains(expected_substr, ui_sb_last()); \
	} \
	while(0)

#define BLUA_ENDS(vlua, expected_suffix, code) \
	do \
	{ \
		ui_sb_msg(""); \
		assert_failure(vlua_run_string(vlua, code)); \
		assert_string_ends_with(expected_suffix, ui_sb_last()); \
	} \
	while(0)

#endif /* VIFM_TESTS__LUA__ASSERTS_H__ */

/* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */
/* vim: set cinoptions+=t0 filetype=c : */