public inbox for ~johnnyrichard/olang-devel@lists.sr.ht
 help / color / mirror / code / Atom feed
From: Carlos Maniero <carlos@maniero.me>
To: ~johnnyrichard/olang-devel@lists.sr.ht
Cc: Carlos Maniero <carlos@maniero.me>
Subject: [PATCH olang v2 3/3] tests: add tests for the minimal possible olang program
Date: Fri,  8 Mar 2024 19:39:09 -0300	[thread overview]
Message-ID: <20240308223909.3184226-4-carlos@maniero.me> (raw)
In-Reply-To: <20240308223909.3184226-1-carlos@maniero.me>

This test is just to ensure the cli is well set and it is compiling a
program given the appropriated flags.

Signed-off-by: Carlos Maniero <carlos@maniero.me>
---
 tests/integration/cli_runner.c | 11 +++++++++++
 tests/integration/cli_test.c   | 21 +++++++++++++++++++++
 2 files changed, 32 insertions(+)

diff --git a/tests/integration/cli_runner.c b/tests/integration/cli_runner.c
index 5a40e15..fed12ab 100644
--- a/tests/integration/cli_runner.c
+++ b/tests/integration/cli_runner.c
@@ -87,3 +87,14 @@ cli_runner_compiler_dump_tokens(char *src)
     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[] = { "0c", src, "-o", result.binary_path, NULL };
+    cli_runner_compiler(&result, program_args);
+    return result;
+}
diff --git a/tests/integration/cli_test.c b/tests/integration/cli_test.c
index 126f612..c5896df 100644
--- a/tests/integration/cli_test.c
+++ b/tests/integration/cli_test.c
@@ -17,6 +17,7 @@
 #define MUNIT_ENABLE_ASSERT_ALIASES
 #include "cli_runner.h"
 #include "munit.h"
+#include <stdio.h>
 
 static MunitResult
 test_cli_dump_tokens(const MunitParameter params[], void *user_data_or_fixture)
@@ -41,8 +42,28 @@ test_cli_dump_tokens(const MunitParameter params[], void *user_data_or_fixture)
     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.0");
+    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", test_cli_dump_tokens, 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 }
 };
 
-- 
2.34.1


  parent reply	other threads:[~2024-03-08 22:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-08 22:39 [PATCH olang v2 0/3] test: cli: cover compilation pipeline Carlos Maniero
2024-03-08 22:39 ` [PATCH olang v2 1/3] tests: fix: rename dump tokens test name Carlos Maniero
2024-03-08 22:39 ` [PATCH olang v2 2/3] tests: decouple command execution from cli_runner Carlos Maniero
2024-03-08 22:39 ` Carlos Maniero [this message]
2024-03-08 22:40   ` [olang/patches/.build.yml] build success builds.sr.ht
2024-03-08 23:59 ` [PATCH olang v2 0/3] test: cli: cover compilation pipeline Johnny Richard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240308223909.3184226-4-carlos@maniero.me \
    --to=carlos@maniero.me \
    --cc=~johnnyrichard/olang-devel@lists.sr.ht \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.johnnyrichard.com/olang.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox