Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
filipsajdak committed Apr 21, 2023
1 parent da1cc61 commit 8066ef9
Show file tree
Hide file tree
Showing 13 changed files with 142 additions and 0 deletions.
27 changes: 27 additions & 0 deletions regression-tests/pure2-nested-ifs-error.cpp2
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
main: (args) = {
p : *int;

a := 1;
b := 2;
c := 3;
d := 4;

if args.argc == 3 {
p = a&;
} else if b > 2 {
if args.argc == 2 {
p = c&;
} else {
if b > 0 {
p = a&;
}
else {
p = d&;
}
}
} else {
// p = c&;
}

std::cout << p* << std::endl;
}
39 changes: 39 additions & 0 deletions regression-tests/pure2-nested-ifs.cpp2
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
main: (args) = {
p : *int;

a := 1;
b := 2;
c := 3;
d := 4;

if args.argc > 20 {
c = 20;
} else if args.argc > 10 {
c = 10;
} else {
if args.argc % 2 {
b = 2;
} else {
b = 1;
}
}

if args.argc == 3 {
p = a&;
} else if b > 2 {
if args.argc == 2 {
p = c&;
} else {
if b > 0 {
p = a&;
}
else {
p = d&;
}
}
} else {
p = c&;
}

std::cout << p* << std::endl;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pure2-nested-ifs-error.cpp2...
pure2-nested-ifs-error.cpp2(2,5): error: local variable p must be initialized on both branches or neither branch
pure2-nested-ifs-error.cpp2(9,5): error: "if" initializes p on:
branch starting at line 9
branch starting at line 11
but not on:
branch starting at line 22
==> program violates initialization safety guarantee - see previous errors

61 changes: 61 additions & 0 deletions regression-tests/test-results/pure2-nested-ifs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

#define CPP2_USE_MODULES Yes

//=== Cpp2 type declarations ====================================================


#include "cpp2util.h"



//=== Cpp2 type definitions and function declarations ===========================

#line 1 "pure2-nested-ifs.cpp2"
auto main(int const argc_, char const* const* const argv_) -> int;


//=== Cpp2 function definitions =================================================

#line 1 "pure2-nested-ifs.cpp2"
auto main(int const argc_, char const* const* const argv_) -> int{
auto args = cpp2::make_args(argc_, argv_);
#line 2 "pure2-nested-ifs.cpp2"
cpp2::deferred_init<int*> p;

auto a {1};
auto b {2};
auto c {3};
auto d {4};

if (cpp2::cmp_greater(args.argc,20)) {
c = 20;
} else if (cpp2::cmp_greater(args.argc,10)) {
c = 10;
}else {
if (args.argc % 2) {
b = 2;
}else {
b = 1;
}
}

if (args.argc==3) {
p.construct(&a);
} else if (cpp2::cmp_greater(b,2)) {
if (args.argc==2) {
p.construct(&c);
}else {
if (cpp2::cmp_greater(std::move(b),0)) {
p.construct(&a);
}
else {
p.construct(&d);
}
}
}else {
p.construct(&c);
}

std::cout << *cpp2::assert_not_null(std::move(p.value())) << std::endl;
}

2 changes: 2 additions & 0 deletions regression-tests/test-results/pure2-nested-ifs.cpp2.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pure2-nested-ifs.cpp2... ok (all Cpp2, passes safety checks)

0 comments on commit 8066ef9

Please sign in to comment.