import os,shutil

def run(arg):
    cmd = '.\hashibuild.exe ' + arg
    print ">", cmd
    out = os.popen(cmd).read()
    print out
    return out

os.system('go build')

cfg = "--config test/testprj.json "
run(cfg)
manifest = run(cfg + "--manifest")

for part in ["buildsomething.cmd", "subdir/testfile.txt"]:
    assert part in manifest

assert "ignored.txt" not in manifest

def nuke(pth):
    if os.path.isdir(pth):
        shutil.rmtree(pth)

outdir = "test/out"
nuke(outdir)

buildcmd = cfg + '--build'
run(buildcmd)
assert os.path.exists("test/out/testfile.txt")

archivedir = os.path.abspath("test/tmp")
os.environ["HASHIBUILD_ARCHIVE"] = archivedir
# this should usully move the file to batch upload place, not do slow upload on build
os.environ["HASHIBUILD_UPLOADER"] = "echo [ZIP]"
nuke(archivedir)
nuke(outdir)
withzipping = run(buildcmd)
assert "Zipping" in withzipping
run(buildcmd)
arccont = os.listdir(archivedir)

assert len(arccont) == 1 and "hashibuildtest" in arccont[0]
zipcont = os.popen("7za l %s/%s" % (archivedir, arccont[0])).read()
assert "testfile.txt" in zipcont
run("--vacuum")
nuke(archivedir)

# test remote fetching

os.environ["HASHIBUILD_ARCHIVE_REMOTE"] = "https://github.com/vivainio/hashibuild/raw/master/test/fakeremote/[ZIP]"
run(buildcmd)


@@ -10,16 +10,35 @@
 ,shutil%0D
+%0Aimport subprocess%0D
 %0A%0D%0Adef r
@@ -108,19 +108,17 @@
 md%0D%0A    
-out
+p
  = os.po
@@ -129,48 +129,204 @@
 cmd)
-.read()%0D%0A    print out%0D%0A    return out%0D%0A
+%0D%0A    out = p.read()%0D%0A    status = p.close()%0D%0A    if status:%0D%0A        raise RuntimeError(%22Command failed with %25d%22 %25 status)%0D%0A    print out%0D%0A    return out%0D%0A%0D%0Asubprocess.check_call(%5B%22go%22, %22build%22%5D)
 %0D%0Aos

test enhancement