xref: /src/contrib/lutok/debug_test.cpp (revision c697fb7f7cc9bedc5beee44d35b771c4e87b335a)
14b2c3eb9SBrooks Davis // Copyright 2011 Google Inc.
24b2c3eb9SBrooks Davis // All rights reserved.
34b2c3eb9SBrooks Davis //
44b2c3eb9SBrooks Davis // Redistribution and use in source and binary forms, with or without
54b2c3eb9SBrooks Davis // modification, are permitted provided that the following conditions are
64b2c3eb9SBrooks Davis // met:
74b2c3eb9SBrooks Davis //
84b2c3eb9SBrooks Davis // * Redistributions of source code must retain the above copyright
94b2c3eb9SBrooks Davis //   notice, this list of conditions and the following disclaimer.
104b2c3eb9SBrooks Davis // * Redistributions in binary form must reproduce the above copyright
114b2c3eb9SBrooks Davis //   notice, this list of conditions and the following disclaimer in the
124b2c3eb9SBrooks Davis //   documentation and/or other materials provided with the distribution.
134b2c3eb9SBrooks Davis // * Neither the name of Google Inc. nor the names of its contributors
144b2c3eb9SBrooks Davis //   may be used to endorse or promote products derived from this software
154b2c3eb9SBrooks Davis //   without specific prior written permission.
164b2c3eb9SBrooks Davis //
174b2c3eb9SBrooks Davis // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
184b2c3eb9SBrooks Davis // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
194b2c3eb9SBrooks Davis // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
204b2c3eb9SBrooks Davis // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
214b2c3eb9SBrooks Davis // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
224b2c3eb9SBrooks Davis // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
234b2c3eb9SBrooks Davis // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
244b2c3eb9SBrooks Davis // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
254b2c3eb9SBrooks Davis // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
264b2c3eb9SBrooks Davis // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
274b2c3eb9SBrooks Davis // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
284b2c3eb9SBrooks Davis 
294b2c3eb9SBrooks Davis #include "debug.hpp"
304b2c3eb9SBrooks Davis 
314b2c3eb9SBrooks Davis #include <atf-c++.hpp>
324b2c3eb9SBrooks Davis #include <lua.hpp>
334b2c3eb9SBrooks Davis 
344b2c3eb9SBrooks Davis #include "state.ipp"
354b2c3eb9SBrooks Davis #include "test_utils.hpp"
364b2c3eb9SBrooks Davis 
374b2c3eb9SBrooks Davis 
384b2c3eb9SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(get_info);
ATF_TEST_CASE_BODY(get_info)394b2c3eb9SBrooks Davis ATF_TEST_CASE_BODY(get_info)
404b2c3eb9SBrooks Davis {
414b2c3eb9SBrooks Davis     lutok::state state;
424b2c3eb9SBrooks Davis     ATF_REQUIRE(luaL_dostring(raw(state), "\n\nfunction hello() end\n"
434b2c3eb9SBrooks Davis                               "return hello") == 0);
444b2c3eb9SBrooks Davis     lutok::debug debug;
454b2c3eb9SBrooks Davis     debug.get_info(state, ">S");
464b2c3eb9SBrooks Davis     ATF_REQUIRE_EQ(3, debug.line_defined());
474b2c3eb9SBrooks Davis }
484b2c3eb9SBrooks Davis 
494b2c3eb9SBrooks Davis 
504b2c3eb9SBrooks Davis ATF_TEST_CASE_WITHOUT_HEAD(get_stack);
ATF_TEST_CASE_BODY(get_stack)514b2c3eb9SBrooks Davis ATF_TEST_CASE_BODY(get_stack)
524b2c3eb9SBrooks Davis {
534b2c3eb9SBrooks Davis     lutok::state state;
544b2c3eb9SBrooks Davis     ATF_REQUIRE(luaL_dostring(raw(state), "error('Hello')") == 1);
554b2c3eb9SBrooks Davis     lutok::debug debug;
564b2c3eb9SBrooks Davis     debug.get_stack(state, 0);
574b2c3eb9SBrooks Davis     lua_pop(raw(state), 1);
584b2c3eb9SBrooks Davis     // Not sure if we can actually validate anything here, other than we did not
594b2c3eb9SBrooks Davis     // crash... (because get_stack only is supposed to update internal values of
604b2c3eb9SBrooks Davis     // the debug structure).
614b2c3eb9SBrooks Davis }
624b2c3eb9SBrooks Davis 
634b2c3eb9SBrooks Davis 
ATF_INIT_TEST_CASES(tcs)644b2c3eb9SBrooks Davis ATF_INIT_TEST_CASES(tcs)
654b2c3eb9SBrooks Davis {
664b2c3eb9SBrooks Davis     ATF_ADD_TEST_CASE(tcs, get_info);
674b2c3eb9SBrooks Davis     ATF_ADD_TEST_CASE(tcs, get_stack);
684b2c3eb9SBrooks Davis }
69