package pro.cucumber;

import org.junit.Before;
import org.junit.Test;
import pro.cucumber.gitcli.GitCliRevisionProvider;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.regex.Pattern;

import static org.junit.Assert.assertTrue;

public abstract class RevisionProviderContract {
    private Path rootPath;

    @Before
    public void createScm() throws IOException {
        rootPath = Files.createTempDirectory("GitWC");
        Path subfolder = rootPath.resolve("subfolder");
        Files.createDirectory(subfolder);
        Files.createFile(subfolder.resolve("file"));
        Exec.cmd("git init", rootPath);
        Exec.cmd("git add -A", rootPath);
        Exec.cmd("git commit -am \"files\"", rootPath);
        System.out.println(Exec.cmd("ls -al", rootPath));
    }

    @Test
    public void findsRev() {
        String sha1Pattern = "^[a-f0-9]{40}$";
        RevisionProvider revisionProvider = makeRevisionProvider(rootPath);
        assertTrue("Expected a sha1", Pattern.matches(sha1Pattern, revisionProvider.getRev()));
    }

    protected abstract RevisionProvider makeRevisionProvider(Path rootPath);

}
@@ -762,66 +762,8 @@
 h);%0A
-        System.out.println(Exec.cmd(%22ls -al%22, rootPath));%0A
     
@@ -919,32 +919,80 @@
 ider(rootPath);%0A
+        String rev = revisionProvider.getRev();%0A
         assertTr
@@ -1010,17 +1010,28 @@
 d a sha1
-%22
+, got: %22+rev
 , Patter
@@ -1056,38 +1056,16 @@
 ern, rev
-isionProvider.getRev()
 ));%0A    

Improve error message