From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id eNo8IKxhxWa3wQAAqHPOHw:P1 (envelope-from ) for ; Wed, 21 Aug 2024 05:40:28 +0200 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id eNo8IKxhxWa3wQAAqHPOHw (envelope-from ) for ; Wed, 21 Aug 2024 05:40:28 +0200 X-Envelope-To: patches@johnnyrichard.com Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=qRlDPksC; dkim=pass header.d=maniero.me header.s=hostingermail1 header.b=JypXlrJE; spf=pass (aspmx1.migadu.com: domain of lists@sr.ht designates 46.23.81.152 as permitted sender) smtp.mailfrom=lists@sr.ht; dmarc=pass (policy=none) header.from=maniero.me; arc=pass ("mailchannels.net:s=arc-2022:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=johnnyrichard.com; s=key1; t=1724211628; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=pXKjojztuGgtdIcgcXFBCkKs6MDEkxJ1Xmm/eJECeto=; b=BBSp+ebthn+xLCtBWEQfz9bDfM8nOB1ZeANokYjCrwh2X60OEhVO9BeMViTISfkIqXGJMf 3+kwhRkq8iItLh6qtxCcir5CZZPE4dEnlZrwrx3IwbXBiZqAIlKitM0aj+oVy0w1eMGUCN MweviCQ7DIyKW8ZJ0gwaJvuCqxATzW3kek8VlyL0x9CxiJR+OjI6B5wcgx18gzZ8g6JoOl f2NRdybv/pdjMCgLi+UIHH7qgaz40qMGOrvuimSpcJ0ZrT7kZMJZOTIE/FNmLJuSCggnb3 nTbEHLiXhpZaBrvLmaBzSPkeWhz1Ba/yoIqr4AiRlD7Ebs64QgriooG6eDMuZg== ARC-Authentication-Results: i=2; aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=qRlDPksC; dkim=pass header.d=maniero.me header.s=hostingermail1 header.b=JypXlrJE; spf=pass (aspmx1.migadu.com: domain of lists@sr.ht designates 46.23.81.152 as permitted sender) smtp.mailfrom=lists@sr.ht; dmarc=pass (policy=none) header.from=maniero.me; arc=pass ("mailchannels.net:s=arc-2022:i=1") ARC-Seal: i=2; s=key1; d=johnnyrichard.com; t=1724211628; a=rsa-sha256; cv=pass; b=AU1GBcoW1SK3l3R6BPai6HLaXFjRP4s3QhBc+0a5l3uGiHdi7HnVXicSryRY2FOEjZViEq gteVLe8Il+Ksuvp5t3bguPk1IoLfvqu/A0nhSqX6YttFRdAIP0LyJUhRfvwwIrvbYH1gmX qWblKMrjT+ezCIOfGIyfMuN0OqA4iALfkkwk1E+66HJmuiqfzjvLEXyTsxEAZPlGSDMFAQ gdUxcDs8/6fp/bkg0aZojajZ2TTmYoUefPnxGuMDCECwPekHFdNwqUMuaftyVmsficsmv6 Xu9n8LYDXQfFv5CDBJjudKzR7ctTatU3F+u+IVg5e7lkQvXDPTCVEcUCk6I4Jg== Received: from mail-a.sr.ht (mail-a.sr.ht [46.23.81.152]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 50365385A5 for ; Wed, 21 Aug 2024 05:40:25 +0200 (CEST) DKIM-Signature: a=rsa-sha256; bh=sZPbqW+yOSn/oPyofy/gP/kSp1UkRZLiHoORPZRScUc=; c=simple/simple; d=lists.sr.ht; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Unsubscribe:List-Subscribe:List-Archive:List-Post:List-ID; q=dns/txt; s=20240113; t=1724211625; v=1; b=qRlDPksCDWNPWBKXjIoHjgoFd+tFZKjEXEcumUGx9v+G5oB8Nkh1Hn0KCLkALlF2VoY0telK Unsum7nM9/L0UT5Pt38fGvZDf7U5BgJ4h0epnyfqfeIopu8SpCYHGskoWa4vr/BpnRURggfcKSf +mPsME3iWjVwBO5vO98IZk+D6gq99sWPf0IMQ5FQIZtxBa1W3v8uVj2DFQxLZigF95joniB82Kt 6aDfaYAnZNOvDmYli9mgaCBdS6BBW9bjbW2UBQrc7ZD7vok+urQROrgkANcAvwINJ/FLYdNjBWf 97KO9P1og5JXOJZ1rijPufz/Gw9/9y7RUCwn5y33JtIBw== Received: from lists.sr.ht (unknown [46.23.81.154]) by mail-a.sr.ht (Postfix) with ESMTPSA id 320AE20292 for ; Wed, 21 Aug 2024 03:40:25 +0000 (UTC) Received: from dog.elm.relay.mailchannels.net (dog.elm.relay.mailchannels.net [23.83.212.48]) by mail-a.sr.ht (Postfix) with ESMTPS id 1279920203 for <~johnnyrichard/olang-devel@lists.sr.ht>; Wed, 21 Aug 2024 03:40:23 +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 72A1A9053CA for <~johnnyrichard/olang-devel@lists.sr.ht>; Wed, 21 Aug 2024 03:40:22 +0000 (UTC) Received: from nl-srv-smtpout1.hostinger.io (unknown [127.0.0.6]) (Authenticated sender: hostingeremail) by relay.mailchannels.net (Postfix) with ESMTPA id B45E99051D4 for <~johnnyrichard/olang-devel@lists.sr.ht>; Wed, 21 Aug 2024 03:40:21 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1724211622; a=rsa-sha256; cv=none; b=e39xwHNasg72dxxce1tr+n6GnbCcnZUbc0mavWINPamz8tnnBZFa9ruaQnWwR1DcHSdrKV DP+KfC2tw8jFFWdy9ZrhFa2FyF2OuuPmHIlSpEQa0OGasEgyvzdVz/14WQoFav+CkPoCzy NsjL5ZF6MSPkyWA4fy2JUq4eHYT/RZsG++I53ywhI9/+dtd4PnfgXQYNby6NM2wDTLjkzp EIgykMFjnlr1dOnQEXxktEZs2mCPYeg5mMJ2+hBPWlLg5bSPpw9RZCmPrdIPUpElEuaWo2 2r+BlQgchkHaH3M3UsB8y62xI8zvbMNd30YmGNynWbQ6qVRAAKFdQliFLiIx8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1724211622; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=pXKjojztuGgtdIcgcXFBCkKs6MDEkxJ1Xmm/eJECeto=; b=AV2+RUDXzi3wcsjhaiz2Y8YlRhS/n1gdXeySRkjrUj463md0F1sYHsbgpNIJUb+80tLoiE 1/ZqHFlv5f2KDlfo2sRdIGN8gmespGEGcSYUjVDUnV8ytgaS8qDNicnTjdvuPMoXW9F5yq rMcaCEJOJbEexLuOFUy9F3WoxLmXW9lDO2tBUwUYjpkCoaUCW1sDa1llhOEAEkR7oN9g36 JNldB7JzKZHvyICtCpsAGT6h461w0qKu1MW/GqvbAS3dxIzlFUfClBreRfPC+3amzPsbJk e55fuhiI5IkcJDPgOGbY4U8ti9XeAZvQpybfqOl7V4PEXnqJS9Ni3NxV5FasFA== ARC-Authentication-Results: i=1; rspamd-587694846-9p89d; 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-Interest-Shade: 6ee14986400c81e5_1724211622343_4257431473 X-MC-Loop-Signature: 1724211622343:2637304636 X-MC-Ingress-Time: 1724211622342 Received: from nl-srv-smtpout1.hostinger.io (nl-srv-smtpout1.hostinger.io [145.14.150.87]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.115.51.245 (trex/7.0.2); Wed, 21 Aug 2024 03:40:22 +0000 From: Carlos Maniero DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=maniero.me; s=hostingermail1; t=1724211620; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pXKjojztuGgtdIcgcXFBCkKs6MDEkxJ1Xmm/eJECeto=; b=JypXlrJEduQJElSSbyMiy3CclFHh75aRQiHIc9vREMTalFO48D4vflQEPi1qRH/3tBE/HL 8DKwguf3iUGVRLvanOl8ohrJtidarTao87INaD/QQiwwH331NLOEIFZalLszt0poZNoB5w b1du+OKladfUiRXOeVTaFo5XeKXlsHEoeR3BTVg7uhpMqA4Z3eSU0/muGFiMiHnufmTgPL dyx+13zfoomH4nO19SvwnkV6pscrjlie2jVXYp+TYVLiW+tRQ9dt8KoJe0dOECw/lEpyld tAOJqB7Hd0T+a8RcU8AiYBrTWOTDjusT3w4KXy+xPSyzm8YFFFOjAZScuIEkzg== To: ~johnnyrichard/olang-devel@lists.sr.ht Cc: Carlos Maniero Subject: [PATCH olang 2/2] tests: remove previous c-based integration tests structure Date: Wed, 21 Aug 2024 00:39:53 -0300 Message-Id: <20240821033953.253090-3-carlos@maniero.me> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240821033953.253090-1-carlos@maniero.me> References: <20240821033953.253090-1-carlos@maniero.me> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-Analysis: v=2.4 cv=YLPNygGx c=1 sm=1 tr=0 ts=66c561a4 a=WwxFCuf3mf1fs3oSi6/dng==:117 a=WwxFCuf3mf1fs3oSi6/dng==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=mDV3o1hIAAAA:8 a=6PGW1_rcwqDUW6p_oRsA:9 a=_FVE-zBwftR9WsbkzFJk:22 a=BXDaF_L80NY05PYiAFlV:22 X-CM-Envelope: MS4xfMxvMs0Tq7L6X5io4hgplQGNOlFiR8zvwPW2aIRJYp4zn8h+XyugKHMnx9mKATkd0Z/tstPILtCX1Rmr7XlW3g7MiMosRcJrIiwtbSyAHvsUbm9ljkMD qRSz/90hw6TiZtd0vCb0r0lAMbfm0yJjzvlXyka86RU5photcOFYlro1EQOojq1qSUd0aue7vkDYEyv2wmcZjgN9yiftPpNHB/9RTm0vxElooI2wRIUyTOzF X-AuthUser: carlos@maniero.me X-Sourcehut-Patchset-Status: UNKNOWN List-Unsubscribe: List-Subscribe: List-Archive: Archived-At: List-Post: List-ID: ~johnnyrichard/olang-devel <~johnnyrichard/olang-devel.lists.sr.ht> Sender: ~johnnyrichard/olang-devel <~johnnyrichard/olang-devel@lists.sr.ht> X-Migadu-Country: NL X-Migadu-Flow: FLOW_IN X-Migadu-Queue-Id: 50365385A5 X-Migadu-Scanner: mx13.migadu.com X-Migadu-Spam-Score: -5.81 X-Spam-Score: -5.81 X-TUID: t+Foku9Bw5QO Signed-off-by: Carlos Maniero --- tests/integration/cli_runner.c | 100 ------------------------- tests/integration/cli_runner.h | 32 -------- tests/integration/cli_test.c | 132 --------------------------------- tests/integration/proc_exec.c | 63 ---------------- tests/integration/proc_exec.h | 37 --------- 5 files changed, 364 deletions(-) delete mode 100644 tests/integration/cli_runner.c delete mode 100644 tests/integration/cli_runner.h delete mode 100644 tests/integration/cli_test.c delete mode 100644 tests/integration/proc_exec.c delete mode 100644 tests/integration/proc_exec.h diff --git a/tests/integration/cli_runner.c b/tests/integration/cli_runner.c deleted file mode 100644 index 636abfc..0000000 --- a/tests/integration/cli_runner.c +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (C) 2024 olang maintainers - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#include "cli_runner.h" -#include "proc_exec.h" -#include -#include -#include -#include -#include -#include -#include - -#define OLANG_COMPILER_PATH "../../olang" - -static int compiler_exists_already_checked = 0; - -static void -assert_compiler_exists() -{ - { - if (compiler_exists_already_checked == 1) { - return; - } - - compiler_exists_already_checked = 1; - } - - FILE *file = fopen(OLANG_COMPILER_PATH, "r"); - - if (file != NULL) { - fclose(file); - return; - } - - perror("Build the compiler before executing tests"); - exit(1); -} - -void -create_tmp_file_name(char *file_name) -{ - sprintf(file_name, "%s/olang_programXXXXXX", P_tmpdir); - int fd = mkstemp(file_name); - - if (fd == -1) { - perror("Could not create a tmp file. Check your P_tmpdir permission."); - exit(1); - } - close(fd); -} - -void -cli_runner_compiler(cli_result_t* result, char *args[]) -{ - assert_compiler_exists(); - - proc_exec_command_t command = { - .path = OLANG_COMPILER_PATH, - .args = args - }; - - proc_exec(&command); - - result->exec = command.result; -} - -cli_result_t -cli_runner_compiler_dump_tokens(char *src) -{ - cli_result_t result = { 0 }; - - char *program_args[] = { "olang", "--dump-tokens", src, NULL }; - cli_runner_compiler(&result, program_args); - return result; -} - -cli_result_t -cli_runner_compiler_compile(char *src) -{ - cli_result_t result = { 0 }; - create_tmp_file_name(result.binary_path); - - char *program_args[] = { "olang", src, "-o", result.binary_path, NULL }; - cli_runner_compiler(&result, program_args); - return result; -} diff --git a/tests/integration/cli_runner.h b/tests/integration/cli_runner.h deleted file mode 100644 index 785cd34..0000000 --- a/tests/integration/cli_runner.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) 2024 olang maintainers - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#ifndef CLI_RUNNER_H -#define CLI_RUNNER_H -#include "proc_exec.h" - -typedef struct cli_result_t -{ - char binary_path[255]; - proc_exec_result_t exec; -} cli_result_t; - -cli_result_t -cli_runner_compiler_dump_tokens(char *src); - -cli_result_t -cli_runner_compiler_compile(char *src); -#endif diff --git a/tests/integration/cli_test.c b/tests/integration/cli_test.c deleted file mode 100644 index e7ae059..0000000 --- a/tests/integration/cli_test.c +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright (C) 2024 olang maintainers - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#define MUNIT_ENABLE_ASSERT_ALIASES -#include "cli_runner.h" -#include "munit.h" -#include - -static MunitResult -test_cli_dump_tokens_example_main_exit(const MunitParameter params[], void *user_data_or_fixture) -{ - cli_result_t compilation_result = cli_runner_compiler_dump_tokens("../../examples/main_exit.ol"); - munit_assert_int(compilation_result.exec.exit_code, ==, 0); - munit_assert_string_equal(compilation_result.exec.stdout_buf, - "../../examples/main_exit.ol:1:12: \n" - "../../examples/main_exit.ol:2:16: \n" - "../../examples/main_exit.ol:3:1: \n" - "../../examples/main_exit.ol:4:1: \n" - "../../examples/main_exit.ol:4:4: \n" - "../../examples/main_exit.ol:4:8: <(>\n" - "../../examples/main_exit.ol:4:9: <)>\n" - "../../examples/main_exit.ol:4:10: <:>\n" - "../../examples/main_exit.ol:4:12: \n" - "../../examples/main_exit.ol:4:16: <{>\n" - "../../examples/main_exit.ol:4:17: \n" - "../../examples/main_exit.ol:5:3: \n" - "../../examples/main_exit.ol:5:10: \n" - "../../examples/main_exit.ol:5:11: \n" - "../../examples/main_exit.ol:6:1: <}>\n" - "../../examples/main_exit.ol:6:2: \n" - "../../examples/main_exit.ol:7:1: \n"); - return MUNIT_OK; -} - -static MunitResult -test_cli_dump_tokens_example_expression(const MunitParameter params[], void *user_data_or_fixture) -{ - cli_result_t compilation_result = cli_runner_compiler_dump_tokens("../../examples/expression.ol"); - munit_assert_int(compilation_result.exec.exit_code, ==, 0); - munit_assert_string_equal(compilation_result.exec.stdout_buf, - "../../examples/expression.ol:1:1: \n" - "../../examples/expression.ol:1:4: \n" - "../../examples/expression.ol:1:8: <(>\n" - "../../examples/expression.ol:1:9: <)>\n" - "../../examples/expression.ol:1:10: <:>\n" - "../../examples/expression.ol:1:12: \n" - "../../examples/expression.ol:1:16: <{>\n" - "../../examples/expression.ol:1:17: \n" - "../../examples/expression.ol:2:3: \n" - "../../examples/expression.ol:2:10: <(>\n" - "../../examples/expression.ol:2:11: \n" - "../../examples/expression.ol:2:14: <+>\n" - "../../examples/expression.ol:2:16: \n" - "../../examples/expression.ol:2:18: <*>\n" - "../../examples/expression.ol:2:20: \n" - "../../examples/expression.ol:2:21: <)>\n" - "../../examples/expression.ol:2:23: <->\n" - "../../examples/expression.ol:2:25: <(>\n" - "../../examples/expression.ol:2:26: \n" - "../../examples/expression.ol:2:29: <->\n" - "../../examples/expression.ol:2:31: <(>\n" - "../../examples/expression.ol:2:32: \n" - "../../examples/expression.ol:2:34: <+>\n" - "../../examples/expression.ol:2:36: \n" - "../../examples/expression.ol:2:37: <)>\n" - "../../examples/expression.ol:2:39: \n" - "../../examples/expression.ol:2:41: \n" - "../../examples/expression.ol:2:42: <)>\n" - "../../examples/expression.ol:2:43: \n" - "../../examples/expression.ol:3:1: <}>\n" - "../../examples/expression.ol:3:2: \n" - "../../examples/expression.ol:4:1: \n"); - return MUNIT_OK; -} - -static MunitResult -test_cli_compile_minimal_program(const MunitParameter params[], void *user_data_or_fixture) -{ - cli_result_t compilation_result = cli_runner_compiler_compile("../../examples/main_exit.ol"); - munit_assert_int(compilation_result.exec.exit_code, ==, 0); - - char *command_args[] = { compilation_result.binary_path, NULL }; - - proc_exec_command_t command = { .path = command_args[0], .args = command_args }; - - proc_exec(&command); - - remove(command_args[0]); - - munit_assert_int(command.result.exit_code, ==, 0); - - return MUNIT_OK; -} - -static MunitTest tests[] = { - { "/test_cli_dump_tokens_example_main_exit", - test_cli_dump_tokens_example_main_exit, - NULL, - NULL, - MUNIT_TEST_OPTION_NONE, - NULL }, - { "/test_cli_dump_tokens_example_expression", - test_cli_dump_tokens_example_expression, - NULL, - NULL, - MUNIT_TEST_OPTION_NONE, - NULL }, - { "/test_cli_compile_minimal_program", test_cli_compile_minimal_program, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }, - { NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL } -}; - -static const MunitSuite suite = { "/cli_test", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE }; - -int -main(int argc, char *argv[]) -{ - return munit_suite_main(&suite, NULL, argc, argv); - return EXIT_SUCCESS; -} diff --git a/tests/integration/proc_exec.c b/tests/integration/proc_exec.c deleted file mode 100644 index c22dd1e..0000000 --- a/tests/integration/proc_exec.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2024 olang maintainers - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#include "proc_exec.h" -#include -#include -#include -#include -#include -#include -#include - - -void -proc_exec(proc_exec_command_t* command) -{ - int fd_pipe[2]; - - if (pipe(fd_pipe) == -1) { - perror("pipe error."); - exit(1); - } - - pid_t pid = fork(); - - if (pid == -1) { - perror("fork error."); - exit(1); - } - - if (pid == 0) { - dup2(fd_pipe[1], STDOUT_FILENO); - close(fd_pipe[0]); - close(fd_pipe[1]); - - execv(command->path, command->args); - perror("execl error."); - exit(127); - } else { - close(fd_pipe[1]); - // TODO: stop truncating the output. - if (read(fd_pipe[0], command->result.stdout_buf, sizeof(command->result.stdout_buf)) == -1) { - perror("read error."); - exit(1); - } - int status; - waitpid(pid, &status, 0); - command->result.exit_code = WEXITSTATUS(status); - } -} diff --git a/tests/integration/proc_exec.h b/tests/integration/proc_exec.h deleted file mode 100644 index 45c2977..0000000 --- a/tests/integration/proc_exec.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2024 olang maintainers - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#ifndef PROC_EXEC_H -#define PROC_EXEC_H -#include - -typedef struct proc_exec_result -{ - int exit_code; - // FIXME: output buffer shouldn't be fixed size - char stdout_buf[2048]; -} proc_exec_result_t; - -typedef struct proc_exec_command -{ - char* path; - char** args; - proc_exec_result_t result; -} proc_exec_command_t; - -void -proc_exec(proc_exec_command_t* command); -#endif -- 2.34.1