FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cli/tests/BuildTaskProcessExecutorTests.cpp at dev · vixcpp/cli · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
vixcpp
/
cli
Public
Notifications
You must be signed in to change notification settings
Fork
2
Star
10
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cli
/
tests
/
BuildTaskProcessExecutorTests.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
169 lines (138 loc) · 4.37 KB
Breadcrumbs
cli
/
tests
/
BuildTaskProcessExecutorTests.cpp
Copy path
File metadata and controls
169 lines (138 loc) · 4.37 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#
include
<
vix/cli/build/BuildTaskProcessExecutor.hpp
>
#
include
<
cstdlib
>
#
include
<
exception
>
#
include
<
filesystem
>
#
include
<
iostream
>
#
include
<
stdexcept
>
#
include
<
string
>
#
include
<
vector
>
using
namespace
vix
::cli::build
;
namespace
{
namespace
fs
=
std::filesystem;
static
fs::path selfPath;
struct
TempDir
{
fs::path path;
TempDir
()
{
path =
fs::temp_directory_path
() /
(
"
vix-build-task-process-adapter-test-
"
+
std::to_string
(
std::rand
()));
fs::remove_all
(path);
fs::create_directories
(path);
}
~TempDir
()
{
std::error_code ec;
fs::remove_all
(path, ec);
}
};
static
void
require
(
bool
condition,
const
std::string &message)
{
if
(!condition)
throw
std::runtime_error
(message);
}
static
BuildTask
command_task
(std::string id, std::vector<std::string> command)
{
BuildTask task;
task.
id
=
std::move
(id);
task.
kind
= BuildTaskKind::Compile;
task.
command
=
std::move
(command);
return
task;
}
static
std::vector<std::string>
self_command
(std::vector<std::string> args)
{
std::vector<std::string> command;
command.
push_back
(selfPath.
string
());
command.
insert
(command.
end
(), args.
begin
(), args.
end
());
return
command;
}
static
void
test_successful_build_task
()
{
BuildTask task =
command_task
(
"
success
"
,
self_command
({
"
--child-output
"
,
"
success
"
}));
const
BuildTaskResult result =
execute_build_task_process
(task);
require
(result.
taskId
==
"
success
"
,
"
success task id
"
);
require
(result.
state
== BuildTaskState::Done,
"
success state
"
);
require
(result.
exitCode
==
0
,
"
success exit code
"
);
require
(result.
output
==
"
success
"
,
"
success output
"
);
}
static
void
test_failed_build_task
()
{
BuildTask task =
command_task
(
"
fail
"
,
self_command
({
"
--child-exit
"
,
"
7
"
}));
const
BuildTaskResult result =
execute_build_task_process
(task);
require
(result.
taskId
==
"
fail
"
,
"
failure task id
"
);
require
(result.
state
== BuildTaskState::Failed,
"
failure state
"
);
require
(result.
exitCode
==
7
,
"
failure exit
"
);
}
static
void
test_output_propagation
()
{
BuildTask task =
command_task
(
"
capture
"
,
self_command
({
"
--child-mixed-output
"
}));
const
BuildTaskResult result =
execute_build_task_process
(task);
require
(result.
state
== BuildTaskState::Done,
"
capture state
"
);
require
(result.
output
==
"
out
\n
err
\n
"
,
"
merged output propagated
"
);
}
static
void
test_working_directory_propagation
()
{
TempDir temp;
BuildTask task =
command_task
(
"
pwd
"
,
self_command
({
"
--child-pwd
"
}));
task.
workingDirectory
= temp.
path
;
const
BuildTaskResult result =
execute_build_task_process
(task);
require
(result.
state
== BuildTaskState::Done,
"
working directory state
"
);
require
(result.
output
.
find
(temp.
path
.
string
()) != std::string::npos,
"
working directory propagated
"
);
}
static
void
test_empty_command
()
{
BuildTask task =
command_task
(
"
empty
"
, {});
const
BuildTaskResult result =
execute_build_task_process
(task);
require
(result.
taskId
==
"
empty
"
,
"
empty task id
"
);
require
(result.
state
== BuildTaskState::Failed,
"
empty state
"
);
require
(result.
exitCode
==
127
,
"
empty exit
"
);
require
(result.
output
.
find
(
"
Empty build command
"
) != std::string::npos,
"
empty output
"
);
}
static
int
child_main
(
int
argc,
char
**argv)
{
const
std::string mode = argc >
1
? argv[
1
] :
"
"
;
if
(mode ==
"
--child-output
"
)
{
if
(argc >
2
)
std::cout << argv[
2
];
return
0
;
}
if
(mode ==
"
--child-exit
"
)
return
argc >
2
?
std::atoi
(argv[
2
]) :
0
;
if
(mode ==
"
--child-mixed-output
"
)
{
std::cout <<
"
out
\n
"
<< std::flush;
std::cerr <<
"
err
\n
"
<< std::flush;
return
0
;
}
if
(mode ==
"
--child-pwd
"
)
{
std::cout <<
fs::current_path
().
string
();
return
0
;
}
return
2
;
}
}
//
namespace
int
main
(
int
argc,
char
**argv)
{
if
(argc >
1
&&
std::string
(argv[
1
]).
rfind
(
"
--child-
"
,
0
) ==
0
)
return
child_main
(argc, argv);
try
{
selfPath =
fs::absolute
(argv[
0
]).
lexically_normal
();
test_successful_build_task
();
test_failed_build_task
();
test_output_propagation
();
test_working_directory_propagation
();
test_empty_command
();
}
catch
(
const
std::exception &ex)
{
std::cerr <<
"
BuildTaskProcessExecutorTests failed:
"
<< ex.
what
() <<
"
\n
"
;
return
1
;
}
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL