Skip to content

Commit b7647dd

Browse files
committed
better framework for ft_sh1 tests
1 parent a23901f commit b7647dd

File tree

9 files changed

+69
-22
lines changed

9 files changed

+69
-22
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ main.build.c
22
unit_test
33
*.o
44
*.so
5+
*.out
56
libft/moulitest
67

78
# USER LOCAL FILES
@@ -26,4 +27,4 @@ get_next_line_tests/get_next_line_tests*
2627
ft_printf_tests/ft_printf_test*
2728
testframework/v3/libmt_framework.a
2829
testframework/fake_rendu/ft_ls/ft_ls
29-
template_tests/sample_test*
30+
template_tests/sample_tests*

ft_sh1_tests/Makefile_cfg.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
NAME = sample_test
1+
NAME = ft_sh1_tests.out
22

33
# RENDU_PATH_KEY is the key used to retrieve
44
# your project "rendu" folder from config.ini

ft_sh1_tests/project.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: yyang <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2014/12/10 00:54:40 by celegran #+# #+# */
9-
/* Updated: 2015/01/25 21:23:12 by yyang ### ########.fr */
9+
/* Updated: 2015/01/26 10:49:38 by yyang ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -19,4 +19,6 @@
1919

2020
# include <fw.h>
2121

22+
void mt_assert_sh(t_test *test, char *commands, char *assert_filter);
23+
2224
#endif

ft_sh1_tests/tests/00_no_conv.spec.c

-15
This file was deleted.
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <project.h>
2+
3+
static void failing_test(t_test *test)
4+
{
5+
test->debug = 1;
6+
mt_assert_sh(test, "cd /usr\n"
7+
"pwd\n"
8+
"exit\n", "grep /usr");
9+
}
10+
11+
void suite_0_sh1_00_cmd_cd(t_suite *suite)
12+
{
13+
SUITE_ADD_TEST(suite, failing_test);
14+
}

ft_sh1_tests/utils.c

+45
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,48 @@
1+
/* ************************************************************************** */
2+
/* */
3+
/* ::: :::::::: */
4+
/* utils.c :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: yyang <[email protected]> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2015/01/26 10:22:27 by yyang #+# #+# */
9+
/* Updated: 2015/01/26 11:12:04 by yyang ### ########.fr */
10+
/* */
11+
/* ************************************************************************** */
12+
113
/*
214
** Project wide utility functions goes here
315
*/
16+
17+
#include <fw.h>
18+
#include <stdio.h>
19+
#include <mt_xstdio.h>
20+
#include <stdbool.h>
21+
22+
#define MT_MAX_CMD_LENGTH 100 * 1000
23+
#define SANDBOX_PATH "sandbox"
24+
#define OUTPUT_AFTER_FILTER_FILE_PATH SANDBOX_PATH"/output_test"
25+
#define RAW_OUTPUT_PATH SANDBOX_PATH"/output_raw"
26+
27+
void mt_assert_sh(t_test *test, char *commands, char *assert_filter)
28+
{
29+
char generate_raw_cmd[MT_MAX_CMD_LENGTH];
30+
char filter_cmd[MT_MAX_CMD_LENGTH];
31+
32+
if (SANDBOX_PATH)
33+
system("rm -rf "SANDBOX_PATH);
34+
system("mkdir -p "SANDBOX_PATH);
35+
sprintf(generate_raw_cmd, "printf '%s' | "RENDU_PATH"/ft_sh1 > "RAW_OUTPUT_PATH, commands);
36+
sprintf(filter_cmd, "cat "RAW_OUTPUT_PATH" | %s > "OUTPUT_AFTER_FILTER_FILE_PATH, assert_filter);
37+
if (test->debug)
38+
{
39+
printf("\n================== cmd ==================\n");
40+
printf("%s\n", generate_raw_cmd);
41+
printf("================ filter =================\n");
42+
printf("%s\n", filter_cmd);
43+
printf("=========================================\n");
44+
}
45+
system(generate_raw_cmd);
46+
system(filter_cmd);
47+
mt_assert(!mt_isemptyfile(OUTPUT_AFTER_FILTER_FILE_PATH));
48+
}

template_tests/Makefile_cfg.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
NAME = sample_test
1+
NAME = sample_tests.out
22

33
# RENDU_PATH_KEY is the key used to retrieve
44
# your project "rendu" folder from config.ini

testframework/v3/includes/mt_xstdio.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
#ifndef MT_XSTDIO
1414
#define MT_XSTDIO
1515

16-
int mt_xstdio_isempty(const char *path);
16+
int mt_isemptyfile(const char *path);
1717

1818
#endif

testframework/v3/srcs/mt_xstdio/mt_xstdio_isempty.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
/* By: yyang <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2015/01/25 22:16:18 by yyang #+# #+# */
9-
/* Updated: 2015/01/25 22:17:31 by yyang ### ########.fr */
9+
/* Updated: 2015/01/26 10:28:47 by yyang ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

1313
#include <stdio.h>
1414

15-
int mt_xstdio_isempty(const char *path)
15+
int mt_isemptyfile(const char *path)
1616
{
1717
FILE *fp;
1818

0 commit comments

Comments
 (0)