-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[master] unique-ptr retval test (#43)
- Loading branch information
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/perl | ||
|
||
use warnings; | ||
use strict; | ||
$ENV{"DALE_TEST_ARGS"} ||= ""; | ||
my $test_dir = $ENV{"DALE_TEST_DIR"} || "."; | ||
$ENV{PATH} .= ":."; | ||
|
||
use Data::Dumper; | ||
use Test::More tests => 3; | ||
|
||
my @res = `dalec $ENV{"DALE_TEST_ARGS"} $test_dir/t/src/up-move-fn-ret.dt -o up-move-fn-ret `; | ||
is_deeply(\@res, [], 'No compilation errors'); | ||
@res = `./up-move-fn-ret`; | ||
is($?, 0, 'Program executed successfully'); | ||
|
||
chomp for @res; | ||
|
||
is_deeply(\@res, [ | ||
'0 100 0', | ||
'100', | ||
'0 0 100', | ||
], | ||
'Got correct results'); | ||
|
||
`rm up-move-fn-ret`; | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
(import cstdio) | ||
(import macros) | ||
(import unique-ptr) | ||
|
||
(std.concepts.instantiate UniquePtr int) | ||
|
||
(def otherfn | ||
(fn extern (retval (UniquePtr int)) ((myptr (rv-ref (UniquePtr int)))) | ||
(def myptr2 (var auto (UniquePtr int) (move (@ myptr)))) | ||
(printf "%d\n" (@ myptr2)) | ||
(setf retval (move myptr2)) | ||
(return))) | ||
|
||
(def main | ||
(fn extern-c int (void) | ||
(let ((myptr (UniquePtr int)) | ||
(myptr2 (UniquePtr int)) | ||
(myptr3 (UniquePtr int)) | ||
(myint \ (malloc' 1 int))) | ||
(setf myint 100) | ||
(init myptr myint) | ||
(setv myptr2 (move myptr)) | ||
(printf "%d %d %d\n" (cast (get myptr) intptr) | ||
(@ myptr2) | ||
(cast (get myptr3) intptr)) | ||
(setv myptr3 (otherfn (move myptr2))) | ||
(printf "%d %d %d\n" (cast (get myptr) intptr) | ||
(cast (get myptr2) intptr) | ||
(@ myptr3)) | ||
0))) |