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 black.elm.relay.mailchannels.net (black.elm.relay.mailchannels.net [23.83.212.19]) by mail-a.sr.ht (Postfix) with ESMTPS id 9C3602010D for <~johnnyrichard/olang-devel@lists.sr.ht>; Fri, 16 Feb 2024 03:12:31 +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 06B61842564 for <~johnnyrichard/olang-devel@lists.sr.ht>; Fri, 16 Feb 2024 03:12:30 +0000 (UTC) Received: from nl-srv-smtpout4.hostinger.io (unknown [127.0.0.6]) (Authenticated sender: hostingeremail) by relay.mailchannels.net (Postfix) with ESMTPA id 3D20D8415AE for <~johnnyrichard/olang-devel@lists.sr.ht>; Fri, 16 Feb 2024 03:12:29 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1708053149; a=rsa-sha256; cv=none; b=W+wE1Jw94ujzVqyGZFItf1u5kVnFxb3TQqHlsGHboVZcK+ZB9T9rv0dyoXcphV69JdABjC Sr61AJ5fzLjdKmfUDHhG42j8iUuUFGH1pqiFHKwTL8ecZSDjbShu1KxZUbnWY6ZXpHZQmm fNtT/oiW7Aj/xigatRbto+J73EiEyXaApJqpLdT1r6Sff3136kMpHtEdlr3MkXgM15Ycma 8JtocALx4ewstiSeJ6oGGPMbnpfcTIMndIpsuFeB0vHaDwpKsZyYw4QMVex10sQJeQ3k6d 4vRF3Wq4kxIV8OsGbg+NwwyPPyaV3FHQUjFhplamytJVpjvoNooKJu3Xvej1UA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1708053149; 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=qGd/KN5tdDOBljzn1ABRk537qyNQBcy0pvhMVpga31E=; b=z0XO1+kYMz3y5VLE6mmgaVJzgA/CgWiOgTXh2rHH2AM1yNwrxZyUnsUrkYD1Ki/pnfIlR1 gjkVnrHxfIUDNLgzgsKgejV2H1RMl96cTwUJzsSzcz7Eo/OHrxHjrPCti7lz3zB3U7O7i9 Ag/94aAdQGZoGIzz3C6JTCYxAn2utsL/7DN4PigbNdj/SsisnD8xitPYE75H9tPEPwM6ti mWn6Fm8ChYghDx1vDmS02iv5d4wOMAV9po4M58686C9sVUb6AG8C8Zeja8Y9kAqhYCRVDV ESEI/vJkURKlF9Lqtc+9V6TwInEZyX75ltOpRlLe/izw3ulkIHRwXM4wQraa8A== ARC-Authentication-Results: i=1; rspamd-6bdc45795d-jfwp8; 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-Robust-Whispering: 16bff761457680b7_1708053149790_2185351857 X-MC-Loop-Signature: 1708053149790:2889268758 X-MC-Ingress-Time: 1708053149790 Received: from nl-srv-smtpout4.hostinger.io (nl-srv-smtpout4.hostinger.io [145.14.159.45]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.127.49.71 (trex/6.9.2); Fri, 16 Feb 2024 03:12:29 +0000 From: Carlos Maniero DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=maniero.me; s=hostingermail1; t=1708053147; 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=qGd/KN5tdDOBljzn1ABRk537qyNQBcy0pvhMVpga31E=; b=AUXvQxxQHGzlhbezu7wrnefhAoyvpxlnDy3MhWwodlgCYD4LR7KCQoSgGFitFexoZFWRMp sbM7m4OTtPDaYnvhZha3ovpWAZGiZWK8YwJBkm/nLhmw30Ur8BYdYOs1gxPO1+eZHh9zqR 9RypgJRQEXP1arC+Wsx4FX+3KINDmuCEpHtMU+hgl/f2AlgPQ7QESMfqbC9KVHIyVoSkb/ 72czkJKpfwNH6EENaT+CIVI27huvEu8WODulriKpbKiB9WuOyol+4jnUBJYAOi4DCpUAsL x7l/2PBFtYhBqe6FjlNue9MDRi+NE5YUgAwSLaSUA47/hCKLVOkBL0GmJL1Dog== To: ~johnnyrichard/olang-devel@lists.sr.ht Cc: Carlos Maniero Subject: [PATCH olang v3 2/2] tests: add integration test setup Date: Fri, 16 Feb 2024 00:07:48 -0300 Message-Id: <20240216030748.1365294-3-carlos@maniero.me> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240216030748.1365294-1-carlos@maniero.me> References: <20240216030748.1365294-1-carlos@maniero.me> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-Envelope: MS4xfPmZJTLILvmfRNqdDjd0ftORkFo+tRxNHMeUZy9Jlt0ztlaXZKOswuW7pyu9qRQxObOioK+hszj3DJ8ajeIJ6mTy6ybX2rikd21YksTMLun6IJRaK94t MKNWfUD2GtGY+0FA3L6B7mkBri9eBBBKbQEEOBEwV89tg0nIaUL8ABvUqtqi9WXx0I32w4EnA7O5kEfTfhc7EEu5JUZbMUcqQGzwToGNg9pYsdmLn147iFFv jVB4/iZMrBfIA2rLFwgbCA== X-CM-Analysis: v=2.4 cv=DIOJ4TNb c=1 sm=1 tr=0 ts=65ced29b a=5+VMC1FZ3J4mVPAKpPmAqg==:117 a=5+VMC1FZ3J4mVPAKpPmAqg==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=BXDaF_L80NYA:10 a=mDV3o1hIAAAA:8 a=Jula4zDGgnm7667QEx4A:9 a=_FVE-zBwftR9WsbkzFJk:22 X-AuthUser: carlos@maniero.me X-TUID: BsV+A546/qAe This is a basic setup for integration tests which includes: - a *cli_runner* helper file to provide an interface to interact with the CLI. - a simple test that validates if the compiler is returning zero exit code when a file is provided. At this point the compiler still doing nothing making all this bootstrap just a fancy way to check if the compiler was compiled properly. Signed-off-by: Carlos Maniero --- .build.yml | 4 ++ Makefile | 12 ++++++ tests/integration/Makefile | 27 ++++++++++++ tests/integration/cli_runner.c | 77 ++++++++++++++++++++++++++++++++++ tests/integration/cli_runner.h | 27 ++++++++++++ tests/integration/cli_test.c | 39 +++++++++++++++++ 6 files changed, 186 insertions(+) create mode 100644 tests/integration/Makefile create mode 100644 tests/integration/cli_runner.c create mode 100644 tests/integration/cli_runner.h create mode 100644 tests/integration/cli_test.c diff --git a/.build.yml b/.build.yml index 3aebfcf..b38efb3 100644 --- a/.build.yml +++ b/.build.yml @@ -12,3 +12,7 @@ tasks: - build: | cd olang make + - check: | + cd olang + make check + diff --git a/Makefile b/Makefile index 2a23b59..b13b41b 100644 --- a/Makefile +++ b/Makefile @@ -19,10 +19,22 @@ $(BUILD_DIR): .PHONY: linter linter: $(SRCS) $(HEADERS) clang-format --dry-run --Werror $? + $(MAKE) -C tests/integration/ linter + .PHONY: linter-fix linter-fix: $(SRCS) $(HEADERS) clang-format -i $? + $(MAKE) -C tests/integration/ linter-fix + +.PHONY: integration-test +integration-test: + $(MAKE) + $(MAKE) -C tests/integration/ + +.PHONY: check +check: + $(MAKE) integration-test $(BUILD_DIR)/%.o: $(SRC_DIR)/%.c $(CC) $(CFLAGS) -c $< -o $@ diff --git a/tests/integration/Makefile b/tests/integration/Makefile new file mode 100644 index 0000000..a42f787 --- /dev/null +++ b/tests/integration/Makefile @@ -0,0 +1,27 @@ +SRCS := $(wildcard *_test.c) +TO_LINT := $(filter-out munit.c munit.h,$(wildcard *.c *.h)) +OBJS := $(patsubst %_test.c, %_test.o, $(SRCS)) +CFLAGS := -I../../src +TESTS := $(patsubst %_test.c, %_test, $(SRCS)) +EXEC_TESTS := $(patsubst %_test, ./%_test, $(TESTS)) + +.PHONY: all +all: munit.o cli_runner.o $(TESTS) + @for file in $(EXEC_TESTS); do \ + ./"$$file"; \ + done + +.PHONY: clean +clean: + $(RM) *.o *_test + +.PHONY: linter +linter: $(TO_LINT) + clang-format --dry-run --Werror $? + +.PHONY: linter-fix +linter-fix: $(TO_LINT) + clang-format -i $? + +cli_test: munit.o cli_runner.o cli_test.o + $(CC) $? $(CFLAGS) -o $@ diff --git a/tests/integration/cli_runner.c b/tests/integration/cli_runner.c new file mode 100644 index 0000000..4e0f7c4 --- /dev/null +++ b/tests/integration/cli_runner.c @@ -0,0 +1,77 @@ +/* + * 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 +#include +#include +#include +#include +#include + +#define OLANG_COMPILER_PATH "../../0c" + +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); +} + +cli_result_t +cli_runner_compile_file(char *src) +{ + assert_compiler_exists(); + + cli_result_t result; + create_tmp_file_name(result.program_path); + + char command[1024]; + sprintf(command, "%s -o %s %s", OLANG_COMPILER_PATH, result.program_path, src); + + result.exit_code = system(command); + return result; +} diff --git a/tests/integration/cli_runner.h b/tests/integration/cli_runner.h new file mode 100644 index 0000000..5caa319 --- /dev/null +++ b/tests/integration/cli_runner.h @@ -0,0 +1,27 @@ +/* + * 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 +typedef struct cli_result_t +{ + int exit_code; + char program_path[255]; +} cli_result_t; + +cli_result_t +cli_runner_compile_file(char *src); +#endif diff --git a/tests/integration/cli_test.c b/tests/integration/cli_test.c new file mode 100644 index 0000000..c7a9557 --- /dev/null +++ b/tests/integration/cli_test.c @@ -0,0 +1,39 @@ +/* + * 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" + +static MunitResult +test_cli_hello_file(const MunitParameter params[], void *user_data_or_fixture) +{ + cli_result_t compilation_result = cli_runner_compile_file("../../examples/hello.olang"); + munit_assert_int(compilation_result.exit_code, ==, 0); + return MUNIT_OK; +} + +static MunitTest tests[] = { { "/test_cli_hello_file", test_cli_hello_file, 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; +} -- 2.34.1