From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mail-a.sr.ht; dkim=pass header.d=maniero.me header.i=@maniero.me Received: from butterfly.birch.relay.mailchannels.net (butterfly.birch.relay.mailchannels.net [23.83.209.27]) by mail-a.sr.ht (Postfix) with ESMTPS id 4A542200EF for <~johnnyrichard/olang-devel@lists.sr.ht>; Mon, 19 Feb 2024 10:01:53 +0000 (UTC) X-Sender-Id: hostingeremail|x-authuser|carlos@maniero.me Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 63D248422CB for <~johnnyrichard/olang-devel@lists.sr.ht>; Mon, 19 Feb 2024 10:01:51 +0000 (UTC) Received: from fr-int-smtpout5.hostinger.io (unknown [127.0.0.6]) (Authenticated sender: hostingeremail) by relay.mailchannels.net (Postfix) with ESMTPA id A06E78420E1 for <~johnnyrichard/olang-devel@lists.sr.ht>; Mon, 19 Feb 2024 10:01:50 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1708336910; a=rsa-sha256; cv=none; b=yLkzpRnOdKZj/Fxr1Q5AsLzbKyhhGRiwgkflWDagKtYfnyoGMFJUbXeM5RZNoFaAWpeMjO dSI6wHXDhbbjgOovBem8qF7FJSjuNLBcJYK9BTsRg3c1bunt00WRQFfpCqvQSnO8QknGVs GAE1jSQEc/zEnKTsxj8BwU0xz2JHZ4ap9y8dxCtpnT47UsZSgAlGYAYIwPBAwcUTEP9gT8 NAHUaER+RYOQmjZpkuigNBteoNwBmqPRZ+AkDuCMA/cnUbC+8+3EE4D1rAMR1mzjKu2vl3 x2yGBng4RZrHx+tx797y4n++w6HsuPgU3qbZ8obV8PAyng7VSgk8iWFxDEGjBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1708336910; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=KtZSdSJmUnMI772iBeFqQVxcoEtgPDze4ZTvE3OLuaU=; b=EJS5q1Hnjbl/JLXyPFIEAC1MCGxG0pxXyz8pIIa3fjBB4asi3jPutXmTp3W39dMKehATNj /WoW/IC2xbX/cFM48JBo1VpM+ev9JpP5A398E14KWJ2CWGkXQFXvKgLPCaRRkXAQBFOuCk uysoHcInuAczzDjPfyho/kgcP6tzkQ0FGZ6IpeEh4eNomKJzZLBysRVcTxGbJUxmoXvy4w iHxHRfI5wo/w50dZxIIzAYyPIv3TakCC3yQBwWpGCuZyzs1adr0WwGKlnlZDK5TYMDJfNy nWpDuljRV46SwSpONHXuWrLiiuHUA1X0EQL/Ytsbe64RHBTJ1UtAR9ujY/aUeg== ARC-Authentication-Results: i=1; rspamd-6bdc45795d-zkpt9; auth=pass smtp.auth=hostingeremail smtp.mailfrom=carlos@maniero.me X-Sender-Id: hostingeremail|x-authuser|carlos@maniero.me X-MC-Relay: Neutral X-MailChannels-SenderId: hostingeremail|x-authuser|carlos@maniero.me X-MailChannels-Auth-Id: hostingeremail X-Coil-Unite: 70e9386b01c54e28_1708336911209_3262177635 X-MC-Loop-Signature: 1708336911209:3076339824 X-MC-Ingress-Time: 1708336911209 Received: from fr-int-smtpout5.hostinger.io ([UNAVAILABLE]. [89.116.146.168]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.119.153.94 (trex/6.9.2); Mon, 19 Feb 2024 10:01:51 +0000 Mime-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=maniero.me; s=hostingermail1; t=1708336905; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=V1ArjQ5JgiKEM1Y3/IrmU0G5dsW/jXX9efM9ZCIFe1Y=; b=OUvopHl4Bl482lHp4UVKV2FHnSgpRcvN6+VS6NJI65C2l7DVSLjl4VlZKcFEcd/GSls4hT Q+cJzWvdW2LE7NEpj5Rb0SiFb4Ys04umgVmc+IhzJ3iloelfDgvgny1LubaT9ztnx+lddC R4IfmTp20L5TaE7Db0npKD4VGrDhPy5Rj3dfhy2itYBVcmoszHrfFuqzrUPGKd0V6j8tJS OOQ/Ei+kJBxNUdjaiyRLbT7kVeKqi77kflQZuO6k9NlF56Rs6Yw5RSBZXAzaIqT/hqJq2f khVa0aoUGZoOzqWAybz1PluOoKJhRV+gkKaH5luOgcyy3nMYCHJGmdKWyuneKg== Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Mon, 19 Feb 2024 07:01:37 -0300 Message-Id: Subject: Re: [PATCH olang v3 2/2] lexer: create --dump-tokens cli command From: "Carlos Maniero" To: "Johnny Richard" , <~johnnyrichard/olang-devel@lists.sr.ht> X-Mailer: aerc 0.15.2-211-g37d5fc691aff References: <20240219013843.15707-1-johnny@johnnyrichard.com> <20240219013843.15707-4-johnny@johnnyrichard.com> In-Reply-To: <20240219013843.15707-4-johnny@johnnyrichard.com> X-CM-Analysis: v=2.4 cv=FdIxxo+6 c=1 sm=1 tr=0 ts=65d32709 a=5+VMC1FZ3J4mVPAKpPmAqg==:117 a=5+VMC1FZ3J4mVPAKpPmAqg==:17 a=IkcTkHD0fZMA:10 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=BXDaF_L80NYA:10 a=mrBPhR1UejvE6VmIkLwA:9 a=QEXdDO2ut3YA:10 X-CM-Envelope: MS4xfMebGGkIqFOHgvXvdTqEjL5f7xlESDYy6zzzXotJ39tgOrX1D3P1Fy4vPFh6SILBtXhDJesy9P7l5EUpXbdX/2SDhu++NWHfMLz5ahqIahZ5R3Yv6nFA //XZcuPZyoxRsbndx8JfNpFcOOG3qtHxrn8acJHoP+0DuV1VuuYbI5cjZ2r8M7kH6X3vgH9NYAI1sJKREn3zlLqtMVfF6grhze7B9MfC6kAAvo7XKDIPBjCY nqpn+jaWFgqMuW66iJwf7Q== X-AuthUser: carlos@maniero.me X-TUID: 61itA+W9xPia I'm sending here the integration tests of the --dump-tokens, in case you want to send a new patch with one less TODO. But feel free to ignore this message, I can send a new patch after this one= is merged. Just to let you know the cli_runner was extended to intercept the program stdout. -- >8 -- tests/integration/cli_runner.c | 47 ++++++++++++++++++++++++++++++---- tests/integration/cli_runner.h | 1 + tests/integration/cli_test.c | 14 ++++++++++ 3 files changed, 57 insertions(+), 5 deletions(-) diff --git a/tests/integration/cli_runner.c b/tests/integration/cli_runner.= c index 0531bcc..7e4fe9a 100644 --- a/tests/integration/cli_runner.c +++ b/tests/integration/cli_runner.c @@ -20,6 +20,7 @@ #include #include #include +#include #include =20 #define OLANG_COMPILER_PATH "../../0c" @@ -62,16 +63,52 @@ create_tmp_file_name(char *file_name) } =20 cli_result_t -cli_runner_compiler_dump_tokens(char *src) +cli_runner_compiler(char *src, char *args[]) { assert_compiler_exists(); =20 - cli_result_t result; + cli_result_t result =3D { 0 }; create_tmp_file_name(result.program_path); =20 - char command[1024]; - sprintf(command, "%s %s --dump-tokens", OLANG_COMPILER_PATH, src); + int fd_link[2]; + + if (pipe(fd_link) =3D=3D -1) { + perror("pipe error."); + exit(1); + } + + pid_t pid =3D fork(); + + if (pid =3D=3D -1) { + perror("fork error."); + exit(1); + } + + if (pid =3D=3D 0) { + dup2(fd_link[1], STDOUT_FILENO); + close(fd_link[0]); + close(fd_link[1]); + + execv(OLANG_COMPILER_PATH, args); + perror("execl error."); + exit(127); + } else { + close(fd_link[1]); + if (read(fd_link[0], result.compiler_output, sizeof(result.compile= r_output)) =3D=3D -1) { + perror("read error."); + exit(1); + } + int status; + waitpid(pid, &status, 0); + result.exit_code =3D WEXITSTATUS(status); + } =20 - result.exit_code =3D system(command); return result; } + +cli_result_t +cli_runner_compiler_dump_tokens(char *src) +{ + char *program_args[] =3D { "0c", "--dump-tokens", src, NULL }; + return cli_runner_compiler(src, program_args); +} diff --git a/tests/integration/cli_runner.h b/tests/integration/cli_runner.= h index 8f4d69a..7ce4e7b 100644 --- a/tests/integration/cli_runner.h +++ b/tests/integration/cli_runner.h @@ -20,6 +20,7 @@ typedef struct cli_result_t { int exit_code; char program_path[255]; + char compiler_output[1024]; } cli_result_t; =20 cli_result_t diff --git a/tests/integration/cli_test.c b/tests/integration/cli_test.c index ce2ed91..1fd70c7 100644 --- a/tests/integration/cli_test.c +++ b/tests/integration/cli_test.c @@ -23,6 +23,20 @@ test_cli_hello_file(const MunitParameter params[], void = *user_data_or_fixture) { cli_result_t compilation_result =3D cli_runner_compiler_dump_tokens(".= ./../examples/main_exit.0"); munit_assert_int(compilation_result.exit_code, =3D=3D, 0); + munit_assert_string_equal(compilation_result.compiler_output, + "../../examples/main_exit.0:1:1: \n" + "../../examples/main_exit.0:1:4: \n" + "../../examples/main_exit.0:1:8: <(>\n" + "../../examples/main_exit.0:1:9: <)>\n" + "../../examples/main_exit.0:1:10: <:>\n" + "../../examples/main_exit.0:1:12: \n" + "../../examples/main_exit.0:1:16: <{>\n" + "../../examples/main_exit.0:1:17: \n" + "../../examples/main_exit.0:2:3: \n" + "../../examples/main_exit.0:2:10: \n= " + "../../examples/main_exit.0:2:11: \n" + "../../examples/main_exit.0:3:1: <}>\n" + "../../examples/main_exit.0:3:2: = \n"); return MUNIT_OK; } =20 --=20 2.34.1