• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

skuzzle / snapshot-tests / 1

12 Feb 2025 03:38PM UTC coverage: 86.61% (+0.03%) from 86.577%
1

Pull #109

jenkins

skuzzle
Remove old file after merge
Pull Request #109: 2.0 dev

1947 of 2248 relevant lines covered (86.61%)

0.87 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

79.45
/../diff-tool/src/main/java/de/skuzzle/difftool/GitLineSeparator.java
1
package de.skuzzle.difftool;
2

3
import java.util.Arrays;
4
import java.util.Locale;
5
import java.util.Objects;
6
import java.util.regex.Pattern;
7
import java.util.stream.Collectors;
8

9
final class GitLineSeparator {
10

11
    private static final boolean gitEolDebugging;
12
    static {
13
        gitEolDebugging = System.getProperties().keySet().stream().map(Object::toString)
1✔
14
                .anyMatch("giteoldebugging"::equalsIgnoreCase);
1✔
15
    }
16

17
    static final LineSeparator GIT_LINE_SEPARATOR = determineGitLineSeparator(GitConfig.DEFAULT);
1✔
18

19
    static LineSeparator determineGitLineSeparator(GitConfig gitConfig) {
20
        final String autocrlf = gitConfig.autocrlf();
1✔
21
        if (autocrlf == null) {
1✔
22
            return LineSeparator.SYSTEM;
1✔
23
        }
24
        switch (autocrlf.toLowerCase(Locale.ROOT)) {
1✔
25
        case "true":
26
            return LineSeparator.CRLF;
1✔
27
        case "input":
28
            return LineSeparator.LF;
1✔
29
        case "false":
30
            final String eol = gitConfig.eol();
1✔
31
            if (eol == null) {
1✔
32
                return LineSeparator.SYSTEM;
×
33
            }
34
            switch (eol.toLowerCase(Locale.ROOT)) {
1✔
35
            case "crlf":
36
                return LineSeparator.CRLF;
1✔
37
            case "lf":
38
                return LineSeparator.LF;
1✔
39
            case "native":
40
            default:
41
                return LineSeparator.SYSTEM;
1✔
42
            }
43
        }
44
        return LineSeparator.SYSTEM;
1✔
45
    }
46

47
    static class GitConfig {
48

49
        static final GitConfig DEFAULT = new GitConfig();
1✔
50

51
        private final String fileParameter;
52

53
        GitConfig() {
54
            this(null);
1✔
55
        }
1✔
56

57
        // Used for testing
58
        GitConfig(String fileParameter) {
1✔
59
            this.fileParameter = fileParameter;
1✔
60
        }
1✔
61

62
        String autocrlf() {
63
            final String gitConfigCommand = makeCommand("git", "config", fileParameter, "core.autocrlf");
1✔
64
            return execute(gitConfigCommand);
1✔
65
        }
66

67
        void setAutoCrlf(String value) {
68
            final String gitConfigCommand = makeCommand("git config", fileParameter, "core.autocrlf", value);
1✔
69
            execute(gitConfigCommand);
1✔
70
        }
1✔
71

72
        String eol() {
73
            final String gitConfigCommand = makeCommand("git", "config", fileParameter, "core.eol");
×
74
            return execute(gitConfigCommand);
×
75
        }
76

77
        private String makeCommand(String... parts) {
78
            return Arrays.stream(parts).filter(Objects::nonNull).collect(Collectors.joining(" "));
1✔
79
        }
80

81
        private String execute(String command) {
82
            final GitCallResult result = executeInternal(command);
1✔
83
            if (gitEolDebugging) {
1✔
84
                System.err.println("GitEolDebugging:");
×
85
                System.err.println(result);
×
86
            }
87
            return result.result();
1✔
88
        }
89

90
        private static GitCallResult executeInternal(String command) {
91
            String systemErr = "<empty>";
1✔
92
            String systemOut = "<empty>";
1✔
93
            int exitCode = 0;
1✔
94
            Exception exception = null;
1✔
95
            try {
96
                final Process exec = Runtime.getRuntime().exec(command);
1✔
97
                exec.waitFor();
1✔
98
                try (var err = exec.getErrorStream()) {
1✔
99
                    final String output = new String(err.readAllBytes());
1✔
100
                    systemErr = output.isEmpty() ? systemErr : output;
1✔
101
                }
102
                exitCode = exec.exitValue();
1✔
103
                try (var in = exec.getInputStream()) {
1✔
104
                    final String output = new String(in.readAllBytes());
1✔
105
                    systemOut = output.isEmpty() ? systemOut : output;
1✔
106

107
                }
108
            } catch (Exception e) {
×
109
                exception = e;
×
110
            }
1✔
111
            return new GitCallResult(command, exitCode, systemOut, systemErr, exception);
1✔
112
        }
113

114
        private static final class GitCallResult {
115

116
            private final String command;
117
            private final int exitCode;
118
            private final String systemOut;
119
            private final String systemErr;
120
            private final Exception exception;
121

122
            private GitCallResult(String command, int exitCode, String systemOut, String systemErr,
123
                    Exception exception) {
1✔
124
                this.command = command;
1✔
125
                this.exitCode = exitCode;
1✔
126
                this.systemOut = trimWhitespaces(systemOut);
1✔
127
                this.systemErr = trimWhitespaces(systemErr);
1✔
128
                this.exception = exception;
1✔
129
            }
1✔
130

131
            private static final Pattern WHITESPACES = Pattern.compile("\\s+");
1✔
132

133
            private static String trimWhitespaces(String s) {
134
                return WHITESPACES.matcher(s).replaceAll("");
1✔
135
            }
136

137
            public String result() {
138
                if (exitCode != 0 || exception != null) {
1✔
139
                    return null;
1✔
140
                }
141
                return systemOut;
1✔
142
            }
143

144
            @Override
145
            public String toString() {
146
                final StringBuilder b = new StringBuilder();
×
147
                b.append("Result of '").append(command).append("': ").append(exitCode).append(System.lineSeparator())
×
148
                        .append("Error Output: ").append(systemErr).append(System.lineSeparator())
×
149
                        .append("System Output: ").append(systemOut).append(System.lineSeparator());
×
150
                if (exception == null) {
×
151
                    b.append("Exception: <none>");
×
152
                } else {
153
                    b.append("Exception: ").append(exception.getMessage());
×
154
                }
155
                return b.toString();
×
156
            }
157
        }
158
    }
159

160
    private GitLineSeparator() {
161
        // hidden
162
    }
163
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc