def run_test(): GPS.execute_action("open Files") buf = GPS.EditorBuffer.get(GPS.File('main.adb')) yield wait_idle() entry = get_widget_by_name("Files_View_Directory") entry.set_text(os.path.join(GPS.Project.root().file().directory(), "src")) yield wait_tasks() fview = get_widget_by_name("File Explorer Tree") t = Tree(get_widget_by_name("File Explorer Tree")) t.expand_by_name(column=1, value='src') t.expand_by_name(column=1, value='d1') t.expand_by_name(column=1, value='d3') yield timeout(100) t.expand_by_name(column=1, value='x1') yield timeout(100) d = dump_expanded(fview, 1) gps_assert(d, expected, "Wrong contents of the files view") GPS.execute_action("refresh files view") yield wait_idle() yield timeout(100) d = dump_expanded(fview, 1) gps_assert(d, expected, "Wrong contents of the files view")
def run_test(): GPS.execute_action("open Files") buf = GPS.EditorBuffer.get(GPS.File('main.adb')) yield wait_idle() entry = get_widget_by_name("Files_View_Directory") entry.set_text(os.path.join(GPS.Project.root().file().directory(), "b")) yield wait_tasks() explorer = get_widget_by_name("File Explorer Tree") d = dump_tree_model(explorer.get_model(), 1) gps_assert(d, ['b', ['b.adb', 'b.ads']], "Wrong contents of the files view")
def driver(): e = Project_Properties_Editor() yield e.open_and_yield(wait_scan=True) page = e.get_page('Build/Toolchain') compiler_entry = get_widget_by_name("gnat_driver_tool", page) gps_assert(compiler_entry.get_text(), "gnat", "native target is overriding") yield e.cancel()
def driver(): yield timeout(1000) als = GPS.LanguageServer.get_by_language_name("Ada") b = GPS.EditorBuffer.get(GPS.File("main.adb")) b.current_view().goto(b.at(4, 5)) yield hook('language_server_response_processed') GPS.execute_action("Entity called by") yield hook('language_server_response_processed') yield timeout(1000) call_tree = get_widget_by_name("Call Graph Tree") selection = call_tree.get_selection() selection.unselect_all() model = call_tree.get_model() selection.select_iter(model.iter_nth_child(model.get_iter_first(), 0)) GPS.execute_action("calltree expand selected") yield hook('language_server_response_processed') expected = [ 'Foo is called by ', [ 'Foo', ['Foo', ['computing...'], 'Main', ['computing...']], 'Main', ['computing...'] ] ] yield timeout(1000) gps_assert(expected, dump_tree_model(model, 0), "The model didn't contain the expected text") # Now verify that double-clicking on the row that lists 'Main' # correctly open its editor and selects it. GPS.execute_action("close all editors") yield wait_tasks(other_than=known_tasks) click_in_tree(call_tree, path=Gtk.TreePath("0:0:1"), button=1, events=double_click_events) yield wait_idle() buffer = GPS.EditorBuffer.get() gps_assert( buffer.file(), GPS.File("main.adb"), "double-clicking on a Call Trees row should open an " + "editor for the clicked entity") gps_assert((buffer.selection_start(), buffer.selection_end()), (buffer.at(2, 11), buffer.at(2, 15)), "Main should be selected in main.adb after double-clicking " + "on its row in the Call Trees")
def driver(): prj_view = Project_View() yield prj_view.open_and_yield() explorer = prj_view.dialog explorer.expand_all() filt = get_widget_by_name("Project Explorer Filter") filt.set_text("be") yield hook("filter_view_changed") dump = dump_tree_model(explorer.get_model(), 1) gps_assert(dump, ['p', ['src1', ['beau.adb']]], "Project view content wrong after filtering") filt.set_text("") yield wait_tasks() dump = dump_tree_model(explorer.get_model(), 1) GPS.Console().write(str(dump)) gps_assert(dump, ['p', ['src1', ['beau.adb'], 'src2', ['nico.adb'], '.']], "Project view content wrong after removing the filter text")
def driver(): prj_view = Project_View() yield prj_view.open_and_yield() explorer = prj_view.dialog dump = dump_tree_model(explorer.get_model(), 1) gps_assert(dump, ['p', ['.', ['beau.adb', 'nico.adb'], '.']], "Initial project view contents wrong") filt = get_widget_by_name("Project Explorer Filter") filt.set_text("be") yield hook("filter_view_changed") dump = dump_tree_model(explorer.get_model(), 1) gps_assert(dump, ['p', ['.', ['beau.adb'], '.']], "Project view content wrong after filtering") GPS.execute_action("reload project") yield wait_tasks() dump = dump_tree_model(explorer.get_model(), 1) gps_assert(dump, ['p', ['.', ['beau.adb'], '.']], "Project view not filtered properly after reload")
def driver(): # Open an editor and go to a line where there's a code action b = GPS.EditorBuffer.get(GPS.File("main.c")) v = b.current_view() v.goto(b.at(5, 8)) # Wait until the language server has responded to the codeAction request yield wait_language_server("textDocument/codeAction", "C") # Verify that one codeAction message has been created m = GPS.Message.list() gps_assert(len(m), 1, "there should be one message at this point") gps_assert(m[0].get_category(), "_internal_code_actions", "we have a message, but not in the expected category") # Click on the side action b.click_on_side_icon(5, 1, "gps-codefix") # Allow a timeout for the asynchronous popup of the menu yield timeout(1000) menu = get_widget_by_name("gnatstudio_code_actions_menu") gps_assert(menu is not None, True, "no menu found") # Check that the menu contains the "Name parameters" action item = menu.get_children()[0] gps_assert(item.get_label(), "Expand macro 'FOO'", "the menu item doesn' have the right title") # Now activate the menu item and wait for the application of the edits item.activate() yield wait_language_server("workspace/executeCommand", "C") # Check that the edits have been received gps_assert( b.get_chars(b.at(5, 1), b.at(6, 1)).strip(), 'if (0 > 2)', "edits not received") yield wait_language_server("textDocument/codeAction", "C") m = GPS.Message.list(category="_internal_code_actions") gps_assert(len(m), 0, "there should be no code action message")
def driver(): GPS.Preference("explorer-hierarchical-directories").set("True") yield wait_tasks() prj_view = Project_View() yield prj_view.open_and_yield() tree = prj_view.dialog path = find_in_tree(tree, column=1, key='A') tree.expand_row(path, open_all=False) path = find_in_tree(tree, column=1, key='B') tree.expand_row(path, open_all=False) yield wait_idle() d1 = dump_tree_model(tree.get_model(), 1) gps_assert(d1, expected, "Wrong hierarchi") filt = get_widget_by_name("Project Explorer Filter") filt.set_text("lib") yield wait_tasks() d2 = dump_tree_model(tree.get_model(), 1) gps_assert(d2,filtered,"Wrong filtered")
def driver(): # Open bla.adb, goto declaration of "Create" b = GPS.EditorBuffer.get(GPS.File("bla.adb")) b.current_view().goto(b.at(6, 16)) GPS.execute_action("goto declaration") yield wait_tasks(other_than=known_tasks) # Sanity check that we're on the runtime file b2 = GPS.EditorBuffer.get() gps_assert(os.path.basename(b2.file().name()), "a-textio.ads", "goto declaration didn't work") # Run "is called by" GPS.execute_action("Entity called by") yield hook('language_server_response_processed') yield timeout(1000) # Verify that the call tree does show the call location in "Bla" call_tree = get_widget_by_name("Call Graph Tree") model = call_tree.get_model() gps_assert(dump_tree_model(model, 0), ['Create is called by ', ['Bla', ['computing...']]], "The model didn't contain the expected result")
def driver(): # Launch a fuzzing session yield idle_modal_dialog( lambda: GPS.execute_action("gnatfuzz fuzz workflow")) yield wait_for_mdi_child("gnatfuzz fuzz") dialog = get_window_by_title("gnatfuzz fuzz") get_button_from_label("Execute", dialog).clicked() yield wait_for_mdi_child("Fuzz Crashes") view = get_widget_by_name("fuzz_crash_list_view") model = view.get_model() # Wait 20 seconds at most, until messages appear in the "Fuzz crashes" view time_waited = 0 while time_waited < MAX_TIME_MS: if len(model) > 0: break yield timeout(INCREMENTS_MS) time_waited += INCREMENTS_MS # Test the contents of the model: presence of the crash... gps_assert(model[0][0], "1 (Crash)", "wrong contents in the first row") # ... and the fact that the faulty parameter (causing integer overflow) # is properly found by the fuzzer and displayed in the view. gps_assert( int(model[0, 0][1]), 2**31 - 1, "wrong value for the parameter which causes the crash", ) # We can stop fuzzing now that we've had one crash GPS.execute_action("gnatfuzz fuzz workflow") # Click in the view to launch a debug workflow click_in_tree(view, path="0", events=double_click_events) # Wait 20 seconds at most, until we have the right data in the debugger view debugger_text = None time_waited = 0 expected_text = "Y := X + 1" while time_waited < MAX_TIME_MS: yield timeout(INCREMENTS_MS) time_waited += INCREMENTS_MS d = None try: d = GPS.Debugger.get() except GPS.Exception: pass if d is None: continue debugger_text = d.get_console().get_text() # The debugger console should contain this if expected_text in debugger_text: break gps_assert(expected_text in debugger_text, True, f"{expected_text} didn't appear in output:\n{debugger_text}") # Quit the debugger GPS.execute_action("terminate all debuggers") yield wait_idle() # Restart a fuzz session... yield idle_modal_dialog( lambda: GPS.execute_action("gnatfuzz fuzz workflow")) yield wait_for_mdi_child("gnatfuzz fuzz") dialog = get_window_by_title("gnatfuzz fuzz") get_button_from_label("Execute", dialog).clicked() # ... and kill it immediately yield timeout(100) GPS.execute_action("gnatfuzz fuzz workflow") # And verify that the Fuzz crashes view is empty gps_assert(len(model), 0, "The Fuzz crashes view should clear when starting a session")