t_str_match

t_str_match(got, expected, msg, reps)

t_str_match() - Tests whether two strings/char arrays match.

t_str_match(got, expected, msg)
t_str_match(got, expected, msg, reps)
ok = t_str_match(...)

This is equivalent to t_ok(strcmp(got, expected), msg), with the option to apply replacements to got, and optionally to expected, as specified by reps before comparing.

Inputs:
  • got (char array) – actual result

  • expected (char array) – expected result

  • msg (char array) – message to display for this test

  • reps (char array) – (optional) cell array of replacement specs

Output:

ok (boolean) – (optional) true if test passed, false if failed

The reps argument is a cell array of replacement specs, applied sequentially, where each replacement spec is a cell array of the following form:

{original, replacement}
{original, replacement, re}
{original, replacement, re, both}

The original and replacement arguments are passed directly as the 2nd and 3rd arguments to regexprep() (or to strrep() if re is present and false). The replacement applies to got only, unless both is present and true, in which case it also applies to expected.

Intended to be called between calls to t_begin() and t_end().

Example:

quiet = 0;
t_begin(5, quiet);

% replace Windows EOL chars with Unix EOL chars
reps = {{char([13 10]), char(10), 0, 1}};
got = fileread('test_generated_output.txt');
expected = fileread('expected_output.txt');
t_str_match(got, expected, 'mytest', reps);

t_end;

See also t_ok(), t_is(), t_file_match(), t_skip(), t_begin(), t_end(), t_run_tests().