tests: verify the behavior of gpiofind in case of invalid arguments
authorBartosz Golaszewski <bartekgola@gmail.com>
Mon, 12 Jun 2017 10:46:04 +0000 (12:46 +0200)
committerBartosz Golaszewski <bartekgola@gmail.com>
Mon, 12 Jun 2017 10:46:04 +0000 (12:46 +0200)
Make sure we bail out with the correct error message when the user
doesn't give us exactly one GPIO line name.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
tests/tests-gpiofind.c

index ba9f8974df24dab0d1c3dd95373a698a3426c827..6f57f1def606bf7736102b6c3423e75cdacfdc83 100644 (file)
@@ -46,3 +46,30 @@ static void gpiofind_not_found(void)
 TEST_DEFINE(gpiofind_not_found,
            "tools: gpiofind - not found",
            TEST_FLAG_NAMED_LINES, { 4, 8 });
+
+static void gpiofind_invalid_args(void)
+{
+       test_gpiotool_run("gpiofind", (char *)NULL);
+       test_tool_wait();
+
+       TEST_ASSERT(test_tool_exited());
+       TEST_ASSERT_EQ(test_tool_exit_status(), 1);
+       TEST_ASSERT_NULL(test_tool_stdout());
+       TEST_ASSERT_NOT_NULL(test_tool_stderr());
+       TEST_ASSERT_STR_CONTAINS(test_tool_stderr(),
+                                "exactly one GPIO line name must be specified");
+
+       test_gpiotool_run("gpiofind", "first argument",
+                         "second argument", (char *)NULL);
+       test_tool_wait();
+
+       TEST_ASSERT(test_tool_exited());
+       TEST_ASSERT_EQ(test_tool_exit_status(), 1);
+       TEST_ASSERT_NULL(test_tool_stdout());
+       TEST_ASSERT_NOT_NULL(test_tool_stderr());
+       TEST_ASSERT_STR_CONTAINS(test_tool_stderr(),
+                                "exactly one GPIO line name must be specified");
+}
+TEST_DEFINE(gpiofind_invalid_args,
+           "tools: gpiofind - invalid arguments",
+           0, { });