self.pakfire = pakfire.Pakfire(path)
def test_execute(self):
- r = self.pakfire.execute(["/usr/bin/sleep", "0"])
+ r = self.pakfire.execute(["/command", "exit-with-code", "0"])
self.assertIsNone(r)
+ def test_return_value(self):
+ with self.assertRaises(pakfire.CommandExecutionError) as e:
+ self.pakfire.execute(["/command", "exit-with-code", "123"])
+
+ # Extract return code
+ code, = e.exception.args
+
+ self.assertTrue(code == 123)
+
def test_environ(self):
r = self.pakfire.execute(["/bin/sh", "-c", "echo ${VAR1}"],
environ={"VAR1" : "VAL1"})
with self.assertRaises(TypeError):
self.pakfire.execute(["/usr/bin/sleep", "--help"], environ="VAR1=VAL1")
- def test_return_value(self):
- with self.assertRaises(pakfire.CommandExecutionError) as e:
- self.pakfire.execute(["/bin/sh", "-c", "exit 123"])
-
- # Extract return code
- code, = e.exception.args
-
- self.assertTrue(code == 123)
-
def test_execute_non_existant_command(self):
"""
Executing non-existant commands should raise an error
# #
#############################################################################*/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+static int exit_with_code(int argc, char* argv[]) {
+ if (argc < 1) {
+ fprintf(stderr, "exit-with-code requires an argument\n");
+ return EXIT_FAILURE;
+ }
+
+ // Return the given code
+ return strtoul(argv[0], NULL, 10);
+}
+
int main(int argc, char* argv[]) {
- return 0;
+ if (argc < 2) {
+ fprintf(stderr, "No command given\n");
+ return EXIT_FAILURE;
+ }
+
+ int (*callback)(int argc, char* argv[]) = NULL;
+ const char* command = argv[1];
+
+ // Exit with code
+ if (strcmp(command, "exit-with-code") == 0) {
+ callback = exit_with_code;
+ }
+
+ // Exit if no callback has been set
+ if (!callback) {
+ fprintf(stderr, "Unknown command: %s\n", command);
+ return EXIT_FAILURE;
+ }
+
+ return callback(argc - 2, argv + 2);
}