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 bird.elm.relay.mailchannels.net (bird.elm.relay.mailchannels.net [23.83.212.17]) by mail-a.sr.ht (Postfix) with ESMTPS id CC4C520132 for <~johnnyrichard/olang-devel@lists.sr.ht>; Fri, 16 Feb 2024 03:03:11 +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 2C15E902211 for <~johnnyrichard/olang-devel@lists.sr.ht>; Fri, 16 Feb 2024 03:03:10 +0000 (UTC) Received: from uk-fast-smtpout2.hostinger.io (unknown [127.0.0.6]) (Authenticated sender: hostingeremail) by relay.mailchannels.net (Postfix) with ESMTPA id 57866902346 for <~johnnyrichard/olang-devel@lists.sr.ht>; Fri, 16 Feb 2024 03:03:09 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1708052589; a=rsa-sha256; cv=none; b=H/iDB9kSBpghy0mXAESGAypKJJZcZWcf0Yv3efu5FU98Pw8PtPYO4VVMCb2om3/h94yNVm Egbd9XJZBy7fv9KDJTeWUkKOaicAg5GbMJIu/YohsFaKVgqrgvebyMvmcgcR8fu/O8RBQs 1FAO+8QasFe3L8xpJG81W96GhE0j4t4iM7L0gkZ2zjpzRl7QOiD4Z7bjEivrhDZ35cAyD1 8PFXPKldl4LmPECpL9xU64pLtRqtCrOX63IbBKjdQ5mOiPnPRUHzISKbyVbzmCJvPOE6bd Oq0jNf7PDN4RmcWlDNRnDV85KAgnWXSlu0ka3oocvsItI8z2AwWCdWDfTQvtog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1708052589; 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=iCg9UA95xMXf/uncwXuI/Q+2h7JyBYtZ/E0RTtCWlms=; b=1GtX1IEQnRwWVQbcCSMt0ryJeBxdeMoVhI1Nt8FaY0yv+rZ4WbNYh2txXYw3jduKOMtSVG sITrHFjWKRIMLwDxz+DXSHbkowrSbQfMULXiB+F3jY4+SKRg0/4pkM0jSJObTan3+O1HTo egViHSCVbLtECYmQDntoldaKUhShmrchVm8kzOezPt5KwH3H3AEUSQWi5MOfE/sMe+OoN1 zcmFftLjF0d3l6cYyUmWlFTz9rxfBE2aCuQ6ZdJpN63zRQqASriw6eiY90IvcpsshZ11Hr XxR9xJ7/0rJio+z36kA1ySqEhmoW2vJAasGucNhuFtytzaZD1y7Mk1WaVlhPZQ== 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-Well-Made-Battle: 214b1ccb4c1d8d82_1708052590070_4286068064 X-MC-Loop-Signature: 1708052590070:1353124882 X-MC-Ingress-Time: 1708052590070 Received: from uk-fast-smtpout2.hostinger.io (uk-fast-smtpout2.hostinger.io [31.220.23.36]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.119.153.71 (trex/6.9.2); Fri, 16 Feb 2024 03:03:10 +0000 From: Carlos Maniero DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=maniero.me; s=hostingermail1; t=1708052586; 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=iCg9UA95xMXf/uncwXuI/Q+2h7JyBYtZ/E0RTtCWlms=; b=bObTbPQ7ZYahW/li6ACw17CEkdLS7PfK5VVxrCBKVJy95IgPP3AQhsoTMRvVCEAVnPTkQM j8PlVcy5Q2F42QpLhP29+vRjwyRrX5SvN2tcDq11iNKQASm8tSzHJBuVELMvhsjHhxEJRy HJOqoLOYMyE1yEzH2455MuWZnVgXPcds3zr+7xB5hTAhcwgKNqVQsku91hMF6OeEPFtiY9 LW3Z3cSoTX6IljS4jY5nMtp4MZNxADp6ojubTs6HQRcA+WQGotMhwQ21VXOvABLsW6fGmd 1NkM/3zyOeOPBDd3alGzn9q3qAHoqjKozKpmKiMAHpGYDEPeGp5dcm91U+M7CA== To: ~johnnyrichard/olang-devel@lists.sr.ht Cc: Carlos Maniero Subject: [PATCH olang v2 2/2] tests: add integration test setup Date: Thu, 15 Feb 2024 23:58:15 -0300 Message-Id: <20240216025815.1355111-3-carlos@maniero.me> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240216025815.1355111-1-carlos@maniero.me> References: <20240216025815.1355111-1-carlos@maniero.me> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-Analysis: v=2.4 cv=Rp/DLjmK c=1 sm=1 tr=0 ts=65ced06b 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-CM-Envelope: MS4xfEkREYPReqLkhs2ymdPn3iqH9rx8JLRkevV8d4wQmvJtOz6Z/1VoKvxtEqy9zh4o4cx0tLWCe++kCR/Yrf+xHGIP4qzRrMMk5YMFUKUVhWpLwk8wnozQ 3DpaTyhtuZXZuP1FNlz8WqyBoL4OfwbSMIsSZ1WcxdLux6hgUTIONV8KRSKtvSimObEgcAKSPqN8X/H7NABIB9OKxkZTiaBRHnxKk8tudvuke6/gGE623byp S9+y6PF/0sc8LEmVvH+Ucw== X-AuthUser: carlos@maniero.me X-TUID: yKqPsvJF3QHx 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..0ca0b37 --- /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; + +void +static 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