def test_not_rebuilt(): src = t.tmpfname() tgt = t.tmpfname() @t.build(src, recreate=False) def mksrc(task): open(task.name, "wb").write(t.uuid.uuid4().hex) @t.build(tgt, [src]) def mktgt(task): print task.sources print task.source open(task.name, "wb").write(open(task.source).read()) print t.app.mgr.tasks t.app.run(None, [tgt]) t.eq(t.app._dbg, [(src, None), (tgt, None)]) t.eq(os.path.exists(src), True) t.eq(os.path.exists(tgt), True) first_run = open(src).read() t.eq(open(tgt).read(), first_run) t.app.clear() t.app.run(None, [tgt]) t.eq(t.app._dbg, []) t.eq(open(src).read(), first_run) t.eq(open(tgt).read(), first_run)
def test_basic_rule(): csrc = t.tmpfname("foo.c") cobj = t.tmpfname("foo.o") app = t.tmpfname("foo") @t.rule(".o", ".c") def compile(task): open(task.name, "wb").write(open(task.source).read() + "+with_o") @t.build(app, [cobj]) def link(task): open(task.name, "wb").write(open(task.source).read() + "+linked") open(csrc, "wb").write("source") t.app.run(None, [app]) t.eq(t.app._dbg, [(cobj, None), (app, None)])
def test_dep_on_synth(): src = t.tmpfname() tgt = t.tmpfname() @t.synth() def synthdep(task): task.synth(src) src.write_bytes("fo") @t.build(tgt, [synthdep]) def withdep(task): task.name.write_bytes(task.source.bytes() + "o") t.app.run(None, [tgt]) t.eq(t.app._dbg, [("synthdep", None), (tgt, None)]) t.eq(src.bytes(), "fo") t.eq(tgt.bytes(), "foo")
def test_multi_sources(): csrcs = [t.tmpfname() + ".c" for i in range(10)] cobjs = [fn[:-2] + ".o" for fn in csrcs] app = t.tmpfname() @t.rule(".o", ".c") def compile(task): open(task.name, "wb").write(open(task.source).read() + ".o") @t.build(app, cobjs) def link(task): open(task.name, "wb").write(open(task.source).read() + ".exe") for cs in csrcs: open(cs, "wb").write("source") t.app.run(None, [app]) t.eq(len(t.app._dbg), len(cobjs)+1) t.eq(t.app._dbg[0], (cobjs[0], None)) t.eq(t.app._dbg[-1], (app, None))
def make_chain(depth): if depth < 1: fname = t.tmpfname() open(fname + ".0", "wb").write("ohai!") return fname @t.rule(".%d" % depth, ".%d" % (depth-1)) def chained(task): open(task.name, "wb").write(open(task.source).read()) return make_chain(depth-1)
def test_dep_not_filetask(): src = t.tmpfname() tgt = t.tmpfname() @t.task def mksrc(task): src.write_bytes("sourcey") @t.build(tgt, [mksrc]) def mktgt(task): task.name.write_bytes("yup") t.app.run(None, [tgt]) t.eq(t.app._dbg, [("mksrc", None), (tgt, None)]) t.app.clear() t.app.run(None, [tgt]) t.eq(t.app._dbg, [("mksrc", None), (tgt, None)])
def test_synth_file(): fname = t.tmpfname() @t.synth() def synth(t): t.synth(fname) fname.write_bytes("o") t.app.run(None, ["synth"]) t.eq(t.app._dbg, [("synth", None)]) t.eq(fname.exists(), True) t.eq(fname.bytes(), "o")
def test_multi_sources(): csrcs = [t.tmpfname() + ".c" for i in range(10)] cobjs = [fn[:-2] + ".o" for fn in csrcs] app = t.tmpfname() @t.rule(".o", ".c") def compile(task): open(task.name, "wb").write(open(task.source).read() + ".o") @t.build(app, cobjs) def link(task): open(task.name, "wb").write(open(task.source).read() + ".exe") for cs in csrcs: open(cs, "wb").write("source") t.app.run(None, [app]) t.eq(len(t.app._dbg), len(cobjs) + 1) t.eq(t.app._dbg[0], (cobjs[0], None)) t.eq(t.app._dbg[-1], (app, None))
def make_chain(depth): if depth < 1: fname = t.tmpfname() open(fname + ".0", "wb").write("ohai!") return fname @t.rule(".%d" % depth, ".%d" % (depth - 1)) def chained(task): open(task.name, "wb").write(open(task.source).read()) return make_chain(depth - 1)
def test_basic_file(): fname = t.tmpfname() @t.build(fname) def build(t): open(t.name, "wb").write("o") t.app.run(None, [fname]) t.eq(t.app._dbg, [(fname, None)]) t.eq(os.path.exists(fname), True) t.eq(open(fname).read(), "o")
def test_synth_with_dep(): base = t.tmpfname() src = t.tmpfname() tgt = t.tmpfname() base.write_bytes("s") @t.build(src, [base]) def mkdep(task, recreate=False): open(task.name, "wb").write("o") @t.synth([src]) def synth(task): task.synth(tgt) tgt.write_bytes(src.bytes() + "n") t.app.run(None, ["synth"]) t.eq(t.app._dbg, [(src, None), ("synth", None)]) t.eq(src.bytes(), "o") t.eq(tgt.bytes(), "on") # Rerun t.app.clear() t.app.run(None, ["synth"]) t.eq(t.app._dbg, [])
def test_rerun_build(): tgt = t.tmpfname() @t.build(tgt) def mktgt(task): task.name.write_bytes("yup") t.app.run(None, [tgt]) t.eq(t.app._dbg, [(tgt, None)]) t.app.clear() t.app.run(None, [tgt]) t.eq(t.app._dbg, [(tgt, None)])
def test_file_as_dep(): fname = t.tmpfname() @t.build(fname) def build(t): open(t.name, "wb").write("h") @t.task([fname]) def foo(): return 2 t.app.run(None, ["foo"]) t.eq(t.app._dbg, [(fname, None), ("foo", 2)]) t.eq(os.path.exists(fname), True) t.eq(open(fname).read(), "h")
def test_file_creation(): fname = t.tmpfname() @t.build(fname, recreate=False) def build(task): open(task.name, "wb").write(t.uuid.uuid4().hex) t.app.run(None, [fname]) t.eq(t.app._dbg, [(fname, None)]) t.eq(os.path.exists(fname), True) first_run = open(fname).read() t.app.clear() t.app.run(None, [fname]) t.eq(t.app._dbg, []) t.eq(os.path.exists(fname), True) t.eq(open(fname).read(), first_run)
def test_not_rebuilt(): prefile = t.tmpfname("foo.c") postfile = t.tmpfname("bar.c") src = t.tmpfname() tgt = t.tmpfname() # Make the prefile, if this is the only file # available to the mktgt rule, then we know that # lazy evaluation was broken with open(prefile, "wb") as out: out.write("prefile") @t.build(src) def mksrc(task, recreate=True): task.name.write_bytes(t.uuid.uuid4().hex) postfile.write_bytes("postfile") @t.build(tgt, [src, t.FileList(t.DATA_DIR / "*.c")]) def mktgt(task): return sorted(task.sources) t.eq(sorted(task.sources), ) out.write_bytes(data.bytes()) # Check that postfile doesn't exist yet. t.eq(postfile.exists(), False) # Run the pipeline, test that target saw the # expected sources t.app.run(None, [tgt]) tgt_out = sorted([src, t.DATA_DIR / "foo.c", t.DATA_DIR / "bar.c"]) t.eq(t.app._dbg, [(src, None), (tgt, tgt_out)]) # Postfile should now exist: t.eq(postfile.exists(), True) # Rerun without destroying postfile t.app.clear() t.app.run(None, [tgt]) tgt_out = sorted([src, t.DATA_DIR / "foo.c", t.DATA_DIR / "bar.c"]) t.eq(t.app._dbg, [(src, None), (tgt, tgt_out)]) # Create a new file to show that we rebind # for each run. t.tmpfname("zoo.c").write_bytes("postpostfile") t.app.clear() t.app.run(None, [tgt]) tgt_out = sorted([ src, t.DATA_DIR / "foo.c", t.DATA_DIR / "bar.c", t.DATA_DIR / "zoo.c" ]) t.eq(t.app._dbg, [(src, None), (tgt, tgt_out)])
def test_not_rebuilt(): prefile = t.tmpfname("foo.c") postfile = t.tmpfname("bar.c") src = t.tmpfname() tgt = t.tmpfname() # Make the prefile, if this is the only file # available to the mktgt rule, then we know that # lazy evaluation was broken with open(prefile, "wb") as out: out.write("prefile") @t.build(src) def mksrc(task, recreate=True): task.name.write_bytes(t.uuid.uuid4().hex) postfile.write_bytes("postfile") @t.build(tgt, [src, t.FileList(t.DATA_DIR / "*.c")]) def mktgt(task): return sorted(task.sources) t.eq(sorted(task.sources), ) out.write_bytes(data.bytes()) # Check that postfile doesn't exist yet. t.eq(postfile.exists(), False) # Run the pipeline, test that target saw the # expected sources t.app.run(None, [tgt]) tgt_out = sorted([src, t.DATA_DIR/"foo.c", t.DATA_DIR/"bar.c"]) t.eq(t.app._dbg, [(src, None), (tgt, tgt_out)]) # Postfile should now exist: t.eq(postfile.exists(), True) # Rerun without destroying postfile t.app.clear() t.app.run(None, [tgt]) tgt_out = sorted([src, t.DATA_DIR/"foo.c", t.DATA_DIR/"bar.c"]) t.eq(t.app._dbg, [(src, None), (tgt, tgt_out)]) # Create a new file to show that we rebind # for each run. t.tmpfname("zoo.c").write_bytes("postpostfile") t.app.clear() t.app.run(None, [tgt]) tgt_out = sorted([src, t.DATA_DIR/"foo.c", t.DATA_DIR/"bar.c", t.DATA_DIR/"zoo.c"]) t.eq(t.app._dbg, [(src, None), (tgt, tgt_out)])
def synth(task): task.synth(t.tmpfname())