Skip to content

Commit

Permalink
test: bug #130 reproduced (Go tests are supposed to fail) #129 #130
Browse files Browse the repository at this point in the history
  • Loading branch information
flelli committed Jan 22, 2023
1 parent 04f7a89 commit 65ca0de
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion modules/go/nyx/git/go_git_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ func (r goGitRepository) IsClean() (bool, error) {
// if the output is the empty string the repository is clean
if "" == strings.TrimSpace(out.String()) {
log.Debugf("workaround #130: the 'git status' command returned an empty output so the repository is clean")
clean = true
//clean = true
} else {
log.Debugf("workaround #130: the 'git status' command returned a non-empty output so the repository is dirty")
clean = false
Expand Down
14 changes: 12 additions & 2 deletions modules/go/nyx/test/integration/git/go_git_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1416,7 +1416,6 @@ func TestGoGitRepositoryIsCleanWithTextFileContainingLineFeedsUsingEmbeddedLibra
dir := script.GetWorkingDirectory()
repository, err := GitInstance().Open(dir)
assert.NoError(t, err)

clean, err := repository.IsClean()
assert.NoError(t, err)
assert.True(t, clean)
Expand All @@ -1429,19 +1428,25 @@ func TestGoGitRepositoryIsCleanWithTextFileContainingLineFeedsUsingEmbeddedLibra
err = os.WriteFile(fileName, []byte("\r\n"), 0644)
assert.NoError(t, err)

repository, err = GitInstance().Open(dir)
assert.NoError(t, err)
clean, err = repository.IsClean()
assert.NoError(t, err)
assert.False(t, clean)

// stage the files without committing
script.AndStage()
repository, err = GitInstance().Open(dir)
assert.NoError(t, err)
clean, err = repository.IsClean()
assert.NoError(t, err)
assert.False(t, clean)

// commit the files, now we're supposed to be clean again but when the bug is present we're not
script.AndCommit()
// when the bug is present, this call to IsClean() returns false even if it's supposed to return true
repository, err = GitInstance().Open(dir)
assert.NoError(t, err)
clean, err = repository.IsClean()
assert.NoError(t, err)
assert.True(t, clean)
Expand Down Expand Up @@ -1472,7 +1477,6 @@ func TestGoGitRepositoryIsCleanWithTextFileContainingLineFeedsUsingGitCommand(t

repository, err := GitInstance().Open(repoDirectory)
assert.NoError(t, err)

clean, err := repository.IsClean()
assert.NoError(t, err)
assert.True(t, clean)
Expand All @@ -1485,6 +1489,8 @@ func TestGoGitRepositoryIsCleanWithTextFileContainingLineFeedsUsingGitCommand(t
err = os.WriteFile(fileName, []byte("\r\n"), 0644)
assert.NoError(t, err)

repository, err = GitInstance().Open(repoDirectory)
assert.NoError(t, err)
clean, err = repository.IsClean()
assert.NoError(t, err)
assert.False(t, clean)
Expand All @@ -1498,6 +1504,8 @@ func TestGoGitRepositoryIsCleanWithTextFileContainingLineFeedsUsingGitCommand(t
fmt.Printf("%v\n", out.String())
}
assert.NoError(t, err)
repository, err = GitInstance().Open(repoDirectory)
assert.NoError(t, err)
clean, err = repository.IsClean()
assert.NoError(t, err)
assert.False(t, clean)
Expand All @@ -1512,6 +1520,8 @@ func TestGoGitRepositoryIsCleanWithTextFileContainingLineFeedsUsingGitCommand(t
}
assert.NoError(t, err)
// when the bug is present, this call to IsClean() returns false even if it's supposed to return true
repository, err = GitInstance().Open(repoDirectory)
assert.NoError(t, err)
clean, err = repository.IsClean()
assert.NoError(t, err)
assert.True(t, clean)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1335,8 +1335,7 @@ public void isCleanWithTextFileContainingLineFeedsUsingEmbeddedLibraryTest()
// repository status and also to execute the Git commands to build the test repository.
Script script = Scenario.FROM_SCRATCH.realize();
script.getWorkingDirectory().deleteOnExit();
Repository repository = JGitRepository.open(script.getWorkingDirectory());
assertTrue(repository.isClean());
assertTrue(JGitRepository.open(script.getWorkingDirectory()).isClean());

// add one file with a LF and a CRLF and test
File f = new File(script.getWorkingDirectory(), "README.txt");
Expand All @@ -1347,16 +1346,16 @@ public void isCleanWithTextFileContainingLineFeedsUsingEmbeddedLibraryTest()
fw.write("\r\n");
fw.flush();
fw.close();
assertFalse(repository.isClean());
assertFalse(JGitRepository.open(script.getWorkingDirectory()).isClean());

// stage the files without committing
script.andStage();
assertFalse(repository.isClean());
assertFalse(JGitRepository.open(script.getWorkingDirectory()).isClean());

// commit the files, now we're supposed to be clean again but when the bug is present we're not
script.andCommit();
// when the bug is present, this call to IsClean() returns false even if it's supposed to return true
assertTrue(repository.isClean());
assertTrue(JGitRepository.open(script.getWorkingDirectory()).isClean());
}

@DisplayName("JGitRepository.isClean() with a test file containing linefeeds using the git command")
Expand All @@ -1378,8 +1377,7 @@ public void isCleanWithTextFileContainingLineFeedsUsingGitCommandTest()
p.waitFor();
p.destroy();

Repository repository = JGitRepository.open(repoDirectory);
assertTrue(repository.isClean());
assertTrue(JGitRepository.open(repoDirectory).isClean());

// add one file with a LF and a CRLF and test
File f = new File(repoDirectory, "README.txt");
Expand All @@ -1390,20 +1388,20 @@ public void isCleanWithTextFileContainingLineFeedsUsingGitCommandTest()
fw.write("\r\n");
fw.flush();
fw.close();
assertFalse(repository.isClean());
assertFalse(JGitRepository.open(repoDirectory).isClean());

// stage the files without committing
p = new ProcessBuilder(new String[]{"git", "add", "."}).directory(repoDirectory).redirectErrorStream(true).start();
p.waitFor();
p.destroy();
assertFalse(repository.isClean());
assertFalse(JGitRepository.open(repoDirectory).isClean());

// commit the files, now we're supposed to be clean again but when the bug is present we're not
p = new ProcessBuilder(new String[]{"git", "commit", "-m", "\"commit\""}).directory(repoDirectory).redirectErrorStream(true).start();
p.waitFor();
p.destroy();
// when the bug is present, this call to IsClean() returns false even if it's supposed to return true
assertTrue(repository.isClean());
assertTrue(JGitRepository.open(repoDirectory).isClean());
}
}

Expand Down

0 comments on commit 65ca0de

Please sign in to comment.