% SAVE_REPORT runs all unit test and saves the result to a readable file

% OLD TODO
% 
%   + Format UTP table by hand - not using \utp
%   + move code block to tables in appendix with same numbering as UTP tables
%   + add pdf link in UTP table to code block
%   + keep code indentation from m-file
%   + wrap strings using utils.prog.wrapstring (or similar) - add ... 
% 

function save_report()
  % config
  csv_filename = 'report/report.csv'; % path to temporary csv file
  end_filename = 'report/utp_%TIME%.xml'; %where the report goes to
  ruby = '/usr/bin/ruby'; %path to ruby
  rb_file = 'buildxml.rb'; %path to buildxml.rb

  % input data (loaded from file)
  result = load('result.mat');
  result = result.s;
  
  % input data (test run)
  % result = utp_run();
  
  % output
  outFile = fopen(csv_filename, 'w');
  
  for i=1:length(result)
    line = sprintf('%s, %.0f, %.0f, %.0f, %.0f\n', result(i).fcn, result(i).a, result(i).s, result(i).num, result(i).date.utc_epoch_milli);
    fprintf(outFile, '%s', line);
  end
  
  fclose(outFile);
  
  system(sprintf('%s %s "%s"', ruby, rb_file, end_filename));
end