1+ include ("rsp/testing" )
2+ include ("rsp/debug" )
3+
4+ define_test_case(
5+ "Var Dump Test"
6+ LABELS "debug;var_dump;dump"
7+ )
8+
9+ # -------------------------------------------------------------------------------------------------------------- #
10+ # Actual tests
11+ # -------------------------------------------------------------------------------------------------------------- #
12+
13+ define_test("dumps 'undefined' when is not declared" "dumps_undefined" )
14+ function (dumps_undefined)
15+
16+ var_dump(OUTPUT result PROPERTIES foo)
17+
18+ string (STRIP "${result} " result)
19+ assert_string_equals("foo = (undefined)" "${result} " MESSAGE "Incorrect dump" )
20+ endfunction ()
21+
22+ define_test("can dump without property name" "dumps_without_prop_name" )
23+ function (dumps_without_prop_name)
24+
25+ var_dump(OUTPUT result WITHOUT_NAMES PROPERTIES foo)
26+
27+ string (STRIP "${result} " result)
28+ assert_string_equals("(undefined)" "${result} " MESSAGE "Incorrect dump" )
29+ endfunction ()
30+
31+ define_test("can dump string with length" "can_dump_str_width_length" )
32+ function (can_dump_str_width_length)
33+
34+ set (prop "foo" )
35+ var_dump(OUTPUT result WITHOUT_NAMES PROPERTIES prop)
36+
37+ string (STRIP "${result} " result)
38+ assert_string_equals("(string 3) \" ${prop} \" " "${result} " MESSAGE "Incorrect dump of string" )
39+ endfunction ()
40+
41+ define_test("can dump empty string" "can_dump_empty_str" )
42+ function (can_dump_empty_str)
43+
44+ set (prop "" )
45+ var_dump(OUTPUT result WITHOUT_NAMES PROPERTIES prop)
46+
47+ string (STRIP "${result} " result)
48+ assert_string_equals("(string 0) \"\" " "${result} " MESSAGE "Incorrect dump of empty string" )
49+ endfunction ()
50+
51+ define_test("can dump integer" "can_dump_int" )
52+ function (can_dump_int)
53+
54+ set (prop 42)
55+ var_dump(OUTPUT result WITHOUT_NAMES PROPERTIES prop)
56+
57+ string (STRIP "${result} " result)
58+ assert_string_equals("(int) ${prop} " "${result} " MESSAGE "Incorrect dump of integer" )
59+ endfunction ()
60+
61+ define_test("can dump float" "can_dump_float" )
62+ function (can_dump_float)
63+
64+ set (prop 42.1234)
65+ var_dump(OUTPUT result WITHOUT_NAMES PROPERTIES prop)
66+
67+ string (STRIP "${result} " result)
68+ assert_string_equals("(float) ${prop} " "${result} " MESSAGE "Incorrect dump of float" )
69+ endfunction ()
70+
71+ define_test("can dump boolean" "can_dump_bool" )
72+ function (can_dump_bool)
73+
74+ set (prop false )
75+ var_dump(OUTPUT result WITHOUT_NAMES PROPERTIES prop)
76+
77+ string (STRIP "${result} " result)
78+ assert_string_equals("(bool) ${prop} " "${result} " MESSAGE "Incorrect dump of boolean" )
79+ endfunction ()
80+
81+ define_test("can dump list" "can_dump_list" )
82+ function (can_dump_list)
83+
84+ set (prop "a;12;true" )
85+ var_dump(OUTPUT result WITHOUT_NAMES PROPERTIES prop)
86+
87+ string (STRIP "${result} " result)
88+
89+ # Debug
90+ # message("${result}")
91+
92+ assert_string_contains("${result} " "0: (string 1) \" a\" " MESSAGE "Incorrect list item" )
93+ assert_string_contains("${result} " "1: (int) 12" MESSAGE "Incorrect list item" )
94+ assert_string_contains("${result} " "2: (bool) true" MESSAGE "Incorrect list item" )
95+ endfunction ()
96+
97+ define_test("can ignore list" "can_ignore_list" )
98+ function (can_ignore_list)
99+
100+ set (prop "a;12;true" )
101+ var_dump(OUTPUT result WITHOUT_NAMES IGNORE_LIST PROPERTIES prop)
102+
103+ string (STRIP "${result} " result)
104+
105+ # Debug
106+ # message("${result}")
107+
108+ assert_string_contains("${result} " "(string 9) \" ${prop} \" " MESSAGE "Incorrect dump of list (as string)" )
109+ endfunction ()
110+
111+ define_test("does not attempt to dump 'nested' list" "does_not_dump_as_nested_list" )
112+ function (does_not_dump_as_nested_list)
113+
114+ # A different list...
115+ set (other_list "foo;bar" )
116+
117+ # In this list, a value corresponds to the "other_list" property, which
118+ # is a bit unlucky. Nevertheless, the var_dump SHOULD not attempt to treat
119+ # it as a "nested" list. Instead, it should see this a string value...
120+ set (prop "a;12;true;other_list" )
121+ var_dump(OUTPUT result WITHOUT_NAMES PROPERTIES prop)
122+
123+ string (STRIP "${result} " result)
124+
125+ # Debug
126+ # message("${result}")
127+
128+ assert_string_contains("${result} " "0: (string 1) \" a\" " MESSAGE "Incorrect list item" )
129+ assert_string_contains("${result} " "1: (int) 12" MESSAGE "Incorrect list item" )
130+ assert_string_contains("${result} " "2: (bool) true" MESSAGE "Incorrect list item" )
131+ assert_string_contains("${result} " "3: (string 10) \" other_list\" " MESSAGE "Incorrect list item" )
132+ endfunction ()
133+
134+ define_test("can dump command" "can_dump_cmd" )
135+ function (can_dump_cmd)
136+
137+ macro (my_macro)
138+ endmacro ()
139+
140+ function (my_function)
141+ endfunction ()
142+
143+ var_dump(OUTPUT result WITHOUT_NAMES PROPERTIES my_macro my_function)
144+
145+ string (STRIP "${result} " result)
146+
147+ assert_string_contains("${result} " "(command) my_macro()" MESSAGE "Incorrect dump of command (macro)" )
148+ assert_string_contains("${result} " "(command) my_function()" MESSAGE "Incorrect dump of command (function)" )
149+ endfunction ()
150+
151+ define_test("shows if variable is cached" "dump_shows_if_prop_cached" )
152+ function (dump_shows_if_prop_cached)
153+
154+ set (rsp_test_prop "foo" CACHE STRING "For testing only" )
155+ var_dump(OUTPUT result WITHOUT_NAMES PROPERTIES rsp_test_prop)
156+
157+ string (STRIP "${result} " result)
158+ assert_string_equals("(string 3, cached) \" ${rsp_test_prop} \" " "${result} " MESSAGE "Incorrect dump of cached state" )
159+
160+ unset (rsp_test_prop CACHE )
161+ endfunction ()
162+
163+ define_test("shows if environment variable" "dump_shows_if_env_prop" )
164+ function (dump_shows_if_env_prop)
165+
166+ set (ENV{rsp_test_env_prop} "/lorum/lipsum" )
167+ var_dump(OUTPUT result WITHOUT_NAMES PROPERTIES rsp_test_env_prop)
168+
169+ string (STRIP "${result} " result)
170+ assert_string_equals("(string 13, ENV) \" $ENV{rsp_test_env_prop} \" " "${result} " MESSAGE "Incorrect dump of env state" )
171+
172+ unset (ENV{rsp_test_env_prop})
173+ endfunction ()
0 commit comments