t_file_match
- t_file_match(got_fname, exp_fname, msg, reps, del_got_fname)
t_file_match()- Tests whether two text files match.t_file_match(got_fname, exp_fname, msg) t_file_match(got_fname, exp_fname, msg, reps) t_file_match(got_fname, exp_fname, msg, reps, del_got_fname) ok = t_file_match(...)
Uses
t_str_match()on the contents of two text files whos names/paths are given ingot_fnameandexp_fname. If both files exist and the contents match, the test passes.- Inputs:
got_fname (char array) – name of file containing actual result
exp_fname (char array) – name of file containing expected result
msg (char array) – message to display for this test
reps (char array) – (optional) cell array of replacement specs
del_got_fname (logical) – (optional, default = false) if true, the file named in
got_fnamewill be deleted if the test passes
- Output:
ok (logical) – (optional) true if test passed, false if failed
It ignores any differences in line ending characters and, like
t_str_match(), can apply replacements to the contents ofgot_fname, and optionallyexp_fname, as specified byrepsbefore comparing.The
repsargument 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
originalandreplacementarguments are passed directly as the 2nd and 3rd arguments toregexprep()(or tostrrep()ifreis present and false). The replacement applies togot_fnameonly, unlessbothis present and true, in which case it also applies toexp_fname.If
del_got_fnameis present and true it will delete the file named ingot_fnameif the test passes.Intended to be called between calls to
t_begin()andt_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_fname = 'test_generated_output.txt'; exp_fname = 'expected_output.txt'; t_file_match(got_fname, exp_fname, 'mytest', reps, 1); t_end;
See also
t_ok(),t_is(),t_str_match(),t_skip(),t_begin(),t_end(),t_run_tests().