Skip to content

Commit bb2d3af

Browse files
Mikachu2333ccmywish
authored andcommitted
增加相应的测试
1 parent 128a9c2 commit bb2d3af

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

test/fw.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,37 +48,37 @@ main (int argc, char const *argv[])
4848
assert (chsrc_check_program_quietly_when_exist ("curl"));
4949
chsrc_ensure_program ("curl");
5050

51-
#define bkup "README.md.bak"
51+
chsrc_ensure_dir ("test");
5252

53-
chsrc_backup ("README.md");
54-
assert (chsrc_check_file (bkup));
53+
char *tmpfile_content = "Line2\n\nLine3\n";
54+
char *tmpfile_name = "test";
55+
char *tmpfile_ext = ".txt";
56+
char *tmpfile = "";
5557

56-
chsrc_ensure_dir ("test");
58+
FILE *tmp = chsrc_make_tmpfile (tmpfile_name, tmpfile_ext, true, &tmpfile);
59+
fwrite (tmpfile_content, sizeof (char), strlen (tmpfile_content), tmp);
60+
fclose (tmp);
5761

58-
chsrc_append_to_file ("append", bkup);
59-
if (!xy.on_windows)
60-
{
61-
chsrc_prepend_to_file ("prepend", bkup);
62-
}
63-
chsrc_overwrite_file ("overwrite", bkup);
64-
chsrc_view_file (bkup);
62+
char *tmpfile_bk = xy_2strcat (tmpfile, ".bak");
63+
64+
assert (xy_file_exist (tmpfile));
65+
chsrc_backup (tmpfile);\
66+
assert (chsrc_check_file (tmpfile_bk));
67+
remove (tmpfile_bk);
68+
69+
chsrc_append_to_file ("Line4\n", tmpfile);
70+
assert_str (xy_file_to_str (tmpfile), "Line2\n\nLine3\nLine4\n");
71+
72+
chsrc_prepend_to_file ("Line1 \n", tmpfile);
73+
assert_str (xy_file_to_str (tmpfile), "Line1 \nLine2\n\nLine3\nLine4\n");
74+
75+
chsrc_overwrite_file ("Line999 \nLine998\nLine997\n", tmpfile);
76+
assert_str (xy_file_to_str (tmpfile), "Line999 \nLine998\nLine997\n");
6577

6678
chsrc_log (xy_2strcat ("CPU arch = ", chsrc_get_cpuarch ()));
6779
print ("chsrc: CPU cores = ");
6880
println (chsrc_get_cpucore ());
6981

70-
if (xy.on_windows)
71-
{
72-
chsrc_run ("del " bkup, RunOpt_No_Last_New_Line);
73-
}
74-
else
75-
{
76-
chsrc_run ("rm " bkup, RunOpt_No_Last_New_Line);
77-
}
78-
79-
char *tmpfile = NULL;
80-
FILE *tmp = chsrc_make_tmpfile ("tmpfile", ".txt", true, &tmpfile);
81-
fclose (tmp);
8282
remove (tmpfile);
8383

8484
// chsrc_run_in_inline_pwsh_shell ("Write-Host \"Hello from inline PowerShell\"");

0 commit comments

Comments
 (0)