From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id uMaKCpzSQGYdVQAAqHPOHw:P1 (envelope-from ) for ; Sun, 12 May 2024 16:30:52 +0200 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id uMaKCpzSQGYdVQAAqHPOHw (envelope-from ) for ; Sun, 12 May 2024 16:30:52 +0200 X-Envelope-To: patches@johnnyrichard.com Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=W2Azl1R7; dkim=pass header.d=maniero.me header.s=hostingermail1 header.b=LDqC5ley; arc=pass ("mailchannels.net:s=arc-2022:i=1"); dmarc=pass (policy=none) header.from=maniero.me; spf=pass (aspmx1.migadu.com: domain of lists@sr.ht designates 46.23.81.152 as permitted sender) smtp.mailfrom=lists@sr.ht ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=johnnyrichard.com; s=key1; t=1715524252; 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=XxMLBwKLwoKekJoZhPeBo27+HFjBtelnKJsY9dRl0yM=; b=UCPpK4w8VeWQ9+tuUz2Eo/TSZA90ZoTJn6arRO59u/IZmiyRhWuPXZVT4JLh2lHyySePf6 kg6LWPCKbVdMJYeNJVN6rNiow3fBEXO33Q7BC1yZHSVzmsmtVFJC3+HWH2JLzbrbXMk7ML /EouUHpACZXPECmxkWS1Usn3H+vQCoBP13Y7uJ6FKXtMw2cgsax/upS9MKE/sTZsclie+y NYXx+JOqcnRqCMyBXwd+99jXIszPl6ogDhZXO9+KWpCYrwY7v2S2iJEhhoyViqZNve/QT5 s2M7nhA+eX6Q36AGJ1ZiwvlQyQQnUmGym1riRmNUpwaPfb6lzyj/tyRkIaY8kQ== ARC-Seal: i=2; s=key1; d=johnnyrichard.com; t=1715524252; a=rsa-sha256; cv=pass; b=Yz1NQjwy1edf1uLvJqCy73p5jB0oGBJWIvtT+AKW4yELBAG5Bdm1JEuRIH0hEW41XA5kRW 0pSkqDc6EWQmpvs9f6zb/A0BWNmrF719DdaQedju95fkzWmIxVXGBlVtyfmLo5hgnOJ9Lc ZEkFerBCG+y4BJgimXQUXj5zalXVXyJAVmYAgq05LVkET6iiNuQe0OHncHoqKikxXM41/K gsVymF0mkeKNhLTaryXcsSwJ3A67kLy634QGWdHLGn6ujWPMxlCRcLBxhUXadT2VkSVMiZ Myw5SQUAlHx8wLdcK2duRO4CCwG1ahsqFaoHgSGJPUFwjsTa8MZ0Pc/2q78uQg== ARC-Authentication-Results: i=2; aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=W2Azl1R7; dkim=pass header.d=maniero.me header.s=hostingermail1 header.b=LDqC5ley; arc=pass ("mailchannels.net:s=arc-2022:i=1"); dmarc=pass (policy=none) header.from=maniero.me; spf=pass (aspmx1.migadu.com: domain of lists@sr.ht designates 46.23.81.152 as permitted sender) smtp.mailfrom=lists@sr.ht 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 190903DB6F for ; Sun, 12 May 2024 16:30:52 +0200 (CEST) DKIM-Signature: a=rsa-sha256; bh=J7TK1AI2mj5oCzu6tn+TTFX8xT3zXLKsGLva3AVDSfU=; 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=1715524251; v=1; b=W2Azl1R7HWGPbHsHCnAxJvvfK4o4Se2cquU9PoMQWZeGaCrMmOo2AOm7A969fWO+H/6qf8H3 yZxPX46VS5823k0zh0kTIgQkelPma7lk76Ys78MF20YY5OeCWl+DCX2Gp6BpuSJHceq4ddDEJ5A QOj8xweLsy6KjjCdKoJF1NdMzJP3QJ8xD7gGBHTnWVA8RmKBazfkzkOQPrZC3vdnY4fLMTVcIIq suZDVjsyZwlZ6WK7KHIfmNLhMz8Rd1neC/bAjbooc/lJEZAWyix5mY88Gd+pxPyeDjpYhD/WsPZ RfdNaLKov7NKXVn4iTxVnTtDTyNMb8nuCjVaUWg7cXu8A== Received: from lists.sr.ht (unknown [IPv6:2a03:6000:1813:1337::154]) by mail-a.sr.ht (Postfix) with ESMTPSA id D901C20139 for ; Sun, 12 May 2024 14:30:51 +0000 (UTC) Received: from crab.ash.relay.mailchannels.net (crab.ash.relay.mailchannels.net [23.83.222.42]) by mail-a.sr.ht (Postfix) with ESMTPS id C16AB2012D for <~johnnyrichard/olang-devel@lists.sr.ht>; Sun, 12 May 2024 14:30:50 +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 6D5D1762611 for <~johnnyrichard/olang-devel@lists.sr.ht>; Sun, 12 May 2024 14:30:49 +0000 (UTC) Received: from uk-fast-smtpout5.hostinger.io (unknown [127.0.0.6]) (Authenticated sender: hostingeremail) by relay.mailchannels.net (Postfix) with ESMTPA id A3E7776266E for <~johnnyrichard/olang-devel@lists.sr.ht>; Sun, 12 May 2024 14:30:48 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1715524249; a=rsa-sha256; cv=none; b=z4z90x9VP9gc35aZyZhkJ8KOcrVWgdphUz318CDFZH1RpwBnuAMEjf5kCsmOKmHTZQJqeX BFOhUFh8sObZgubrbwuJuGfRMUcGK47ERqB+OvGH0pU9TU2czM4kOSYGh9ugOQnCbqlq9/ PpQtOf/bvFeq5pD81NqOLEshZyTdTMx32Emb+FwbvNGmiTUoWOEGITdQeEU5GB4gZZOp61 PTxzU46OroLMOsM7F34JvPmDrNVsmtQ0wxWBS2rAIfiFGTqaaTee2NRjdViC1G7xMM+uYN gJ98+o4hojpSv0Pi1rt9hppqP3ewR3rBtHX7BSbUujT2CdYH5VictDJvt3XJgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1715524249; 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=XxMLBwKLwoKekJoZhPeBo27+HFjBtelnKJsY9dRl0yM=; b=wvttPjSsaMfN6i0XigfhkYW8PWEch9sBaw3azy0xlAp6XB2cnu1VCIhK3JDVauPX77o5PD J4US/bkjLQ+Mm2XEt3c3PVuCk5/zG7I08CaLrghwA1NULahCOrOfkWMhvBxGLchZyh1xZr B9iuQsNrjPVDgyw1ALdQNeZDSVnr4d1Cl721u5QREBOGA0aw5tfbM4ox3yMhzO0Lr5yImO 3MCh1bSudTqw4x8918ZmIwDmzEj4qXdrx1Lc/haRTk882kYEGuNTGRxbkm/1XBf+NQ/a9v 6UYLqcFVCnZsa5dZkGPEcD5P518KcaKg8CAowQPzhpaIdNxsB1MrFZmcy19RQw== ARC-Authentication-Results: i=1; rspamd-68bbddc7f5-xrgdp; 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-Broad-Lyrical: 58e1c1e930c59585_1715524249373_1554426506 X-MC-Loop-Signature: 1715524249373:2829402288 X-MC-Ingress-Time: 1715524249372 Received: from uk-fast-smtpout5.hostinger.io ([UNAVAILABLE]. [31.220.23.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.107.48.229 (trex/6.9.2); Sun, 12 May 2024 14:30:49 +0000 From: Carlos Maniero DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=maniero.me; s=hostingermail1; t=1715524246; 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=XxMLBwKLwoKekJoZhPeBo27+HFjBtelnKJsY9dRl0yM=; b=LDqC5leyyM9RQbDcUwPxU3GA5R9xvIU9rBLx89ScbsUetyTmM0CkMz/stBEN+e3uS3x90m bnWZVgzFBUjaS9v7NoMQPboIqEeOVE/w3AA7mX4yzbxBAAcBYSByHtLZ/TGlB+UBOius+e eTl1l0JZoIo/Y9TG5qnQ7UXnKGnz3B3NlRnCTG1SYH8iHGbx7DsZatns3o7R9gWNThyj6d rGP3uAP5aemSDTXomCRRCZW5SIUV+CASzufjJXHtVrI1Du2dPkmhBZUK7wKpv4j/9NAa4b +t7WLOTNPt47kitILUVlzW/weoivxfzM+rLPvE0CD2L0CbPBgM+PdSyzzOZAig== To: ~johnnyrichard/olang-devel@lists.sr.ht Cc: Carlos Maniero Subject: [PATCH olang 2/4] tests: remove previous integration tests structure Date: Sun, 12 May 2024 11:30:31 -0300 Message-Id: <20240512143033.229961-3-carlos@maniero.me> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240512143033.229961-1-carlos@maniero.me> References: <20240512143033.229961-1-carlos@maniero.me> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-Envelope: MS4xfJM6SqBslxEjAbdY/Uzsv+QbSe42bDo2Jg78aIVtgj9ZJNC6jCBTfwKYXIOSTrmeG0IL7Q+H7smADh1a+SXFFkIrlWYPxrAQd1T16N1ZCYmAePlYbhn7 Pf1KJLpobLa8QgF8nH3gC88TDshcB83J/Wn3AnoWlKAjatx9gMwSzo2SrX9292hqN7mKli5GEkJGA8z6QvBRtPzIyPypqvGPd6Sg1WSSMtUcPFfaNyXcsmq1 X-CM-Analysis: v=2.4 cv=ctHJkE4i c=1 sm=1 tr=0 ts=6640d296 a=WwxFCuf3mf1fs3oSi6/dng==:117 a=WwxFCuf3mf1fs3oSi6/dng==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=mDV3o1hIAAAA:8 a=-v5gWw_XHd2JDANJAk4A:9 a=_FVE-zBwftR9WsbkzFJk:22 a=BXDaF_L80NY05PYiAFlV:22 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-Flow: FLOW_IN X-Migadu-Country: NL X-Migadu-Spam-Score: -6.58 X-Spam-Score: -6.58 X-Migadu-Queue-Id: 190903DB6F X-Migadu-Scanner: mx11.migadu.com X-TUID: 9BT6LRCBxaoQ 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 --------- tests/integration/test.sh | 62 ++++++++-------- 6 files changed, 33 insertions(+), 393 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 diff --git a/tests/integration/test.sh b/tests/integration/test.sh index 6ab03de..9fdabef 100755 --- a/tests/integration/test.sh +++ b/tests/integration/test.sh @@ -1,3 +1,4 @@ +#!/bin/sh COMPILER_PATH="../../olang" TEST_FILE="$1" @@ -15,57 +16,63 @@ TOKENS_EXPECT_OUTPUT_FILE="$TEST_FILE.test.expected_tokens_output" TOKENS_OUTPUT_FILE="$TEST_FILE.test.tokens_output" TOKENS_EXPECT_OUTPUT_FILE="$TEST_FILE.test.expected_tokens_output" -PROGRAM_OUTPUT="$TEST_FILE.test.program_output" - +# Misc extract_comment() { tag="$1" - comment="# $tag: " - cat $TEST_FILE | grep "$comment" | sed -e "s/$comment//" + comment="# $tag:" + grep "$comment" "$TEST_FILE" | sed -e "s/$comment //" +} + +cleanup() { + rm -f "$PROGRAM*" } # UI COLOR_RED=1 COLOR_GREEN=2 COLOR_YELLOW=3 -COLOR_BLUE=4 COLOR_CYAN=6 COLOR_GRAY=7 colored() { text="$1" - color="$2" + color=$(tput setaf "$2") + reset=$(tput sgr0) + if [ -t 1 ]; then - if tput setaf 1 &> /dev/null; then - printf "$(tput setaf $color)$text$(tput sgr0)" + if tput setaf 1 > /dev/null 2>&1; then + printf "%s%s%s" "$color" "$text" "$reset" return fi fi - printf "$text" + printf "%s" "$text" } print_test_description() { - colored "$TEST_FILE: \n" $COLOR_CYAN - colored "$(extract_comment spec)\n\n" $COLOR_GRAY + colored "$TEST_FILE: " $COLOR_CYAN + printf "\n" + colored "$(extract_comment spec)" $COLOR_GRAY + printf "\n\n" } print_passed() { context="$1" - printf "$context: " + printf "%s: " "$context" colored "passed" $COLOR_GREEN echo } print_failed() { context="$1" - printf "$context: " + printf "%s: " "$context" colored "failed" $COLOR_RED echo } print_skiped() { context="$1" - printf "$context: " + printf "%s: " "$context" colored "not set" $COLOR_GRAY echo } @@ -98,7 +105,7 @@ expect_output() { expected_file="$2" actual_file="$3" - if [ "$(cat $expected_file | wc -l)" = "0" ]; then + if [ "$(wc -l < "$expected_file")" = "0" ]; then print_skiped "$context" return fi @@ -107,7 +114,7 @@ expect_output() { print_passed "$context" else if [ "$(cat "$expected_file")" = "%empty%" ]; then - if [ "$(cat $actual_file | wc -c)" = "0" ]; then + if [ "$(wc -c < "$actual_file")" = "0" ]; then print_passed "$context" return fi @@ -119,19 +126,16 @@ expect_output() { fi } -cleanup() { - rm -f $PROGRAM* -} - +# Tests test_compiler() { - $COMPILER_PATH $TEST_FILE -o $PROGRAM > "$COMPILER_OUTPUT_FILE" 2>&1 + $COMPILER_PATH "$TEST_FILE" -o "$PROGRAM" > "$COMPILER_OUTPUT_FILE" 2>&1 EXIT=$? EXPECTED_EXIT=$(extract_comment compiler_exit) expect_exit_code compiler_exit "$EXPECTED_EXIT" "$EXIT" - extract_comment compiler_output > $COMPILER_EXPECT_OUTPUT_FILE + extract_comment compiler_output > "$COMPILER_EXPECT_OUTPUT_FILE" expect_output compiler_output "$COMPILER_EXPECT_OUTPUT_FILE" "$COMPILER_OUTPUT_FILE" if [ "$EXIT" = "1" ]; then @@ -142,25 +146,25 @@ test_compiler() { } test_ast() { - $COMPILER_PATH $TEST_FILE --dump-ast > "$AST_OUTPUT_FILE" 2>&1 + $COMPILER_PATH "$TEST_FILE" --dump-ast > "$AST_OUTPUT_FILE" 2>&1 - extract_comment ast > $AST_EXPECT_OUTPUT_FILE + extract_comment ast > "$AST_EXPECT_OUTPUT_FILE" expect_output "ast" "$AST_EXPECT_OUTPUT_FILE" "$AST_OUTPUT_FILE" } test_tokens() { - extract_comment tokens > $TOKENS_EXPECT_OUTPUT_FILE - TOKEN_LINES=$(cat $TOKENS_EXPECT_OUTPUT_FILE | wc -l) + extract_comment tokens > "$TOKENS_EXPECT_OUTPUT_FILE" + TOKEN_LINES=$(wc -l < "$TOKENS_EXPECT_OUTPUT_FILE") - $COMPILER_PATH $TEST_FILE --dump-tokens | head -n $TOKEN_LINES > "$TOKENS_OUTPUT_FILE" 2>&1 + $COMPILER_PATH "$TEST_FILE" --dump-tokens | head -n "$TOKEN_LINES" > "$TOKENS_OUTPUT_FILE" 2>&1 - expect_output tokens $TOKENS_OUTPUT_FILE $TOKENS_EXPECT_OUTPUT_FILE + expect_output tokens "$TOKENS_OUTPUT_FILE" "$TOKENS_EXPECT_OUTPUT_FILE" print_passed tokens } test_program() { - ./$PROGRAM + "./$PROGRAM" EXIT=$? EXPECTED_EXIT=$(extract_comment program_exit) -- 2.34.1