Skip to content

Commit

Permalink
header_includes
Browse files Browse the repository at this point in the history
  • Loading branch information
sim-immunant committed Oct 6, 2023
1 parent 54a793b commit ca0d4b9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions rewriter/tests/header_includes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ define_shared_lib(
define_test(
SRCS main.c
NEEDS_LD_WRAP
CRITERION_TEST
)

# Build the wrapper lib
Expand Down
6 changes: 3 additions & 3 deletions rewriter/tests/header_includes/liboption.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
RUN: cat header_includes_call_gates_1.ld | FileCheck --check-prefix=LINKARGS %s
*/
#include <stdio.h>
#include <criterion/logging.h>
#include "liboption.h"
#include "types.h"

// LINKARGS: --wrap=None
Option None() {
printf("returning `None`\n");
cr_log_info("returning `None`");
Option none = {
.value = 0,
.present = false,
Expand All @@ -17,7 +17,7 @@ Option None() {

// LINKARGS: --wrap=Some
Option Some(int x) {
printf("returning `Some(%d)`\n", x);
cr_log_info("returning `Some(%d)`", x);
Option opt = {
.value = x,
.present = true,
Expand Down
9 changes: 5 additions & 4 deletions rewriter/tests/header_includes/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ RUN: sh -c 'if [ ! -s "header_includes_call_gates_0.ld" ]; then echo "No link ar
*/
#include "liboption.h"
#include "types.h"
#include <stdio.h>
#include <criterion/criterion.h>
#include <criterion/logging.h>
#include <ia2.h>

INIT_RUNTIME(1);
#define IA2_COMPARTMENT 1
#include <ia2_compartment_init.inc>

int main() {
Test(header_includes, main) {
Option x = Some(3);
Option none = None();
printf("`x` has value %d\n", unwrap_or(x, -1));
printf("`none` has no value %d\n", unwrap_or(none, -1));
cr_assert_eq(unwrap_or(x, -1), 3);
cr_assert_eq(unwrap_or(none, -1), -1);
}

0 comments on commit ca0d4b9

Please sign in to comment.