Skip to content

Commit db6db48

Browse files
committed
Merge branch 'master' of github.com:sagiegurari/c_scriptexec
2 parents a4d098f + c920c58 commit db6db48

7 files changed

Lines changed: 21 additions & 5 deletions

src/scriptexec.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ struct ScriptExecResult scriptexec_run_with_options(const char *script, struct S
129129
result.out = read_text_file(out_file, buffer);
130130
result.err = read_text_file(err_file, buffer);
131131

132+
// delete files
133+
remove(script_file);
134+
rmdir(dir_name);
135+
132136
string_buffer_release(buffer);
133137

134138
return(result);
@@ -159,6 +163,7 @@ char *read_text_file(char *file, struct StringBuffer *buffer)
159163
}
160164

161165
fclose(fp);
166+
remove(file);
162167

163168
return(string_buffer_to_string(buffer));
164169
}

tests/test.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,13 @@ void assert_string_equal(char *value1, char *value2)
4848
test_fail();
4949
}
5050
}
51+
52+
53+
void assert_string_starts_with(char *string, char *prefix)
54+
{
55+
if (strncmp(prefix, string, strlen(prefix)) != 0)
56+
{
57+
printf("assert failed, value: %s does not start with: %s", string, prefix);
58+
test_fail();
59+
}
60+
}

tests/test.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ void assert_true(bool);
1010

1111
void assert_num_equal(size_t, size_t);
1212
void assert_string_equal(char *, char *);
13+
void assert_string_starts_with(char * /* string */, char * /* prefix */);
1314

1415
#endif
1516

tests/test_exit_on_error_valid.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ void test_impl()
1212
struct ScriptExecResult result = scriptexec_run_with_options("echo 1\necho 2\necho 3\necho 4", options);
1313

1414
assert_num_equal(result.code, 0);
15-
assert_string_equal(result.out, "1\n2\n3\n4\n");
15+
assert_string_starts_with(result.out, "1\n2\n3\n4");
1616
assert_string_equal(result.err, "");
1717
}
1818

tests/test_valid_multiple_commands.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ void test_impl()
77
struct ScriptExecResult result = scriptexec_run("echo 1\necho 2\necho 3\necho 4");
88

99
assert_num_equal(result.code, 0);
10-
assert_string_equal(result.out, "1\n2\n3\n4\n");
10+
assert_string_starts_with(result.out, "1\n2\n3\n4");
1111
assert_string_equal(result.err, "");
1212
}
1313

tests/test_valid_multiple_commands_default_options.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ void test_impl()
99
struct ScriptExecResult result = scriptexec_run_with_options("echo 1\necho 2\necho 3\necho 4", options);
1010

1111
assert_num_equal(result.code, 0);
12-
assert_string_equal(result.out, "1\n2\n3\n4\n");
12+
assert_string_starts_with(result.out, "1\n2\n3\n4");
1313
assert_string_equal(result.err, "");
1414
}
1515

tests/test_valid_multiple_commands_with_valid_runner.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ void test_impl()
66
{
77
struct ScriptExecOptions options = scriptexec_create_options();
88

9-
options.runner = "bash";
9+
options.runner = "sh";
1010

1111
struct ScriptExecResult result = scriptexec_run_with_options("echo 1\necho 2\necho 3\necho 4", options);
1212

1313
assert_num_equal(result.code, 0);
14-
assert_string_equal(result.out, "1\n2\n3\n4\n");
14+
assert_string_starts_with(result.out, "1\n2\n3\n4");
1515
assert_string_equal(result.err, "");
1616
}
1717

0 commit comments

Comments
 (0)