2 # Copyright (C) 2007-2008, Parrot Foundation.
8 use Test::More tests => 29;
11 use_ok('config::auto::opengl');
12 use Parrot::Configure::Options qw( process_options );
13 use Parrot::Configure::Step::Test;
14 use Parrot::Configure::Test qw(
15 test_step_constructor_and_description
17 use IO::CaptureOutput qw| capture |;
19 ########## --without-opengl ##########
21 my ($args, $step_list_ref) = process_options(
23 argv => [ q{--without-opengl} ],
28 my $conf = Parrot::Configure::Step::Test->new;
29 $conf->include_config_results( $args );
31 my $serialized = $conf->pcfreeze();
33 my $pkg = q{auto::opengl};
35 $conf->add_steps($pkg);
36 $conf->options->set( %{$args} );
37 my $step = test_step_constructor_and_description($conf);
38 ok( $step->runstep($conf), "runstep() returned true value");
39 is( $step->result(), 'no', "Got expected result" );
40 is( $conf->data->get( 'has_opengl' ), 0,
41 "Got expected value for 'has_opengl'");
43 $conf->replenish($serialized);
45 ########## _select_lib() ##########
47 ($args, $step_list_ref) = process_options(
53 $conf->add_steps($pkg);
54 $conf->options->set( %{$args} );
55 $step = test_step_constructor_and_description($conf);
57 # Mock OS/C-compiler combinations
58 my ($osname, $cc, $initial_libs);
59 $initial_libs = $conf->data->get('libs');
62 is($step->_select_lib( {
66 win32_gcc => '-lglut32 -lglu32 -lopengl32',
67 win32_nongcc => 'glut.lib glu.lib gl.lib',
68 darwin => '-framework OpenGL -framework GLUT',
69 default => '-lglut -lGLU -lGL',
71 '-lglut32 -lglu32 -lopengl32',
72 "_select_lib() returned expected value");
76 $initial_libs = $conf->data->get('libs');
77 is($step->_select_lib( {
81 win32_gcc => '-lglut32 -lglu32 -lopengl32',
82 win32_nongcc => 'glut.lib glu.lib gl.lib',
83 darwin => '-framework OpenGL -framework GLUT',
84 default => '-lglut -lGLU -lGL',
86 'glut.lib glu.lib gl.lib',
87 "_select_lib() returned expected value");
91 $initial_libs = $conf->data->get('libs');
92 is($step->_select_lib( {
96 win32_gcc => '-lglut32 -lglu32 -lopengl32',
97 win32_nongcc => 'glut.lib glu.lib gl.lib',
98 darwin => '-framework OpenGL -framework GLUT',
99 default => '-lglut -lGLU -lGL',
101 '-framework OpenGL -framework GLUT',
102 "_select_lib() returned expected value");
106 $initial_libs = $conf->data->get('libs');
107 is($step->_select_lib( {
111 win32_gcc => '-lglut32 -lglu32 -lopengl32',
112 win32_nongcc => 'glut.lib glu.lib gl.lib',
113 darwin => '-framework OpenGL -framework GLUT',
114 default => '-lglut -lGLU -lGL',
117 "_select_lib() returned expected value");
119 $conf->replenish($serialized);
121 ########## --verbose; _evaluate_cc_run() ##########
123 ($args, $step_list_ref) = process_options(
125 argv => [ q{--verbose} ],
126 mode => q{configure},
129 $conf->add_steps($pkg);
130 $conf->options->set( %{$args} );
131 $step = test_step_constructor_and_description($conf);
133 my @try = qw( 4 freeglut );
134 my $test = qq{$try[0] $try[1]\n};
137 my ($stdout, $stderr);
138 my ($glut_api_version, $glut_brand);
140 sub { ($glut_api_version, $glut_brand) = $step->_evaluate_cc_run(
147 is( $glut_api_version, $try[0],
148 "Got first expected return value for _evaluate_cc_run()." );
149 is( $glut_brand, $try[1],
150 "Got first expected return value for _evaluate_cc_run()." );
153 qr/yes, $glut_brand API version $glut_api_version/,
154 "Got expected verbose output for _evaluate_cc_run()"
156 # prepare for next test
157 $conf->options->set(verbose => undef);
160 ########## _handle_glut() ##########
163 my $glut_api_version = '4';
164 my $glut_brand = 'freeglut';
165 ok(auto::opengl::_handle_glut( $conf, 'lib', $glut_api_version, $glut_brand ),
166 "_handle_glut() returned true value");
167 is( $conf->data->get( 'opengl' ), 'define',
168 "Got expected value for opengl");
169 is( $conf->data->get( 'has_opengl' ), 1,
170 "Got expected value for has_opengl");
171 is( $conf->data->get( 'HAS_OPENGL' ), 1,
172 "Got expected value for HAS_OPENGL");
173 is( $conf->data->get( 'glut' ), 'define',
174 "Got expected value for glut");
175 is( $conf->data->get( 'glut_brand' ), $glut_brand,
176 "Got expected value for glut_brand");
177 is( $conf->data->get( 'has_glut' ), $glut_api_version,
178 "Got expected value for has_glut");
179 is( $conf->data->get( 'HAS_GLUT' ), $glut_api_version,
180 "Got expected value for HAS_GLUT");
183 pass("Completed all tests in $0");
185 ################### DOCUMENTATION ###################
189 auto/opengl-01.t - test auto::opengl
193 % prove t/steps/auto/opengl-01.t
197 The files in this directory test functionality used by F<Configure.pl>.
199 The tests in this file test configuration step class auto::opengl.
203 Geoffrey Broadwell; modified from a similar file by James E Keenan
207 config::auto::opengl, F<Configure.pl>.
213 # cperl-indent-level: 4
216 # vim: expandtab shiftwidth=4: