zircon/system/utest/runtests-utils/runtests-utils-test.cc
// Passing an --output argument *and* a syslog file name should result in output being
// written that includes a syslog reference.
Passing an --output argument *and* a syslog file name should result in output being
written that includes a syslog reference.
Passing an -- output argument * and * a syslog file name should result in output being written that includes a syslog reference .
TEST(DiscoverAndRunTests, DiscoverAndRunTestsWithSyslogOutput) {
  fbl::String all_scripts_dir = packaged_script_dir();
  fbl::String script_dir = JoinPath(all_scripts_dir, "testwithoutput");
  ScopedTestDir test_dir;
  const fbl::String succeed_file_name = JoinPath(script_dir, "test-with-output-succeed.sh");
  const fbl::String fail_file_name = JoinPath(script_dir, "test-with-output-fail.sh");
  const fbl::String output_dir = JoinPath(test_dir.path(), "run-all-tests-output-2");
  EXPECT_EQ(0, MkDirAll(output_dir));
  const char* const argv[] = {"./runtests", "--all", "--output", output_dir.c_str()};
  TestStopwatch stopwatch;
  EXPECT_EQ(EXIT_FAILURE,
            DiscoverAndRunTests(4, argv, {script_dir.c_str()}, &stopwatch, "syslog.txt"));
  fbl::String success_output_rel_path;
  ASSERT_TRUE(GetOutputFileRelPath(output_dir, succeed_file_name, &success_output_rel_path));
  fbl::String failure_output_rel_path;
  ASSERT_TRUE(GetOutputFileRelPath(output_dir, fail_file_name, &failure_output_rel_path));
  const char kExpectedOutputsStr[] =
      "  \"outputs\": {\n"
      "    \"syslog_file\": \"syslog.txt\"\n"
      "  }";
  const fbl::String output_path = JoinPath(output_dir, "summary.json");
  FILE* output_file = fopen(output_path.c_str(), "r");
  ASSERT_TRUE(output_file);
  char buf[1024];
  memset(buf, 0, sizeof(buf));
  EXPECT_LT(0, fread(buf, sizeof(buf[0]), sizeof(buf), output_file));
  fclose(output_file);
  bool found_expected_outputs_str = false;
  for (size_t buf_index = 0; buf[buf_index]; ++buf_index) {
    if (!strncmp(kExpectedOutputsStr, &buf[buf_index], sizeof(kExpectedOutputsStr) - 1)) {
      found_expected_outputs_str = true;
      break;
    }
  }
  if (!found_expected_outputs_str) {
    printf("Unexpected buffer contents: %s\n", buf);
  }
  EXPECT_TRUE(found_expected_outputs_str, "Didn't find expected outputs str in buf");
}
TEST ( DiscoverAndRunTests , DiscoverAndRunTestsWithSyslogOutput ) { fbl :: String all_scripts_dir = packaged_script_dir ( ) ; fbl :: String script_dir = JoinPath ( all_scripts_dir , " " ) ; ScopedTestDir test_dir ; const fbl :: String succeed_file_name = JoinPath ( script_dir , " " ) ; const fbl :: String fail_file_name = JoinPath ( script_dir , " " ) ; const fbl :: String output_dir = JoinPath ( test_dir . path ( ) , " " ) ; EXPECT_EQ ( 0 , MkDirAll ( output_dir ) ) ; const char * const argv [ ] = { " " , " " , " " , output_dir . c_str ( ) } ; TestStopwatch stopwatch ; EXPECT_EQ ( EXIT_FAILURE , DiscoverAndRunTests ( 4 , argv , { script_dir . c_str ( ) } , & stopwatch , " " ) ) ; fbl :: String success_output_rel_path ; ASSERT_TRUE ( GetOutputFileRelPath ( output_dir , succeed_file_name , & success_output_rel_path ) ) ; fbl :: String failure_output_rel_path ; ASSERT_TRUE ( GetOutputFileRelPath ( output_dir , fail_file_name , & failure_output_rel_path ) ) ; const char kExpectedOutputsStr [ ] = " \" \" \n " " \" \" \" \" \n " " " ; const fbl :: String output_path = JoinPath ( output_dir , " " ) ; FILE * output_file = fopen ( output_path . c_str ( ) , " " ) ; ASSERT_TRUE ( output_file ) ; char buf [ 1024 ] ; memset ( buf , 0 , sizeof ( buf ) ) ; EXPECT_LT ( 0 , fread ( buf , sizeof ( buf [ 0 ] ) , sizeof ( buf ) , output_file ) ) ; fclose ( output_file ) ; bool found_expected_outputs_str = false ; for ( size_t buf_index = 0 ; buf [ buf_index ] ; ++ buf_index ) { if ( ! strncmp ( kExpectedOutputsStr , & buf [ buf_index ] , sizeof ( kExpectedOutputsStr ) - 1 ) ) { found_expected_outputs_str = true ; break ; } } if ( ! found_expected_outputs_str ) { printf ( " \n " , buf ) ; } EXPECT_TRUE ( found_expected_outputs_str , " " ) ; }
Passing an --output argument *and* a syslog file name should result in output being
written that includes a syslog reference.
Passing an -- output argument * and * a syslog file name should result in output being written that includes a syslog reference .
// Prepare the expected output. // Extract the actual output. // We don't actually care if the string is at the beginning or the end of // the JSON, so just search for it anywhere.