]> git.ipfire.org Git - pakfire.git/commitdiff
tests: execute: Add a simple echo command that prints lines
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 21 Jul 2022 08:25:53 +0000 (08:25 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 21 Jul 2022 08:25:53 +0000 (08:25 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
tests/python/execute.py
tests/stub/command.c

index 649ff06bcf97f9e19c4f574caf6d2d8abd61b989..cd9eff11a93c9bdd71432f62f6e6a4e31b2bcae0 100755 (executable)
@@ -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):
index 164bc5278820b08ab043174134a50f2ef708d552..512d0fd8ff55c1531377e4d7342330f635029e68 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 
+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) {