Skip to content

Commit

Permalink
#1061: fixed test and cover all OS (red/green pattern) (#1062)
Browse files Browse the repository at this point in the history
  • Loading branch information
hohwille authored Feb 21, 2025
1 parent a0f0396 commit f164fda
Showing 1 changed file with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
import java.nio.file.Path;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import com.devonfw.tools.ide.context.AbstractIdeContextTest;
import com.devonfw.tools.ide.context.IdeTestContext;
import com.devonfw.tools.ide.os.SystemInfo;
import com.devonfw.tools.ide.os.SystemInfoMock;
import com.devonfw.tools.ide.os.WindowsHelper;
import com.devonfw.tools.ide.os.WindowsPathSyntax;
Expand All @@ -32,20 +35,27 @@ public void testRemoveObsoleteEntryFromWindowsPath() {
}

/** Test of {@link IdeasyCommandlet#installIdeasy(Path)}. */
@Test
public void testInstallIdeasy() {
@ParameterizedTest
@ValueSource(strings = { "windows", "mac", "linux" })
public void testInstallIdeasy(String os) {

// arrange
SystemInfo systemInfo = SystemInfoMock.of(os);
IdeTestContext context = newContext("install");
context.setIdeRoot(null);
context.setSystemInfo(SystemInfoMock.WINDOWS_X64);
context.setSystemInfo(systemInfo);
context.getStartContext().setForceMode(true);
WindowsHelper helper = context.getWindowsHelper();
String originalPath = helper.getUserEnvironmentValue("PATH");
helper.setUserEnvironmentValue("PATH", "C:\\projects\\_ide\\bin;" + originalPath);
if (systemInfo.isWindows()) {
helper.setUserEnvironmentValue("PATH", "C:\\projects\\_ide\\bin;" + originalPath);
}
Path ideRoot = context.getUserHome().resolve("projects");
String addedRcLines = "export IDE_ROOT=\"" + WindowsPathSyntax.MSYS.format(ideRoot) + "\"\n"
+ "source \"$IDE_ROOT/_ide/installation/functions\"\n";
String addedRcLines =
"source \"$IDE_ROOT/_ide/installation/functions\"\n";
if (!systemInfo.isWindows()) {
addedRcLines = "export IDE_ROOT=\"" + WindowsPathSyntax.MSYS.format(ideRoot) + "\"\n" + addedRcLines;
}
Path idePath = ideRoot.resolve("_ide");
Path installationPath = idePath.resolve("installation");
Path releasePath = idePath.resolve("software/maven/ideasy/ideasy/SNAPSHOT");
Expand All @@ -55,8 +65,10 @@ public void testInstallIdeasy() {
// assert
verifyInstallation(installationPath);
verifyInstallation(releasePath);
assertThat(helper.getUserEnvironmentValue("IDE_ROOT")).isEqualTo(ideRoot.toString());
assertThat(helper.getUserEnvironmentValue("PATH")).isEqualTo(originalPath + ";" + context.getUserHome().resolve("projects/_ide/installation/bin"));
if (systemInfo.isWindows()) {
assertThat(helper.getUserEnvironmentValue("IDE_ROOT")).isEqualTo(ideRoot.toString());
assertThat(helper.getUserEnvironmentValue("PATH")).isEqualTo(originalPath + ";" + context.getUserHome().resolve("projects/_ide/installation/bin"));
}
assertThat(context.getUserHome().resolve(".bashrc")).hasContent(addedRcLines);
assertThat(context.getUserHome().resolve(".zshrc")).hasContent("#already exists\n"
+ "autoload -U +X bashcompinit && bashcompinit\n"
Expand Down

0 comments on commit f164fda

Please sign in to comment.