Skip to content

Commit

Permalink
Insert extra logging for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Wootten authored and Jeremy Wootten committed Nov 24, 2024
1 parent 0420ee3 commit 5a557f9
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/tests/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -108,30 +108,36 @@ namespace Terminal.Test.Application {

// local command line: any instance from terminal
GLib.Test.add_func ("/application/cli/commandline", () => {
stdout.printf ("# Starting /application/cli/commandline\n");
cli ({ "io.elementary.terminal", "--commandline=true" }, (dict) => {
stdout.printf ("# Callback for cli 1\n");
assert_true ("commandline" in dict);
unowned var commandline = dict.lookup_value ("commandline", null).get_bytestring ();
assert_cmpstr (commandline, CompareOperator.EQ, "true");
});

cli ({ "io.elementary.terminal", "-x", "echo", "-e", "true\tfalse" }, (dict) => {
stdout.printf ("# Callback for cli 2\n");
assert_true ("commandline" in dict);
unowned var commandline = dict.lookup_value ("commandline", null).get_bytestring ();
assert_cmpstr (commandline, CompareOperator.EQ, "echo -e true\\tfalse");
});

cli ({ "io.elementary.terminal", "--commandline", "echo", "true" }, (dict) => {
stdout.printf ("# Callback for cli 3\n");
assert_true ("commandline" in dict);
unowned var commandline = dict.lookup_value ("commandline", null).get_bytestring ();
assert_cmpstr (commandline, CompareOperator.EQ, "echo true");
});
});

GLib.Test.add_func ("/application/cli/working-directory", () => {
stdout.printf ("# Starting /application/cli/working-directory\n");
unowned var working_directory = GLib.Test.get_dir (GLib.Test.FileType.DIST);
var cwd = Environment.get_current_dir ();

cli ({ "io.elementary.terminal", "-w", working_directory }, (dict) => {
stdout.printf ("# Callback for cli 4\n");
assert_false ("working-dir" in dict);
var current_directory = Environment.get_current_dir ();
assert_cmpstr (current_directory, CompareOperator.EQ, working_directory);
Expand All @@ -142,14 +148,17 @@ namespace Terminal.Test.Application {

// primary command line: first instance from terminal. any instance from dbus.
GLib.Test.add_func ("/application/command-line/new-tab", () => {
stdout.printf ("# Starting /application/command-line/new-tab\n");
option ("{'new-tab':<true>}", "@a{sv} {}", () => {
stdout.printf ("# Callback for option 1\n");
unowned var window = (MainWindow) application.active_window;
assert_nonnull (window);
var n_tabs = (int) window.notebook.n_pages;
assert_cmpint (n_tabs, CompareOperator.EQ, 2);
});

option ("{'new-tab':<false>}", "@a{sv} {}", () => {
stdout.printf ("# Callback for option 2\n");
unowned var window = (MainWindow) application.active_window;
assert_nonnull (window);
var n_tabs = (int) window.notebook.n_pages;
Expand All @@ -158,22 +167,27 @@ namespace Terminal.Test.Application {
});

GLib.Test.add_func ("/application/command-line/new-window", () => {
stdout.printf ("# Starting /application/command-line/new-window\n");
option ("{'new-window':<true>}", "@a{sv} {}", () => {
stdout.printf ("# Callback for option 3\n");
var n_windows = (int) application.get_windows ().length ();
assert_cmpint (n_windows, CompareOperator.EQ, 2);
});

option ("{'new-window':<false>}", "@a{sv} {}", () => {
stdout.printf ("# Callback for option 4\n");
var n_windows = (int) application.get_windows ().length ();
assert_cmpint (n_windows, CompareOperator.EQ, 1);
});
});

GLib.Test.add_func ("/application/command-line/execute", () => {
stdout.printf ("# Starting /application/command-line/execute\n");
string[] execute = { "true", "echo test", "echo -e te\\tst", "false" };

//valid
option ("{'execute':<[b'%s']>}".printf (string.joinv ("',b'", execute)), "@a{sv} {}", () => {
stdout.printf ("# Callback for option 5\n");
unowned var window = (MainWindow) application.active_window;
assert_nonnull (window);
var n_tabs = (int) window.notebook.n_pages;
Expand All @@ -182,6 +196,7 @@ namespace Terminal.Test.Application {

// invalid
option ("{'execute':<[b'',b'',b'']>}", "@a{sv} {}", () => {
stdout.printf ("# Callback for option 6\n");
unowned var window = (MainWindow) application.active_window;
assert_nonnull (window);
var n_tabs = (int) window.notebook.n_pages;
Expand All @@ -193,9 +208,11 @@ namespace Terminal.Test.Application {
GLib.Test.add_func ("/application/command-line/commandline", () => GLib.Test.skip ());

GLib.Test.add_func ("/application/command-line/platform-data/cwd", () => {
stdout.printf ("# Starting //application/command-line/platform-data/cwd\n");
unowned var working_directory = GLib.Test.get_dir (GLib.Test.FileType.DIST);

option ("{'new-tab':<true>}", "{'cwd':<b'%s'>}".printf (working_directory), () => {
stdout.printf ("# Callback for option 7\n");
unowned var window = (MainWindow) application.active_window;
assert_nonnull (window);
var terminal_directory = window.current_terminal.get_shell_location ();
Expand All @@ -205,15 +222,19 @@ namespace Terminal.Test.Application {

// actions
GLib.Test.add_func ("/application/action/new-window", () => {
stdout.printf ("# Starting /application/action/new-window\n");
action ("new-window", null, () => {
stdout.printf ("# Callback for action 1\n");
// include the extra window from terminal launching
var n_windows = (int) application.get_windows ().length ();
assert_cmpint (n_windows, CompareOperator.EQ, 2);
});
});

GLib.Test.add_func ("/application/action/quit", () => {
stdout.printf ("# Starting /application/action/quit\n");
action ("quit", null, () => {
stdout.printf ("# Callback for action 2\n");
assert_null (application.active_window);
});
});
Expand Down

0 comments on commit 5a557f9

Please sign in to comment.