From: Michael Tremer Date: Thu, 21 Jul 2022 08:25:53 +0000 (+0000) Subject: tests: execute: Add a simple echo command that prints lines X-Git-Tag: 0.9.28~661 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=de106366348bca959d6b1a9745a99ce7ed4dc185;p=pakfire.git tests: execute: Add a simple echo command that prints lines Signed-off-by: Michael Tremer --- diff --git a/tests/python/execute.py b/tests/python/execute.py index 649ff06bc..cd9eff11a 100755 --- a/tests/python/execute.py +++ b/tests/python/execute.py @@ -64,7 +64,7 @@ class Test(unittest.TestCase): self.pakfire.execute(["/usr/bin/does-not-exist"]) def test_execute_output(self): - self.pakfire.execute(["/bin/bash", "--help"]) + self.pakfire.execute(["/command", "echo", "123"]) # Run a command with a lot of output which exceeds the buffer size self.pakfire.execute(["/usr/bin/openssl", "rand", "-hex", "65536"]) @@ -73,7 +73,7 @@ class Test(unittest.TestCase): self.pakfire.execute(["/usr/bin/openssl", "rand", "-base64", "4096"]) # Multiple newlines in one read - self.pakfire.execute(["/usr/bin/printf", "1\n2\n3\n"]) + self.pakfire.execute(["/command", "echo", "1\n2\n3"]) def test_execute_logger(self): def log(priority, message): diff --git a/tests/stub/command.c b/tests/stub/command.c index 164bc5278..512d0fd8f 100644 --- a/tests/stub/command.c +++ b/tests/stub/command.c @@ -22,6 +22,14 @@ #include #include +static int echo(int argc, char* argv[]) { + for (int i = 0; i < argc; i++) { + printf("%s\n", argv[i]); + } + + return 0; +} + static int exit_with_code(int argc, char* argv[]) { if (argc < 1) { fprintf(stderr, "exit-with-code requires an argument\n"); @@ -41,10 +49,13 @@ int main(int argc, char* argv[]) { int (*callback)(int argc, char* argv[]) = NULL; const char* command = argv[1]; + // Echo + if (strcmp(command, "echo") == 0) + callback = echo; + // Exit with code - if (strcmp(command, "exit-with-code") == 0) { + else if (strcmp(command, "exit-with-code") == 0) callback = exit_with_code; - } // Exit if no callback has been set if (!callback) {