From: Calvin Wan <calvinwan@google.com>
To: git@vger.kernel.org
Cc: Calvin Wan <calvinwan@google.com>,
nasamuffin@google.com, chooglen@google.com,
jonathantanmy@google.com, linusa@google.com,
phillip.wood123@gmail.com, vdye@github.com
Subject: [RFC PATCH v2 7/7] git-std-lib: add test file to call git-std-lib.a functions
Date: Thu, 10 Aug 2023 16:36:54 +0000 [thread overview]
Message-ID: <20230810163654.275023-7-calvinwan@google.com> (raw)
In-Reply-To: <20230810163346.274132-1-calvinwan@google.com>
Add test file that directly or indirectly calls all functions defined in
git-std-lib.a object files to showcase that they do not reference
missing objects and that git-std-lib.a can stand on its own.
Certain functions that cause the program to exit or are already called
by other functions are commented out.
TODO: replace with unit tests
Signed-off-by: Calvin Wan <calvinwan@google.com>
---
t/Makefile | 4 +
t/stdlib-test.c | 239 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 243 insertions(+)
create mode 100644 t/stdlib-test.c
diff --git a/t/Makefile b/t/Makefile
index 3e00cdd801..b6d0bc9daa 100644
--- a/t/Makefile
+++ b/t/Makefile
@@ -150,3 +150,7 @@ perf:
.PHONY: pre-clean $(T) aggregate-results clean valgrind perf \
check-chainlint clean-chainlint test-chainlint
+
+test-git-std-lib:
+ cc -It -o stdlib-test stdlib-test.c -L. -l:../git-std-lib.a
+ ./stdlib-test
diff --git a/t/stdlib-test.c b/t/stdlib-test.c
new file mode 100644
index 0000000000..a5d7374e2f
--- /dev/null
+++ b/t/stdlib-test.c
@@ -0,0 +1,239 @@
+#include "../git-compat-util.h"
+#include "../abspath.h"
+#include "../hex-ll.h"
+#include "../parse.h"
+#include "../strbuf.h"
+#include "../string-list.h"
+
+/*
+ * Calls all functions from git-std-lib
+ * Some inline/trivial functions are skipped
+ */
+
+void abspath_funcs(void) {
+ struct strbuf sb = STRBUF_INIT;
+
+ fprintf(stderr, "calling abspath functions\n");
+ is_directory("foo");
+ strbuf_realpath(&sb, "foo", 0);
+ strbuf_realpath_forgiving(&sb, "foo", 0);
+ real_pathdup("foo", 0);
+ absolute_path("foo");
+ absolute_pathdup("foo");
+ prefix_filename("foo/", "bar");
+ prefix_filename_except_for_dash("foo/", "bar");
+ is_absolute_path("foo");
+ strbuf_add_absolute_path(&sb, "foo");
+ strbuf_add_real_path(&sb, "foo");
+}
+
+void hex_ll_funcs(void) {
+ unsigned char c;
+
+ fprintf(stderr, "calling hex-ll functions\n");
+
+ hexval('c');
+ hex2chr("A1");
+ hex_to_bytes(&c, "A1", 2);
+}
+
+void parse_funcs(void) {
+ intmax_t foo;
+ ssize_t foo1 = -1;
+ unsigned long foo2;
+ int foo3;
+ int64_t foo4;
+
+ fprintf(stderr, "calling parse functions\n");
+
+ git_parse_signed("42", &foo, maximum_signed_value_of_type(int));
+ git_parse_ssize_t("42", &foo1);
+ git_parse_ulong("42", &foo2);
+ git_parse_int("42", &foo3);
+ git_parse_int64("42", &foo4);
+ git_parse_maybe_bool("foo");
+ git_parse_maybe_bool_text("foo");
+ git_env_bool("foo", 1);
+ git_env_ulong("foo", 1);
+}
+
+static int allow_unencoded_fn(char ch) {
+ return 0;
+}
+
+void strbuf_funcs(void) {
+ struct strbuf *sb = xmalloc(sizeof(void*));
+ struct strbuf *sb2 = xmalloc(sizeof(void*));
+ struct strbuf sb3 = STRBUF_INIT;
+ struct string_list list = STRING_LIST_INIT_NODUP;
+ char *buf = "foo";
+ struct strbuf_expand_dict_entry dict[] = {
+ { "foo", NULL, },
+ { "bar", NULL, },
+ };
+ int fd = open("/dev/null", O_RDONLY);
+
+ fprintf(stderr, "calling strbuf functions\n");
+
+ starts_with("foo", "bar");
+ istarts_with("foo", "bar");
+ // skip_to_optional_arg_default(const char *str, const char *prefix,
+ // const char **arg, const char *def)
+ strbuf_init(sb, 0);
+ strbuf_init(sb2, 0);
+ strbuf_release(sb);
+ strbuf_attach(sb, strbuf_detach(sb, NULL), 0, 0); // calls strbuf_grow
+ strbuf_swap(sb, sb2);
+ strbuf_setlen(sb, 0);
+ strbuf_trim(sb); // calls strbuf_rtrim, strbuf_ltrim
+ // strbuf_rtrim() called by strbuf_trim()
+ // strbuf_ltrim() called by strbuf_trim()
+ strbuf_trim_trailing_dir_sep(sb);
+ strbuf_trim_trailing_newline(sb);
+ strbuf_reencode(sb, "foo", "bar");
+ strbuf_tolower(sb);
+ strbuf_add_separated_string_list(sb, " ", &list);
+ strbuf_list_free(strbuf_split_buf("foo bar", 8, ' ', -1));
+ strbuf_cmp(sb, sb2);
+ strbuf_addch(sb, 1);
+ strbuf_splice(sb, 0, 1, "foo", 3);
+ strbuf_insert(sb, 0, "foo", 3);
+ // strbuf_vinsertf() called by strbuf_insertf
+ strbuf_insertf(sb, 0, "%s", "foo");
+ strbuf_remove(sb, 0, 1);
+ strbuf_add(sb, "foo", 3);
+ strbuf_addbuf(sb, sb2);
+ strbuf_join_argv(sb, 0, NULL, ' ');
+ strbuf_addchars(sb, 1, 1);
+ strbuf_addf(sb, "%s", "foo");
+ strbuf_add_commented_lines(sb, "foo", 3, '#');
+ strbuf_commented_addf(sb, '#', "%s", "foo");
+ // strbuf_vaddf() called by strbuf_addf()
+ strbuf_expand(sb, "%s", strbuf_expand_literal_cb, NULL);
+ strbuf_expand(sb, "%s", strbuf_expand_dict_cb, &dict);
+ // strbuf_expand_literal_cb() called by strbuf_expand()
+ // strbuf_expand_dict_cb() called by strbuf_expand()
+ strbuf_addbuf_percentquote(sb, &sb3);
+ strbuf_add_percentencode(sb, "foo", STRBUF_ENCODE_SLASH);
+ strbuf_fread(sb, 0, stdin);
+ strbuf_read(sb, fd, 0);
+ strbuf_read_once(sb, fd, 0);
+ strbuf_write(sb, stderr);
+ strbuf_readlink(sb, "/dev/null", 0);
+ strbuf_getcwd(sb);
+ strbuf_getwholeline(sb, stderr, '\n');
+ strbuf_appendwholeline(sb, stderr, '\n');
+ strbuf_getline(sb, stderr);
+ strbuf_getline_lf(sb, stderr);
+ strbuf_getline_nul(sb, stderr);
+ strbuf_getwholeline_fd(sb, fd, '\n');
+ strbuf_read_file(sb, "/dev/null", 0);
+ strbuf_add_lines(sb, "foo", "bar", 0);
+ strbuf_addstr_xml_quoted(sb, "foo");
+ strbuf_addstr_urlencode(sb, "foo", allow_unencoded_fn);
+ strbuf_humanise_bytes(sb, 42);
+ strbuf_humanise_rate(sb, 42);
+ printf_ln("%s", sb);
+ fprintf_ln(stderr, "%s", sb);
+ xstrdup_tolower("foo");
+ xstrdup_toupper("foo");
+ // xstrvfmt() called by xstrfmt()
+ xstrfmt("%s", "foo");
+ // strbuf_addftime(struct strbuf *sb, const char *fmt, const struct tm *tm,
+ // int tz_offset, int suppress_tz_name)
+ // strbuf_stripspace(struct strbuf *sb, char comment_line_char)
+ // strbuf_strip_suffix(struct strbuf *sb, const char *suffix)
+ // strbuf_strip_file_from_path(struct strbuf *sb)
+}
+
+static void error_builtin(const char *err, va_list params) {}
+static void warn_builtin(const char *err, va_list params) {}
+
+static report_fn error_routine = error_builtin;
+static report_fn warn_routine = warn_builtin;
+
+void usage_funcs(void) {
+ fprintf(stderr, "calling usage functions\n");
+ // Functions that call exit() are commented out
+
+ // usage()
+ // usagef()
+ // die()
+ // die_errno();
+ error("foo");
+ error_errno("foo");
+ die_message("foo");
+ die_message_errno("foo");
+ warning("foo");
+ warning_errno("foo");
+
+ // set_die_routine();
+ get_die_message_routine();
+ set_error_routine(error_builtin);
+ get_error_routine();
+ set_warn_routine(warn_builtin);
+ get_warn_routine();
+ // set_die_is_recursing_routine();
+}
+
+void wrapper_funcs(void) {
+ void *ptr = xmalloc(1);
+ int fd = open("/dev/null", O_RDONLY);
+ struct strbuf sb = STRBUF_INIT;
+ int mode = 0444;
+ char host[PATH_MAX], path[PATH_MAX], path1[PATH_MAX];
+ xsnprintf(path, sizeof(path), "out-XXXXXX");
+ xsnprintf(path1, sizeof(path1), "out-XXXXXX");
+ int tmp;
+
+ fprintf(stderr, "calling wrapper functions\n");
+
+ xstrdup("foo");
+ xmalloc(1);
+ xmallocz(1);
+ xmallocz_gently(1);
+ xmemdupz("foo", 3);
+ xstrndup("foo", 3);
+ xrealloc(ptr, 2);
+ xcalloc(1, 1);
+ xsetenv("foo", "bar", 0);
+ xopen("/dev/null", O_RDONLY);
+ xread(fd, &sb, 1);
+ xwrite(fd, &sb, 1);
+ xpread(fd, &sb, 1, 0);
+ xdup(fd);
+ xfopen("/dev/null", "r");
+ xfdopen(fd, "r");
+ tmp = xmkstemp(path);
+ close(tmp);
+ unlink(path);
+ tmp = xmkstemp_mode(path1, mode);
+ close(tmp);
+ unlink(path1);
+ xgetcwd();
+ fopen_for_writing(path);
+ fopen_or_warn(path, "r");
+ xstrncmpz("foo", "bar", 3);
+ // xsnprintf() called above
+ xgethostname(host, 3);
+ tmp = git_mkstemps_mode(path, 1, mode);
+ close(tmp);
+ unlink(path);
+ tmp = git_mkstemp_mode(path, mode);
+ close(tmp);
+ unlink(path);
+ read_in_full(fd, &sb, 1);
+ write_in_full(fd, &sb, 1);
+ pread_in_full(fd, &sb, 1, 0);
+}
+
+int main() {
+ abspath_funcs();
+ hex_ll_funcs();
+ parse_funcs();
+ strbuf_funcs();
+ usage_funcs();
+ wrapper_funcs();
+ fprintf(stderr, "all git-std-lib functions finished calling\n");
+ return 0;
+}
--
2.41.0.640.ga95def55d0-goog
next prev parent reply other threads:[~2023-08-10 16:38 UTC|newest]
Thread overview: 111+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-27 19:52 [RFC PATCH 0/8] Introduce Git Standard Library Calvin Wan
2023-06-27 19:52 ` [RFC PATCH 1/8] trace2: log fsync stats in trace2 rather than wrapper Calvin Wan
2023-06-28 2:05 ` Victoria Dye
2023-07-05 17:57 ` Calvin Wan
2023-07-05 18:22 ` Victoria Dye
2023-07-11 20:07 ` Jeff Hostetler
2023-06-27 19:52 ` [RFC PATCH 2/8] hex-ll: split out functionality from hex Calvin Wan
2023-06-28 13:15 ` Phillip Wood
2023-06-28 16:55 ` Calvin Wan
2023-06-27 19:52 ` [RFC PATCH 3/8] object: move function to object.c Calvin Wan
2023-06-27 19:52 ` [RFC PATCH 4/8] config: correct bad boolean env value error message Calvin Wan
2023-06-27 19:52 ` [RFC PATCH 5/8] parse: create new library for parsing strings and env values Calvin Wan
2023-06-27 22:58 ` Junio C Hamano
2023-06-27 19:52 ` [RFC PATCH 6/8] pager: remove pager_in_use() Calvin Wan
2023-06-27 23:00 ` Junio C Hamano
2023-06-27 23:18 ` Calvin Wan
2023-06-28 0:30 ` Glen Choo
2023-06-28 16:37 ` Glen Choo
2023-06-28 16:44 ` Calvin Wan
2023-06-28 17:30 ` Junio C Hamano
2023-06-28 20:58 ` Junio C Hamano
2023-06-27 19:52 ` [RFC PATCH 7/8] git-std-lib: introduce git standard library Calvin Wan
2023-06-28 13:27 ` Phillip Wood
2023-06-28 21:15 ` Calvin Wan
2023-06-30 10:00 ` Phillip Wood
2023-06-27 19:52 ` [RFC PATCH 8/8] git-std-lib: add test file to call git-std-lib.a functions Calvin Wan
2023-06-28 0:14 ` [RFC PATCH 0/8] Introduce Git Standard Library Glen Choo
2023-06-28 16:30 ` Calvin Wan
2023-06-30 7:01 ` Linus Arver
2023-08-10 16:33 ` [RFC PATCH v2 0/7] " Calvin Wan
2023-08-10 16:36 ` [RFC PATCH v2 1/7] hex-ll: split out functionality from hex Calvin Wan
2023-08-10 16:36 ` [RFC PATCH v2 2/7] object: move function to object.c Calvin Wan
2023-08-10 20:32 ` Junio C Hamano
2023-08-10 22:36 ` Glen Choo
2023-08-10 22:43 ` Junio C Hamano
2023-08-10 16:36 ` [RFC PATCH v2 3/7] config: correct bad boolean env value error message Calvin Wan
2023-08-10 20:36 ` Junio C Hamano
2023-08-10 16:36 ` [RFC PATCH v2 4/7] parse: create new library for parsing strings and env values Calvin Wan
2023-08-10 23:21 ` Glen Choo
2023-08-10 23:43 ` Junio C Hamano
2023-08-14 22:15 ` Jonathan Tan
2023-08-14 22:09 ` Jonathan Tan
2023-08-14 22:19 ` Junio C Hamano
2023-08-10 16:36 ` [RFC PATCH v2 5/7] date: push pager.h dependency up Calvin Wan
2023-08-10 23:41 ` Glen Choo
2023-08-14 22:17 ` Jonathan Tan
2023-08-10 16:36 ` [RFC PATCH v2 6/7] git-std-lib: introduce git standard library Calvin Wan
2023-08-14 22:26 ` Jonathan Tan
2023-08-10 16:36 ` Calvin Wan [this message]
2023-08-14 22:28 ` [RFC PATCH v2 7/7] git-std-lib: add test file to call git-std-lib.a functions Jonathan Tan
2023-08-10 22:05 ` [RFC PATCH v2 0/7] Introduce Git Standard Library Glen Choo
2023-08-15 9:20 ` Phillip Wood
2023-08-16 17:17 ` Calvin Wan
2023-08-16 21:19 ` Junio C Hamano
2023-08-15 9:41 ` Phillip Wood
2023-09-08 17:41 ` [PATCH v3 0/6] " Calvin Wan
2023-09-08 17:44 ` [PATCH v3 1/6] hex-ll: split out functionality from hex Calvin Wan
2023-09-08 17:44 ` [PATCH v3 2/6] wrapper: remove dependency to Git-specific internal file Calvin Wan
2023-09-15 17:54 ` Jonathan Tan
2023-09-08 17:44 ` [PATCH v3 3/6] config: correct bad boolean env value error message Calvin Wan
2023-09-08 17:44 ` [PATCH v3 4/6] parse: create new library for parsing strings and env values Calvin Wan
2023-09-08 17:44 ` [PATCH v3 5/6] git-std-lib: introduce git standard library Calvin Wan
2023-09-11 13:22 ` Phillip Wood
2023-09-27 14:14 ` Phillip Wood
2023-09-15 18:39 ` Jonathan Tan
2023-09-26 14:23 ` phillip.wood123
2023-09-08 17:44 ` [PATCH v3 6/6] git-std-lib: add test file to call git-std-lib.a functions Calvin Wan
2023-09-09 5:26 ` Junio C Hamano
2023-09-15 18:43 ` Jonathan Tan
2023-09-15 20:22 ` Junio C Hamano
2023-09-08 20:36 ` [PATCH v3 0/6] Introduce Git Standard Library Junio C Hamano
2023-09-08 21:30 ` Junio C Hamano
2023-09-29 21:20 ` [PATCH v4 0/4] Preliminary patches before git-std-lib Jonathan Tan
2023-09-29 21:20 ` [PATCH v4 1/4] hex-ll: separate out non-hash-algo functions Jonathan Tan
2023-10-21 4:14 ` Linus Arver
2023-09-29 21:20 ` [PATCH v4 2/4] wrapper: reduce scope of remove_or_warn() Jonathan Tan
2023-10-10 9:59 ` phillip.wood123
2023-10-10 16:13 ` Junio C Hamano
2023-10-10 17:38 ` Jonathan Tan
2023-09-29 21:20 ` [PATCH v4 3/4] config: correct bad boolean env value error message Jonathan Tan
2023-09-29 23:03 ` Junio C Hamano
2023-09-29 21:20 ` [PATCH v4 4/4] parse: separate out parsing functions from config.h Jonathan Tan
2023-10-10 10:00 ` phillip.wood123
2023-10-10 17:43 ` Jonathan Tan
2023-10-10 17:58 ` Phillip Wood
2023-10-10 20:57 ` Junio C Hamano
2023-10-10 10:05 ` [PATCH v4 0/4] Preliminary patches before git-std-lib phillip.wood123
2023-10-10 16:21 ` Jonathan Tan
2024-02-22 17:50 ` [PATCH v5 0/3] Introduce Git Standard Library Calvin Wan
2024-02-22 17:50 ` [PATCH v5 1/3] pager: include stdint.h because uintmax_t is used Calvin Wan
2024-02-22 21:43 ` Junio C Hamano
2024-02-26 18:59 ` Kyle Lippincott
2024-02-27 0:20 ` Junio C Hamano
2024-02-27 0:56 ` Kyle Lippincott
2024-02-27 2:45 ` Junio C Hamano
2024-02-27 22:29 ` Kyle Lippincott
2024-02-27 23:25 ` Junio C Hamano
2024-02-27 8:45 ` Jeff King
2024-02-27 9:05 ` Jeff King
2024-02-27 20:10 ` Kyle Lippincott
2024-02-24 1:33 ` Kyle Lippincott
2024-02-24 7:58 ` Junio C Hamano
2024-02-22 17:50 ` [PATCH v5 2/3] git-std-lib: introduce Git Standard Library Calvin Wan
2024-02-29 11:16 ` Phillip Wood
2024-02-29 17:23 ` Junio C Hamano
2024-02-29 18:27 ` Linus Arver
2024-02-29 18:54 ` Junio C Hamano
2024-02-29 20:03 ` Linus Arver
2024-02-22 17:50 ` [PATCH v5 3/3] test-stdlib: show that git-std-lib is independent Calvin Wan
2024-02-22 22:24 ` Junio C Hamano
2024-03-07 21:13 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230810163654.275023-7-calvinwan@google.com \
--to=calvinwan@google.com \
--cc=chooglen@google.com \
--cc=git@vger.kernel.org \
--cc=jonathantanmy@google.com \
--cc=linusa@google.com \
--cc=nasamuffin@google.com \
--cc=phillip.wood123@gmail.com \
--cc=vdye@github.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).