def driver(): b = GPS.EditorBuffer.get(GPS.File("main.adb")) b.current_view().goto(b.at(4, 7)) yield wait_tasks(other_than=known_tasks) # First verify that the navigation does *not* work GPS.execute_action('goto declaration') # At this point "language_server_response_processed" shouldn't work, # timeout instead yield timeout(500) current_buf = GPS.EditorBuffer.get() gps_assert(current_buf.file(), GPS.File('main.adb'), "'goto declaration' should not have worked at this point") # Now set the project path and reload the project GPS.setenv("GPR_PROJECT_PATH", os.path.join(GPS.pwd(), "subdir")) # Restart the language server GPS.LanguageServer.get_by_language_name("Ada").restart() GPS.Project.load("p.gpr") yield timeout(1000) # Verify that the navigation works now b = GPS.EditorBuffer.get(GPS.File("main.adb")) b.current_view().goto(b.at(4, 7)) GPS.execute_action('goto declaration') yield timeout(500) gps_assert(GPS.EditorBuffer.get().file(), GPS.File('foo.ads'), "'goto declaration' did not open the right file")
def driver(): buf = GPS.EditorBuffer.get(GPS.File("hello.adb")) view = buf.current_view() expected_orig = buf.get_chars() # Select a bit buf.select(buf.at(5, 3), buf.at(6, 6)) yield timeout(200) # get the low-level textview v = pygps.get_widgets_by_type(Gtk.TextView, view.pywidget())[0] # simulate a click at coordinates 40, 5: regardless of the font, # this is somewhere on the first line, well past the last character win = v.get_window(Gtk.TextWindowType.TEXT) click_in_widget(window=win, x=40, y=5, button=2) yield timeout(200) # Verify that paste happend gps_assert(buf.get_chars(), expected_after_click, """Middle click paste didn't happen at the right place""") # Verify noncorruption after Undo buf.undo() gps_assert(buf.get_chars(), expected_orig, """Undo didn't restore the right contents""")
def driver(): # type 'foo' in the omnisearch yield wait_tasks() w = pygps.get_widget_by_name('global_search') w.get_toplevel().grab_focus() yield wait_idle() w.grab_focus() yield wait_idle() w.set_text("foo") yield timeout(1000) popup = pygps.get_widget_by_name('global_search-results-list') results_tree = pygps.get_widgets_by_type(Gtk.TreeView, popup)[0] # select "foo.adb" file click_in_tree(results_tree, path="0", column=1) yield timeout(1000) if not GPS.EditorBuffer.get().file().name().endswith("foo.adb"): simple_error("foo.adb is not opened") # retype 'foo' in the omnisearch w.get_toplevel().grab_focus() yield wait_idle() w.grab_focus() yield wait_idle() w.set_text("foo") yield timeout(1000) # check whether we have result from the History provider popup = pygps.get_widget_by_name('global_search-results-list') results_tree = pygps.get_widgets_by_type(Gtk.TreeView, popup)[0] result = dump_tree_model(results_tree.get_model(), 3) gps_assert("History (1)" in result, True, "wrong omnisearch result")
def driver(): buf = GPS.EditorBuffer.get(GPS.File("test_fold.adb")) yield wait_language_server("textDocument/foldingRange") buf.select(buf.at(10, 11), buf.at(15, 11)) GPS.execute_action("Cut to Clipboard") yield wait_language_server("textDocument/foldingRange") buf.at(7, 1).block_fold() buf.current_view().goto(buf.at(7, 19)) GPS.execute_action("Paste from Clipboard") yield wait_language_server("textDocument/foldingRange") # Verify that the contents is what we logically expect gps_assert(buf.get_chars(), expected, "Buffer corruption when inserting after folded block") # Verify that the logical contents correspond to the contents # on screen! g = buf.gtk_text_buffer() gps_assert(buf.get_chars(), g.get_text(g.get_start_iter(), g.get_end_iter(), False), "Corruption between the visible text and the logical text") # Last layer of safety: verify that saving + undo works buf.undo() buf.undo() buf.save(file=GPS.File("out.txt"))
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 driver(): GPS.EditorBuffer.get(GPS.File("p.ads")) GPS.execute_action("gnatfuzz analyze file workflow") messages = [] # Wait at most 2 seconds for messages to appear in the locations view time_waited = 0 while time_waited < 2000: yield timeout(100) time_waited += 100 messages = GPS.Message.list("Fuzzable Subprograms") if len(messages) > 0: break gps_assert(len(messages) > 0, True, "No messages found after analyze") m = messages[0] # We have one "Fuzzable program" message: click on the action yield idle_modal_dialog(lambda: m.execute_action()) dialog = get_window_by_title("gnatfuzz analyze") # The confirmation dialog to switch to the harness project should pop up yield idle_modal_dialog( lambda: get_button_from_label("Execute", dialog).clicked()) dialog = get_window_by_title("Confirmation") get_button_from_label("Yes", dialog).clicked() yield wait_tasks() # Check that we've switched to the harness project gps_assert(GPS.Project.root().name(), "Fuzz_Test", "wrong project name after generation")
def driver(): yield wait_tasks() b = GS.EditorBuffer.get(GS.File("main.adb")) GPS.execute_action("Expand alias under cursor") yield wait_idle() gps_assert(b.get_chars(), expected, "Autofix failed")
def driver(): # Launch a program that will run forever GPS.execute_action("Build & Run Number 1") # Wait until the command appears while True: tasks = filter(lambda x: x.name() == "Run Main", GPS.Task.list()) if len(tasks) == 1: break yield timeout(100) # Wait a bit more yield timeout(100) # Interrupt the command tasks[0].interrupt() # Wait a bit and verify that the process interruption is showing in # the console yield timeout(100) if "linux" in sys.platform: console = GPS.Console("Run: main") else: console = GPS.Console("Run: main.exe") gps_assert( "process interrupted" in console.get_text(), True, "the console didn't see the process ending: {}".format( console.get_text())) # Now destroy the console: this shouldn't crash console.destroy() yield timeout(100)
def driver(): # Create a new file with no name GPS.execute_action("new file") b = GPS.EditorBuffer.get() # Insert some ada code b.insert(b.at(1, 1), "package pack is\n") # Now save the file to its rightful name f = GPS.File("pack.ads") b.save(file=f) # Add some more Ada Code b.insert(b.at(2, 1), " Foo : Integer := 42;\n") b.insert(b.at(3, 1), " Bla : Integer := Foo;\n") b.insert(b.at(4, 1), "end pack;\n") # Do a "goto declaration" on Foo at line 3 b.current_view().goto(b.at(3, 22)) # wait LSP responses has been processed to have folding information if GPS.LanguageServer.is_enabled_for_language_name("Ada"): yield wait_tasks(other_than=known_tasks) GPS.execute_action("goto declaration") yield hook('language_server_response_processed') # Check that "Foo" is selected at line 2 gps_assert(b.get_cursors()[0].location().line(), 2, "Wrong line selected after goto declaration") gps_assert(b.get_chars(b.selection_start(), b.selection_end()), "Foo ", "'Foo' wasn't selected after the call to goto declaration")
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(): GPS.Preference("General-Charset").set("UTF-8") b = GPS.EditorBuffer.get(GPS.File("hello.adb")) b.find_all_refs(b.at(2, 15), True) yield hook('language_server_response_processed') actual = b.debug_dump_syntax_highlighting("Search results") gps_assert( actual.strip(), expected.strip(), "highlighting is wrong after find all refs:\n" + "\n%s\n!=\n%s\n" % (actual, expected))
def run_test(): buf = GPS.EditorBuffer.get(GPS.File('main.adb')) yield wait_idle() GPS.execute_action("Build Main Number 1") yield hook("compilation_finished") yield wait_idle() gps_assert( GPS.dump_elaborations(), ['b (body):a (spec):pragma Elaborate_All', 'a (body):b (spec):withed'], "The elaboration Ccrcularities view has wrong content")
def driver(): b = GPS.EditorBuffer.get(GPS.File("hello.adb")) v = b.current_view() b.blocks_fold() gps_assert(b.get_chars(include_hidden_chars=False), expected_1, "block folding didn't happen") b.insert(b.at(7, 19), "a") gps_assert(b.get_chars(include_hidden_chars=False), expected_2, "contents not right after inserting character")
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(): # Set the conditional continuation pref to a ridiculous amount GPS.Preference("Ada-Conditional-Level").set(120) b = GPS.EditorBuffer.get(GPS.File("t.adb")) # Format the second line in the aggregate b.current_view().goto(b.at(6, 6)) GPS.execute_action("format selection") # Verify that the proper indentation is produced gps_assert(b.get_chars(b.at(1, 1), b.at(6, 24)), expected, "Wrong format for aggregate in expression function")
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 wait_idle() 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') yield wait_idle() expected = [ 'Foo is called by ', [ 'Foo', ['Foo', ['computing...'], 'Main', ['computing...']], 'Main', ['computing...'] ] ] 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. 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")
def driver(): b = GPS.EditorBuffer.get(GPS.File("t.c")) v = b.current_view() v.goto(b.at(1, 1)) # Test the default behavior # Toggle to comment GPS.execute_action("Toggle Comment") gps_assert(b.get_chars(), "/* a */\nb\nc\n", "Text wrong after first toggle to comment") # Toggle to uncomment v.goto(b.at(1, 1)) GPS.execute_action("Toggle Comment") gps_assert(b.get_chars(), "a\nb\nc\n", "Text wrong after first toggle to uncomment") # Change the preference GPS.Preference("C-Comment-Two-Slashes").set(True) # Toggle to comment v.goto(b.at(2, 1)) GPS.execute_action("Toggle Comment") gps_assert(b.get_chars(), "a\n// b\nc\n", "Text wrong after seond toggle to comment") # Toggle to uncomment v.goto(b.at(2, 1)) GPS.execute_action("Toggle Comment") gps_assert(b.get_chars(), "a\nb\nc\n", "Text wrong after second toggle to uncomment")
def run_test(): buf = GPS.EditorBuffer.get(GPS.File('main.adb')) buf.current_view().goto(buf.at(5, 10)) GPS.execute_action('goto declaration') yield hook("language_server_response_processed") current_buf = GPS.EditorBuffer.get() gps_assert(current_buf.file(), GPS.File('hello_world.ads'), "'goto declaration' did not open the right file") current_loc = current_buf.main_cursor().location() gps_assert(current_loc, current_buf.at(3, 33), "'goto declaration' did not jump to right location") GPS.execute_action('goto body') yield hook("language_server_response_processed") current_buf = GPS.EditorBuffer.get() gps_assert(current_buf.file(), GPS.File('hello_world.adb'), "'goto body' did not open the right file") current_loc = current_buf.main_cursor().location() gps_assert(current_loc, current_buf.at(5, 33), "'goto body' did not jump to right location")
def driver(): # Open an editor and go to a line where there's a code action b = GPS.EditorBuffer.get(GPS.File("hello.adb")) v = b.current_view() v.goto(b.at(5, 9)) # Wait until the language server has responded to the codeAction request yield wait_language_server("textDocument/codeAction") # 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") b.click_on_side_column(5, 1, "gps-light-bulb") # Wait for the language server yield wait_language_server("workspace/executeCommand") # Check that the edits have been received gps_assert(b.get_chars(b.at(5, 1), b.at(6, 1)).strip(), 'Put_Line (Item => "hello");', "edits not received") yield wait_language_server("textDocument/codeAction") m = GPS.Message.list(category="_internal_code_actions") gps_assert(len(m), 0, "there should be no code action message")
def driver(): b = GPS.EditorBuffer.get(GPS.File("hello.adb")) orig = b.get_chars() v = b.current_view() v.goto(b.at(2, 14)) send_key_event(GDK_RETURN) # Check contents after entern gps_assert(b.get_chars(), orig.replace(" Foo", "\n Foo"), "enter character was not received") # Undo and check for contents b.undo() gps_assert(b.get_chars(), orig, "contents corrupted after undo")
def run_test(): buf = GPS.EditorBuffer.get(GPS.File('main.adb')) buf.current_view().goto(buf.at(5, 10)) # wait LSP responses has been processed to have folding information if GPS.LanguageServer.is_enabled_for_language_name("Ada"): yield wait_tasks(other_than=known_tasks) GPS.execute_action('goto declaration') yield wait_language_server('textDocument/declaration') current_buf = GPS.EditorBuffer.get() gps_assert(current_buf.file(), GPS.File('hello_world.ads'), "'goto declaration' did not open the right file") current_loc = current_buf.main_cursor().location() gps_assert(current_loc, current_buf.at(3, 33), "'goto declaration' did not jump to right location") # wait LSP responses has been processed to have folding information if GPS.LanguageServer.is_enabled_for_language_name("Ada"): yield wait_tasks(other_than=known_tasks) GPS.execute_action('goto body') yield wait_language_server('textDocument/implementation') current_buf = GPS.EditorBuffer.get() gps_assert(current_buf.file(), GPS.File('hello_world.adb'), "'goto body' did not open the right file") current_loc = current_buf.main_cursor().location() gps_assert(current_loc, current_buf.at(5, 33), "'goto body' did not jump to right location")
def driver(): f = GPS.File("locpack.adb") b = GPS.EditorBuffer.get(f) node = lal_utils.node(f, 3, 7, 'SubpBody') # This is the call that used to cause an infinite recursion; # calling this will either crash GS or generate an exception # traceback decl = node.p_decl_part() # Check that the operation was successful gps_assert(os.path.basename(decl.unit.filename), "locpack.ads", "p_decl_part() didn't work")
def driver(): p = GS.Process("echo 1") p.get_result() try: p.send("1") raise Exception("Should not reach this") except Exception as e: gps_assert(str(e), expected, "Wrong error message") try: p.kill() raise Exception("Should not reach this") except Exception as e: gps_assert(str(e), expected, "Wrong error message")
def driver(): b = GPS.EditorBuffer.get(GPS.File("main.adb")) b.select(b.at(2, 1), b.at(4, 12)) GPS.execute_action("Copy to Clipboard") GPS.Project.load("q.gpr") b = GPS.EditorBuffer.get(GPS.File("p.ads")) b.current_view().goto(b.at(2, 1)) GPS.execute_action("Paste from Clipboard") gps_assert(b.get_chars(), """package p is -- bla -- bla bla -- bla bla end p; """, "paste did not work after switching projects")
def driver(): GPS.Preference("General-Charset").set("UTF-8") b = GPS.EditorBuffer.get(GPS.File("hello.adb")) # wait LSP responses has been processed to have folding information if GPS.LanguageServer.is_enabled_for_language_name("Ada"): yield wait_tasks(other_than=known_tasks) b.find_all_refs(b.at(2, 15), True) yield hook('language_server_response_processed') actual = b.debug_dump_syntax_highlighting("Search results") gps_assert( actual.strip(), expected.strip(), "highlighting is wrong after find all refs:\n" + "\n%s\n!=\n%s\n" % (actual, expected))
def driver(): list = [x for x in GPS.lookup_actions() if GPS.Action(x).get_keys()] x = {} for item in list: key = GPS.Action(item).get_keys() if key in x: x[key].append(item) else: x[key] = [item] dups = {} for j in x: if len(x[j]) > 1: dups[j] = x[j] gps_assert(dups, expected, "Unexpected duplicated shortcuts")
def driver(): b = GPS.EditorBuffer.get(GPS.File("hello.adb")) v = b.current_view() # wait LSP responses has been processed if GPS.LanguageServer.is_enabled_for_language_name("Ada"): yield wait_tasks(other_than=known_tasks) yield timeout(1000) b.blocks_fold() gps_assert(b.get_chars(include_hidden_chars=False), expected_1, "block folding didn't happen") b.insert(b.at(7, 19), "a") gps_assert(b.get_chars(include_hidden_chars=False), expected_2, "contents not right after inserting character")
def driver(): GPS.Preference("Debugger-Execution-Window").set(False) # This test launches a debug session, and runs the program in the # debugger. The goal is to check against a memory corruption that # occurs after the process has terminated - the test itself might # not report an issue, but valgrind might. GPS.execute_action("Build & Debug Number 1") yield wait_tasks() GPS.Debugger.get().non_blocking_send("run") yield timeout(2000) yield wait_for_mdi_child("Debugger Execution") # sanity check that the test ran gps_assert("finished!" in GPS.Debugger.get().get_console().get_text(), True, "debug output not visible in console")
def driver(): b = GPS.EditorBuffer.get(GPS.File("p.adb")) yield wait_tasks() v = b.current_view() v.goto(b.at(9, 8)) GPS.execute_action("Macro Start Keyboard") send_key_event(ord('o')) yield timeout(200) send_key_event(ord('o')) yield timeout(200) GPS.execute_action("Macro Stop") v.goto(b.at(9, 1)) GPS.execute_action("Macro Play") # Let the macro execute yield timeout(1000) gps_assert(b.get_chars(b.at(9, 1), b.at(9, 4)), "oo ", "Macro playback was hindered by completion")
def driver(): # Generate a giant file on disk and load it from disk with open("p.ads", "wb") as f: f.write("""package P is function Foo return Integer is (42); end P;""" + ("--" + "spam" * 100 + "\n") * 10000) # Reload the project so that p.ads is considered as a source GPS.execute_action("reload project") q_ads = GPS.File("q.ads") p_ads = GPS.File("p.ads") a = GPS.EditorBuffer.get(p_ads) yield timeout(1000) b = GPS.EditorBuffer.get(q_ads) # Now insert a huge amount of data in an already open editor b.insert(b.at(4, 7), ("-- " + "spam" * 100 + "\n") * 10000) als = GPS.LanguageServer.get_by_language_name("Ada") params = {"textDocument": {"uri": q_ads.uri}, "position": {"line": 2, "character": 27}, "context": {"includeDeclaration": True}} result = yield als.request_promise("textDocument/references", params) if not result.is_valid: simple_error("we were expecting a valid result") # The result we expect from find_all_references expected = [{"uri": p_ads.uri, "range": {"start": {"line": 1, "character": 12}, "end": {"line": 1, "character": 15}}, "alsKind": ["reference"]}, {"uri": q_ads.uri, "range": {"start": {"line": 2, "character": 27}, "end": {"line": 2, "character": 30}}, "alsKind": ["call"]}] gps_assert( result.data, expected, "result contents doesn't match expectations: {}".format(result))