summaryrefslogtreecommitdiffstats
path: root/src/test/run_cmd.cc
blob: ada624e8b5a9d070dde3af9113ad6bf8e1b7b79d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include "common/config.h"
#include "common/run_cmd.h"

#include "gtest/gtest.h"

#include <stdlib.h>
#include <unistd.h>

TEST(RunCommand, StringSimple)
{
  char temp_file_name[] = "run_cmd_temp_file_XXXXXX";

  int fd = ::mkstemp(temp_file_name);
  ASSERT_GE(fd, 0);
  ::close(fd);

  std::string ret = run_cmd("touch", temp_file_name, (char*)NULL);
  ASSERT_EQ(ret, "");

  ASSERT_EQ(access(temp_file_name, R_OK), 0);

  ret = run_cmd("rm", "-f", temp_file_name, (char*)NULL);
  ASSERT_EQ(ret, "");

  ASSERT_NE(access(temp_file_name, R_OK), 0);
}