Subprocess with pipe capturing
This commit is contained in:
parent
7a3f1955b9
commit
a0da4ce1a3
6 changed files with 225 additions and 0 deletions
|
@ -44,3 +44,11 @@ target_link_libraries(BinaryTree-test
|
|||
pointers
|
||||
allocator-interface
|
||||
)
|
||||
|
||||
add_executable(Subprocess-test Subprocess.test.c)
|
||||
target_link_libraries(Subprocess-test
|
||||
Subprocess
|
||||
threading
|
||||
pointers
|
||||
allocator-interface
|
||||
)
|
||||
|
|
31
tests/Subprocess.test.c
Normal file
31
tests/Subprocess.test.c
Normal file
|
@ -0,0 +1,31 @@
|
|||
#include "../src/Subprocess/Subprocess.h"
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
char read_buffer[128];
|
||||
|
||||
void testEcho()
|
||||
{
|
||||
Subprocess sub;
|
||||
sub.in .type = SUBPROCESSREDIRECTIONTYPE_PIPE;
|
||||
sub.out.type = SUBPROCESSREDIRECTIONTYPE_PIPE;
|
||||
sub.err.type = SUBPROCESSREDIRECTIONTYPE_PIPE;
|
||||
|
||||
char* argv[] = { "echo", "Hello World!", NULL };
|
||||
|
||||
assert(EXIT_SUCCESS == Subprocess_Create(&sub, "/usr/bin/echo", argv));
|
||||
ssize_t read_size = read(sub.out.get.pipefd, read_buffer, 128);
|
||||
assert(read_size == 13);
|
||||
assert(strcmp(read_buffer, "Hello World!\n") == 0);
|
||||
assert(read(sub.out.get.pipefd, read_buffer, 128) == 0);
|
||||
Subprocess_Destroy(&sub);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
testEcho();
|
||||
return 0;
|
||||
}
|
|
@ -79,6 +79,38 @@ void testGroup(void)
|
|||
assert(RegexMatch_HaveNumberedCapture(&match, 1));
|
||||
assert(RegexMatch_HaveNumberedCapture(&match, 2));
|
||||
|
||||
Regex_Destroy(®ex);
|
||||
RegexMatch_Destroy(&match);
|
||||
assert(allocator.reserved == 0);
|
||||
Allocator_DestroySystemAllocator(&allocator);
|
||||
return;
|
||||
}
|
||||
|
||||
void testOption(void)
|
||||
{
|
||||
StringView regex_string = StringView_FromString("abc|def|");
|
||||
StringView match_string_0 = StringView_FromString("abc");
|
||||
StringView match_string_1 = StringView_FromString("def");
|
||||
StringView match_string_2 = StringView_FromString("");
|
||||
allocator_t allocator;
|
||||
Allocator_CreateSystemAllocator(&allocator);
|
||||
|
||||
Regex regex;
|
||||
assert(Regex_Create(®ex, &allocator) == EXIT_SUCCESS);
|
||||
|
||||
assert(Regex_Compile(®ex, regex_string) == EXIT_SUCCESS);
|
||||
|
||||
RegexMatch match;
|
||||
|
||||
assert(Regex_FirstMatch(®ex, match_string_0, &match) == EXIT_SUCCESS);
|
||||
assert(StringView_Equal(match.match, match_string_0));
|
||||
|
||||
assert(Regex_FirstMatch(®ex, match_string_1, &match) == EXIT_SUCCESS);
|
||||
assert(StringView_Equal(match.match, match_string_1));
|
||||
|
||||
assert(Regex_FirstMatch(®ex, match_string_2, &match) == EXIT_SUCCESS);
|
||||
assert(StringView_Equal(match.match, match_string_2));
|
||||
|
||||
Regex_Destroy(®ex);
|
||||
assert(allocator.reserved == 0);
|
||||
Allocator_DestroySystemAllocator(&allocator);
|
||||
|
@ -118,6 +150,7 @@ int main()
|
|||
testLiteral();
|
||||
testBackslash();
|
||||
testGroup();
|
||||
testOption();
|
||||
testQuantifier();
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue