diff --git a/tests/init/side_cwd/side.txt b/tests/init/side_cwd/side.txt new file mode 100644 index 00000000..9c558e35 --- /dev/null +++ b/tests/init/side_cwd/side.txt @@ -0,0 +1 @@ +. diff --git a/tests/init/up_cwd/project/sub/test.txt b/tests/init/up_cwd/project/sub/test.txt new file mode 100644 index 00000000..9c558e35 --- /dev/null +++ b/tests/init/up_cwd/project/sub/test.txt @@ -0,0 +1 @@ +. diff --git a/tests/init/up_cwd/project/wscript b/tests/init/up_cwd/project/wscript new file mode 100755 index 00000000..8e449636 --- /dev/null +++ b/tests/init/up_cwd/project/wscript @@ -0,0 +1,47 @@ +#! /usr/bin/env waf + +top = '.' +out = 'tmp_out' + +import os +from waflib import ConfigSet, Context, Build, Configure + +Configure.autoconfig='clobber' + +def options(opt): + opt.add_option('--based', action='store', default='foo', help='base directory', dest='based') + opt.add_option('--dumpf', action='store', default='foo', help='dump config to this file', dest='dumpf') + +def configure(ctx): + pass + +def build(ctx): + pass + +def write_conf(ctx): + if not ctx.options.dumpf: + raise ValueError('Missing --dumpf option') + if not ctx.options.based: + raise ValueError('Missing --based option') + + def g(x): + # path from conf.options.based + based = ctx.root.find_node(ctx.options.based) + node = ctx.root.find_node(x) + return node.path_from(based) + + env = ConfigSet.ConfigSet() + env.cwd_dir = g(os.getcwd()) + env.top_dir = g(Context.top_dir) + env.out_dir = g(Context.out_dir) + env.run_dir = g(Context.run_dir) + env.launch_dir = g(Context.launch_dir) + + env.store(ctx.options.dumpf) + +for y in (Build.BuildContext, Configure.ConfigurationContext): + class tmp(y): + def execute(self, *k, **kw): + super(self.__class__, self).execute(*k, **kw) + write_conf(self) + diff --git a/tests/init/wscript b/tests/init/wscript new file mode 100644 index 00000000..62981934 --- /dev/null +++ b/tests/init/wscript @@ -0,0 +1,120 @@ +#! /usr/bin/env python + +top = '.' +out = 'build' + +import os, shutil, subprocess, sys +from waflib import ConfigSet, Logs, Utils + +def options(opt): + pass + +def configure(conf): + pass + + +def run_command(ctx, *k, **kw): + with open('/dev/null', 'w') as f: + kw['stdout'] = f + ret = ctx.exec_command(*k, **kw) + if ret: + ctx.fatal('Command failed ret:%r - %r %r' % (ret, k, kw)) + return ret + +def cleanup(ctx): + for y in ('side_cwd', 'up_cwd'): + lst = ctx.path.find_node(y).ant_glob(['**/.lock-waf*']) + for k in lst: + k.delete() + + for k in ctx.path.ant_glob('**/tmp_out', dir=True): + shutil.rmtree(k.abspath()) + +def build(bld): + failures = [] + up_cwd = bld.path.find_node('up_cwd').abspath() + side_cwd = bld.path.find_node('side_cwd').abspath() + proj_cwd = bld.path.find_node('up_cwd/project').abspath() + proj_sub_cwd = bld.path.find_node('up_cwd/project/sub').abspath() + proj_out_cwd = bld.path.make_node('up_cwd/project/tmp_out').abspath() + wscript = bld.path.find_node('up_cwd/project/wscript').abspath() + + d_node = bld.path.make_node('path_to_record') + dumpf_default = d_node.abspath() + + def make_cmd(cmd, based=proj_cwd, dumpf=dumpf_default): + return list(cmd) + ['--based=%s' % based, '--dumpf=%s' % dumpf] + + def test_cmd(cmd, cwd, test_name, cwd_dir='.', top_dir='.', out_dir='tmp_out', run_dir='.', launch_dir='.'): + cmd = make_cmd(cmd) + try: + run_command(bld, cmd, cwd=cwd) + v = ConfigSet.ConfigSet(dumpf_default) + finally: + for k in bld.path.ant_glob('**/path_to_record'): + k.delete() + + err = [] + def check_err(got, expected, var_name): + if got != expected: + Logs.pprint('RED', '- %s: %s -> got:%r expected:%r' % (test_name, var_name, got, expected)) + err.append(var_name) + + check_err(v.cwd_dir, cwd_dir, 'cwd') + check_err(v.top_dir, top_dir, 'top') + check_err(v.run_dir, run_dir, 'run') + check_err(v.out_dir, out_dir, 'out') + check_err(v.launch_dir, launch_dir, 'launch') + if err: + failures.append(test_name) + else: + Logs.pprint('GREEN', '- %s: ok' % test_name) + + exe = sys.argv[0] + + cleanup(bld) + + test_cmd([exe, 'configure'], proj_cwd, 'regular configure') + test_cmd([exe], proj_cwd, ' regular build from top') + test_cmd([exe], proj_out_cwd, ' regular build from out', launch_dir='tmp_out') + test_cmd([exe], proj_sub_cwd, ' regular build from subfolder', launch_dir='sub') + cleanup(bld) + + test_cmd([exe, 'configure', '--top=%s' % proj_cwd, '--out=%s' % proj_out_cwd], proj_cwd, 'configure with top/out from proj cwd') + test_cmd([exe], proj_cwd, ' next build from top') + test_cmd([exe], proj_out_cwd, ' next build from out', launch_dir='tmp_out') + test_cmd([exe], proj_sub_cwd, ' next build from subfolder', launch_dir='sub') + cleanup(bld) + + test_cmd([exe, 'configure', '--top=%s' % proj_cwd, '--out=%s' % proj_out_cwd], up_cwd, 'configure with top/out from up cwd', + launch_dir='..') + test_cmd([exe], proj_cwd, ' next build from top') + test_cmd([exe], proj_out_cwd, ' next build from out', launch_dir='tmp_out') + test_cmd([exe], proj_sub_cwd, ' next build from subfolder', launch_dir='sub') + cleanup(bld) + + test_cmd([wscript, 'configure'], proj_cwd, 'wscript configure') + test_cmd([wscript], proj_cwd, ' next build from top') + test_cmd([wscript], proj_out_cwd, ' next build from out', launch_dir='tmp_out') + test_cmd([wscript], proj_sub_cwd, ' next build from subfolder', launch_dir='sub') + cleanup(bld) + + test_cmd([wscript, 'configure', '--top=%s' % proj_cwd, '--out=%s' % proj_out_cwd], proj_cwd, 'wscript configure with top/out from proj cwd') + test_cmd([wscript], proj_cwd, ' next build from top') + test_cmd([wscript], proj_out_cwd, ' next build from out', launch_dir='tmp_out') + test_cmd([wscript], proj_sub_cwd, ' next build from subfolder', launch_dir='sub') + cleanup(bld) + + test_cmd([wscript, 'configure', '--top=%s' % proj_cwd, '--out=%s' % proj_out_cwd], up_cwd, 'wscript configure with top/out from up cwd', + launch_dir='..') + test_cmd([wscript], proj_cwd, ' next build from top') + test_cmd([wscript], proj_out_cwd, ' next build from out', launch_dir='tmp_out') + test_cmd([wscript], proj_sub_cwd, ' next build from subfolder', launch_dir='sub') + cleanup(bld) + + test_cmd([exe, '--top=%s' % proj_cwd], proj_cwd, 'autoconfig') + cleanup(bld) + + if failures: + bld.fatal('there were errors') +