]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add "fail" command
authorAlan T. DeKok <aland@freeradius.org>
Fri, 11 Oct 2019 14:27:40 +0000 (10:27 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 11 Oct 2019 16:31:49 +0000 (12:31 -0400)
for tests where we know the expected output, but which don't yet
work. It's better to have known failures than results which are
commented out

src/bin/unit_test_attribute.c

index 9bd18661dce1dad76ea758f5f1625b4653dbf8e8..3a7f59733dbea51cc681ca7be52d2875f76cb8b2 100644 (file)
@@ -1281,6 +1281,26 @@ static size_t command_exit(command_result_t *result, UNUSED command_ctx_t *cc,
        RETURN_EXIT(atoi(in));
 }
 
+/** Compare the data buffer to an expected value
+ *
+ *  Note that we fail if the string DOES match!  This command is used
+ *  as a place-holder for tests which SHOULD work in the future, but
+ *  which do not work right no.  It allows us to store the expected
+ *  output in a test that isn't commented out.
+ */
+static size_t command_fail(command_result_t *result, UNUSED command_ctx_t *cc,
+                          char *data, size_t data_used, char *in, size_t inlen)
+{
+       if (strcmp(in, data) == 0) RETURN_MISMATCH(in, inlen, data, data_used);
+
+       /*
+        *      We didn't actually write anything, but this
+        *      keeps the contents of the data buffer around
+        *      for the next command to operate on.
+        */
+       RETURN_OK(data_used);
+}
+
 /** Dynamically load a protocol library
  *
  */
@@ -1541,6 +1561,11 @@ static fr_table_ptr_sorted_t     commands[] = {
                                        .usage = "exit[ <num>]",
                                        .description = "Exit with the specified error number.  If no <num> is provided, process will exit with 0"
                                }},
+       { "fail",               &(command_entry_t){
+                                       .func = command_fail,
+                                       .usage = "fail <string>",
+                                       .description = "The expected output should NOT match the string"
+                               }},
        { "load ",              &(command_entry_t){
                                        .func = command_proto_load,
                                        .usage = "load <protocol>",