-
Notifications
You must be signed in to change notification settings - Fork 17
Handle cross-platform shell execution and adapt test utilities accordingly #2226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,7 @@ | ||
| package com.virtuslab.gitmachete.backend.integration; | ||
|
|
||
| import static com.virtuslab.gitmachete.backend.api.SyncToRemoteStatus.AheadOfRemote; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wow weird that these imports weren't removed, despite Lemme open an issue for fixing that - #2228 |
||
| import static com.virtuslab.gitmachete.backend.api.SyncToRemoteStatus.BehindRemote; | ||
| import static com.virtuslab.gitmachete.backend.api.SyncToRemoteStatus.DivergedFromAndNewerThanRemote; | ||
| import static com.virtuslab.gitmachete.backend.api.SyncToRemoteStatus.DivergedFromAndOlderThanRemote; | ||
| import static com.virtuslab.gitmachete.backend.api.SyncToRemoteStatus.InSyncToRemote; | ||
| import static com.virtuslab.gitmachete.backend.api.SyncToRemoteStatus.NoRemotes; | ||
| import static com.virtuslab.gitmachete.backend.api.SyncToRemoteStatus.Untracked; | ||
| import static com.virtuslab.gitmachete.testcommon.SetupScripts.ALL_SETUP_SCRIPTS; | ||
| import static com.virtuslab.gitmachete.testcommon.TestFileUtils.cleanUpDir; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,6 @@ import com.intellij.ide.starter.driver.engine.BackgroundRun | |
| import com.intellij.ide.starter.driver.engine.runIdeWithDriver | ||
| import com.intellij.ide.starter.ide.IdeProductProvider | ||
| import com.intellij.ide.starter.models.TestCase | ||
| import com.intellij.ide.starter.plugins.PluginConfigurator | ||
| import com.intellij.ide.starter.project.ProjectInfoSpec | ||
| import com.intellij.ide.starter.runner.Starter | ||
| import com.intellij.remoterobot.RemoteRobot | ||
|
|
@@ -28,6 +27,7 @@ import java.io.File | |
| import java.nio.file.Files | ||
| import java.nio.file.Path | ||
| import java.nio.file.attribute.PosixFilePermission.* | ||
| import java.util.Locale.getDefault | ||
| import kotlin.time.Duration.Companion.minutes | ||
|
|
||
| abstract class BaseUITestSuite : TestGitRepository(SetupScripts.SETUP_WITH_SINGLE_REMOTE) { | ||
|
|
@@ -256,6 +256,9 @@ abstract class BaseUITestSuite : TestGitRepository(SetupScripts.SETUP_WITH_SINGL | |
| rootDirectoryPath.resolve("machete-post-slide-out-hook-executed") | ||
|
|
||
| fun Path.makeExecutable() { | ||
| if (System.getProperty("os.name").lowercase(getDefault()).contains("windows")) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's extract this to some shared place in testCommon |
||
| return | ||
| } | ||
| val attributes = Files.getPosixFilePermissions(this) | ||
| attributes.add(OWNER_EXECUTE) | ||
| attributes.add(GROUP_EXECUTE) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,10 @@ | ||
| package com.virtuslab.gitmachete.testcommon; | ||
|
|
||
| import static com.virtuslab.gitmachete.testcommon.TestProcessUtils.runProcessAndReturnStdout; | ||
|
|
||
| import java.io.File; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.Paths; | ||
| import java.nio.file.StandardCopyOption; | ||
| import java.util.Comparator; | ||
|
|
||
|
|
@@ -23,9 +22,33 @@ public static void copyScriptFromResources(String scriptName, Path targetDir) { | |
| StandardCopyOption.REPLACE_EXISTING); | ||
| } | ||
|
|
||
| @SneakyThrows | ||
| public static String runProcessAndReturnStdout(int timeoutSeconds, String... command) { | ||
| Path currentDir = Paths.get(".").toAbsolutePath().normalize(); | ||
| return TestProcessUtils.runProcessAndReturnStdout(currentDir, timeoutSeconds, command); | ||
| } | ||
|
|
||
| public static String getShellExecutable() { | ||
| String shell = "bash"; | ||
| String osName = System.getProperty("os.name").toLowerCase(); | ||
| if (osName.contains("windows")) { | ||
| String gitPath = runProcessAndReturnStdout(5, "where", "git").trim().split(System.lineSeparator())[0]; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can it just be |
||
| if (gitPath.endsWith("cmd\\git.exe")) { | ||
| shell = gitPath.replace("cmd\\git.exe", "bin\\sh.exe"); | ||
| } else if (gitPath.endsWith("bin\\git.exe")) { | ||
| shell = gitPath.replace("bin\\git.exe", "bin\\sh.exe"); | ||
| } else { | ||
| shell = "sh"; // fall back to PATH | ||
| } | ||
| } | ||
| return shell; | ||
| } | ||
|
|
||
| @SneakyThrows | ||
| public static void prepareRepoFromScript(String scriptName, Path workingDir) { | ||
| runProcessAndReturnStdout(/* workingDirectory */ workingDir, /* timeoutSeconds */ 60, | ||
| /* command */ "bash", workingDir.resolve(scriptName).toString()); | ||
| String shell = getShellExecutable(); | ||
| String scriptPath = workingDir.resolve(scriptName).toString(); | ||
| TestProcessUtils.runProcessAndReturnStdout(/* workingDirectory */ workingDir, /* timeoutSeconds */ 60, shell, scriptPath); | ||
| } | ||
|
|
||
| @SneakyThrows | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,16 +20,16 @@ public static String runProcessAndReturnStdout(Path workingDirectory, int timeou | |
| Process process = new ProcessBuilder() | ||
| .command(command) | ||
| .directory(workingDirectory.toFile()) | ||
| .redirectErrorStream(true) | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On Windows, the OS pipe buffer for process output is limited. In the original implementation, the Java process called |
||
| .start(); | ||
| boolean completed = process.waitFor(timeoutSeconds, TimeUnit.SECONDS); | ||
|
|
||
| String stdout = IOUtils.toString(process.getInputStream(), StandardCharsets.UTF_8); | ||
| String stderr = IOUtils.toString(process.getErrorStream(), StandardCharsets.UTF_8); | ||
| boolean completed = process.waitFor(timeoutSeconds, TimeUnit.SECONDS); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm now that |
||
|
|
||
| String commandRepr = Arrays.toString(command); | ||
| String NL = System.lineSeparator(); | ||
| String stdoutMessage = "Stdout of " + commandRepr + ": " + NL + stdout; | ||
| String stderrMessage = "Stderr of " + commandRepr + ": " + NL + stderr; | ||
| String joinedMessage = NL + NL + stdoutMessage + NL + stderrMessage + NL; | ||
| String joinedMessage = NL + NL + stdoutMessage + NL; | ||
|
|
||
| assertTrue( | ||
| completed, "command " + commandRepr + " has not completed within " + timeoutSeconds + " seconds" + joinedMessage); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,12 +43,10 @@ function create_repo() { | |
| cd $dir || exit 1 | ||
| shift | ||
| git init "$@" | ||
| if [[ "$(uname -s)" != *MINGW*_NT* ]]; then | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤔 not needed anymore? |
||
| mkdir -p .git/hooks/ | ||
| local hook_path=.git/hooks/machete-status-branch | ||
| echo "$status_branch_hook" > $hook_path | ||
| chmod +x $hook_path | ||
| fi | ||
| mkdir -p .git/hooks/ | ||
| local hook_path=.git/hooks/machete-status-branch | ||
| echo "$status_branch_hook" > $hook_path | ||
| chmod +x $hook_path | ||
| # `--local` (per-repository) is the default when writing git config... let's put it here for clarity anyway. | ||
| git config --local user.email "circleci@example.com" | ||
| git config --local user.name "CircleCI" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests in this class were failing before on Windows. Now they pass. 🟢