Skip to content

Commit

Permalink
Added some tests for embed api, get/set compiler and commented set_st…
Browse files Browse the repository at this point in the history
…d_handles

since there is no way to test.
  • Loading branch information
kapace committed Jan 7, 2011
1 parent 9bc14ee commit f30aa2f
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/embed/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,8 @@ a true value if this call is successful and false value otherwise.
=cut
*/
/* Whiteknight told me that theres no way to test this for now, so it should be
commented out, for now.
PARROT_API
Parrot_Int
Expand Down Expand Up @@ -650,7 +652,7 @@ Parrot_api_set_stdhandles(Parrot_PMC interp_pmc, Parrot_Int in,
UNUSED(dummy);
EMBED_API_CALLOUT(interp_pmc, interp)
}
}*/

/*
Expand Down
99 changes: 98 additions & 1 deletion t/src/embed.t
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use File::Spec::Functions;

plan skip_all => 'src/parrot_config.o does not exist' unless -e catfile(qw/src parrot_config.o/);

plan tests => 15;
plan tests => 16;

=head1 NAME
Expand Down Expand Up @@ -1113,6 +1113,103 @@ OUTPUT

}


#c_output_is(linedirective(__LINE__) . <<'CODE', <<'OUTPUT', 'Test set_std_handles');
#
##include <stdio.h>
##include <stdlib.h>
##include <string.h>
##include "parrot/parrot.h"
##include "parrot/api.h"
##include "parrot/embed.h"
##include "parrot/extend.h"
#
#static void fail(const char *msg);
#static Parrot_String createstring(Parrot_Interp interp, const char * value);
#
#static void fail(const char *msg)
#{
# fprintf(stderr, "failed: %s\n", msg);
# exit(EXIT_FAILURE);
#}
#
#static Parrot_String createstring(Parrot_Interp interp, const char * value)
#{
# return Parrot_new_string(interp, value, strlen(value), (const char*)NULL, 0);
#}
#
#
#int main(int argc, const char **argv)
#{
#
# char * c_outstr = NULL;
# Parrot_Init_Args *initargs = NULL;
# Parrot_PMC interpmc = NULL;
# Parrot_PMC p_str = NULL, p_keyedstr = NULL;
# Parrot_String s_teststr = NULL, s_outstr = NULL;
#
# FILE * stdout = fopen("/tmp/stdout", "w");
# /*FILE * stdin = fopen("/tmp/stdin", "r");
# FILE * stderr = fopen("/tmp/stdin", "w");*/
#
# GET_INIT_STRUCT(initargs);
# Parrot_api_make_interpreter(NULL, 0, initargs, &interpmc);
#
# Parrot_api_set_stdhandles(interpmc, stdout, PIO_INVALID_HANDLE, PIO_INVALID_HANDLE);
# /* Now run a simple PIR program that outputs some text, and make sure that it is
# writen to the file instead of stdout etc */
# puts("Done");
# return 0;
#
#}
#CODE
#OUTPUT

c_output_is(linedirective(__LINE__) . <<'CODE', <<'OUTPUT', "get set compiler" );
#include <stdio.h>
#include <stdlib.h>
#include "parrot/api.h"
#include "parrot/embed.h"
void fail(const char *msg);
void fail(const char *msg)
{
fprintf(stderr, "failed: %s\n", msg);
exit(EXIT_FAILURE);
}
int main(int argc, const char **argv)
{
char * c_outstr = NULL;
Parrot_Init_Args *initargs = NULL;
Parrot_PMC interpmc = NULL;
Parrot_PMC apmc = NULL;
Parrot_PMC bpmc = NULL;
Parrot_String s_teststr = NULL, s_outstr = NULL;
int a;
GET_INIT_STRUCT(initargs);
Parrot_api_make_interpreter(NULL, 0, initargs, &interpmc);
Parrot_api_string_import_ascii(interpmc, "PIR", &s_teststr);
Parrot_api_load_language(interpmc, s_teststr);
Parrot_api_get_compiler(interpmc, s_teststr, &apmc);
Parrot_api_set_compiler(interpmc, s_teststr, apmc);
Parrot_api_get_compiler(interpmc, s_teststr, &bpmc);
printf ("%s\n", apmc == bpmc ? "True" : "False!");
puts("Done");
return 0;
}
CODE
True
Done
OUTPUT

# Local Variables:
# mode: cperl
# cperl-indent-level: 4
Expand Down

0 comments on commit f30aa2f

Please sign in to comment.