File: process.cpp

package info (click to toggle)
polybar 3.7.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,108 kB
  • sloc: cpp: 30,424; python: 3,750; sh: 284; makefile: 83
file content (44 lines) | stat: -rw-r--r-- 882 bytes parent folder | download | duplicates (3)
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "utils/process.hpp"

#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>

#include <chrono>
#include <thread>

#include "common/test.hpp"

using namespace polybar;
using namespace process_util;

TEST(SpawnAsync, is_async) {
  pid_t pid = spawn_async([] { exec_sh("sleep 0.1"); });
  int status;

  pid_t res = process_util::wait_for_completion_nohang(pid, &status);

  ASSERT_NE(res, -1);

  EXPECT_FALSE(WIFEXITED(status));
}

TEST(SpawnAsync, exit_code) {
  pid_t pid = spawn_async([] { exec_sh("exit 42"); });
  int status = 0;
  pid_t res = waitpid(pid, &status, 0);

  EXPECT_EQ(res, pid);

  EXPECT_EQ(WEXITSTATUS(status), 42);
}

TEST(SpawnAsync, env) {
  pid_t pid = spawn_async([] { exec_sh("exit $EXIT", {{"EXIT", "45"}}); });
  int status = 0;
  pid_t res = waitpid(pid, &status, 0);

  EXPECT_EQ(res, pid);

  EXPECT_EQ(WEXITSTATUS(status), 45);
}