summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2022-02-01 05:23:14 -0500
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>2022-02-01 05:23:14 -0500
commit6778e89bfafbeb8eedaf4e35d0ee9c4af057a7e4 (patch)
tree759439407edce19bbf22b33f4de7ea06750b9eba
parent48aae36a22455fbb7553054003de0be69b2b5311 (diff)
parent58d203fc7f97706183b4427e2175dac400cd1dca (diff)
downloadjgit-6778e89bfafbeb8eedaf4e35d0ee9c4af057a7e4.tar.gz
jgit-6778e89bfafbeb8eedaf4e35d0ee9c4af057a7e4.zip
Merge "[test] Fix EolRepositoryTest for eol=native"
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolRepositoryTest.java114
1 files changed, 44 insertions, 70 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolRepositoryTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolRepositoryTest.java
index d0dfd1ab92..b937b1f6a9 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolRepositoryTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolRepositoryTest.java
@@ -1,40 +1,11 @@
/*
- * Copyright (C) 2015, Ivan Motsch <ivan.motsch@bsiag.com>
+ * Copyright (C) 2015, 2022 Ivan Motsch <ivan.motsch@bsiag.com> and others
*
- * This program and the accompanying materials are made available
- * under the terms of the Eclipse Distribution License v1.0 which
- * accompanies this distribution, is reproduced below, and is
- * available at http://www.eclipse.org/org/documents/edl-v10.php
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Distribution License v. 1.0 which is available at
+ * https://www.eclipse.org/org/documents/edl-v10.php.
*
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or
- * without modification, are permitted provided that the following
- * conditions are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided
- * with the distribution.
- *
- * - Neither the name of the Eclipse Foundation, Inc. nor the
- * names of its contributors may be used to endorse or promote
- * products derived from this software without specific prior
- * written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * SPDX-License-Identifier: BSD-3-Clause
*/
package org.eclipse.jgit.api;
@@ -173,15 +144,22 @@ public class EolRepositoryTest extends RepositoryTestCase {
private DirCache dirCache;
+ private boolean isDefaultCrLf() {
+ String eol = mockSystemReader.getProperty("line.separator");
+ return "\r\n".equals(eol);
+ }
+
@Test
public void testDefaultSetup() throws Exception {
// for EOL to work, the text attribute must be set
setupGitAndDoHardReset(null, null, null, null, "* text=auto");
collectRepositoryState();
assertEquals("text=auto", entryCRLF.attrs);
- checkEntryContent(entryCRLF, CONTENT_LF, CONTENT_LF);
- checkEntryContent(entryLF, CONTENT_LF, CONTENT_LF);
- checkEntryContent(entryMixed, CONTENT_LF, CONTENT_LF);
+ // eol=native is the default!
+ String expected = isDefaultCrLf() ? CONTENT_CRLF : CONTENT_LF;
+ checkEntryContent(entryCRLF, expected, CONTENT_LF);
+ checkEntryContent(entryLF, expected, CONTENT_LF);
+ checkEntryContent(entryMixed, expected, CONTENT_LF);
}
public void checkEntryContent(ActualEntry entry, String fileContent,
@@ -199,9 +177,11 @@ public class EolRepositoryTest extends RepositoryTestCase {
setupGitAndDoHardReset(AutoCRLF.FALSE, null, null, null, "* text=auto");
collectRepositoryState();
assertEquals("text=auto", entryCRLF.attrs);
- checkEntryContent(entryCRLF, CONTENT_LF, CONTENT_LF);
- checkEntryContent(entryLF, CONTENT_LF, CONTENT_LF);
- checkEntryContent(entryMixed, CONTENT_LF, CONTENT_LF);
+ // eol=native is the default!
+ String expected = isDefaultCrLf() ? CONTENT_CRLF : CONTENT_LF;
+ checkEntryContent(entryCRLF, expected, CONTENT_LF);
+ checkEntryContent(entryLF, expected, CONTENT_LF);
+ checkEntryContent(entryMixed, expected, CONTENT_LF);
}
@Test
@@ -250,34 +230,24 @@ public class EolRepositoryTest extends RepositoryTestCase {
@Test
public void test_ConfigEOL_native_windows() throws Exception {
- String origLineSeparator = System.getProperty("line.separator", "\n");
- System.setProperty("line.separator", "\r\n");
- try {
- // for EOL to work, the text attribute must be set
- setupGitAndDoHardReset(null, EOL.NATIVE, "*.txt text", null, null);
- collectRepositoryState();
- assertEquals("text", entryCRLF.attrs);
- checkEntryContent(entryCRLF, CONTENT_LF, CONTENT_LF);
- checkEntryContent(entryLF, CONTENT_LF, CONTENT_LF);
- } finally {
- System.setProperty("line.separator", origLineSeparator);
- }
+ mockSystemReader.setWindows();
+ // for EOL to work, the text attribute must be set
+ setupGitAndDoHardReset(null, EOL.NATIVE, "*.txt text", null, null);
+ collectRepositoryState();
+ assertEquals("text", entryCRLF.attrs);
+ checkEntryContent(entryCRLF, CONTENT_CRLF, CONTENT_LF);
+ checkEntryContent(entryLF, CONTENT_CRLF, CONTENT_LF);
}
@Test
public void test_ConfigEOL_native_xnix() throws Exception {
- String origLineSeparator = System.getProperty("line.separator", "\n");
- System.setProperty("line.separator", "\n");
- try {
- // for EOL to work, the text attribute must be set
- setupGitAndDoHardReset(null, EOL.NATIVE, "*.txt text", null, null);
- collectRepositoryState();
- assertEquals("text", entryCRLF.attrs);
- checkEntryContent(entryCRLF, CONTENT_LF, CONTENT_LF);
- checkEntryContent(entryLF, CONTENT_LF, CONTENT_LF);
- } finally {
- System.setProperty("line.separator", origLineSeparator);
- }
+ mockSystemReader.setUnix();
+ // for EOL to work, the text attribute must be set
+ setupGitAndDoHardReset(null, EOL.NATIVE, "*.txt text", null, null);
+ collectRepositoryState();
+ assertEquals("text", entryCRLF.attrs);
+ checkEntryContent(entryCRLF, CONTENT_LF, CONTENT_LF);
+ checkEntryContent(entryLF, CONTENT_LF, CONTENT_LF);
}
@Test
@@ -297,9 +267,10 @@ public class EolRepositoryTest extends RepositoryTestCase {
setupGitAndDoHardReset(AutoCRLF.FALSE, EOL.NATIVE, "*.txt text", null, null);
collectRepositoryState();
assertEquals("text", entryCRLF.attrs);
- checkEntryContent(entryCRLF, CONTENT_LF, CONTENT_LF);
- checkEntryContent(entryLF, CONTENT_LF, CONTENT_LF);
- checkEntryContent(entryMixed, CONTENT_LF, CONTENT_LF);
+ String expected = isDefaultCrLf() ? CONTENT_CRLF : CONTENT_LF;
+ checkEntryContent(entryCRLF, expected, CONTENT_LF);
+ checkEntryContent(entryLF, expected, CONTENT_LF);
+ checkEntryContent(entryMixed, expected, CONTENT_LF);
}
@Test
@@ -524,9 +495,12 @@ public class EolRepositoryTest extends RepositoryTestCase {
// info overrides all
collectRepositoryState();
assertEquals("text", entryCRLF.attrs);
- checkEntryContent(entryCRLF, CONTENT_LF, CONTENT_LF);
- checkEntryContent(entryLF, CONTENT_LF, CONTENT_LF);
- checkEntryContent(entryMixed, CONTENT_LF, CONTENT_LF);
+ // !eol means unspecified, so use the default of core.eol, which is
+ // native.
+ String expected = isDefaultCrLf() ? CONTENT_CRLF : CONTENT_LF;
+ checkEntryContent(entryCRLF, expected, CONTENT_LF);
+ checkEntryContent(entryLF, expected, CONTENT_LF);
+ checkEntryContent(entryMixed, expected, CONTENT_LF);
}
@Test