Make tests work on Windows

This commit is contained in:
Erik C. Thauvin 2025-03-25 12:48:55 -07:00
parent 8ba37725ce
commit 07e2daff34
Signed by: erik
GPG key ID: 776702A6A2DA330E

View file

@ -17,6 +17,8 @@
package rife.bld.extension; package rife.bld.extension;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.OS;
import rife.bld.BaseProject; import rife.bld.BaseProject;
import rife.bld.Project; import rife.bld.Project;
import rife.bld.WebProject; import rife.bld.WebProject;
@ -24,6 +26,7 @@ import rife.bld.operations.exceptions.ExitStatusException;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;
import java.util.Locale;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode; import static org.assertj.core.api.Assertions.assertThatCode;
@ -31,6 +34,8 @@ import static org.assertj.core.api.Assertions.assertThatCode;
class ExecOperationTest { class ExecOperationTest {
private static final String FOO = "foo"; private static final String FOO = "foo";
private static final boolean IS_WINDOWS = System.getProperty("os.name").toLowerCase(Locale.US).contains("win");
private static final String CAT = IS_WINDOWS ? "type" : "cat";
@Test @Test
void testCommand() { void testCommand() {
@ -53,7 +58,7 @@ class ExecOperationTest {
assertThatCode(() -> assertThatCode(() ->
new ExecOperation() new ExecOperation()
.fromProject(new BaseProject()) .fromProject(new BaseProject())
.command(List.of("cat", FOO)) .command(List.of(CAT, FOO))
.execute()).isInstanceOf(ExitStatusException.class); .execute()).isInstanceOf(ExitStatusException.class);
} }
@ -61,7 +66,7 @@ class ExecOperationTest {
void testFailOnExit() { void testFailOnExit() {
var op = new ExecOperation() var op = new ExecOperation()
.fromProject(new BaseProject()) .fromProject(new BaseProject())
.command(List.of("cat", FOO)) .command(List.of(CAT, FOO))
.failOnExit(false); .failOnExit(false);
assertThat(op.isFailOnExit()).isFalse(); assertThat(op.isFailOnExit()).isFalse();
assertThatCode(op::execute).doesNotThrowAnyException(); assertThatCode(op::execute).doesNotThrowAnyException();
@ -72,15 +77,22 @@ class ExecOperationTest {
@Test @Test
void testTimeout() { void testTimeout() {
List<String> sleep;
if (IS_WINDOWS) {
sleep = List.of("timeout", "/t", "10");
} else {
sleep = List.of("sleep", "10");
}
var op = new ExecOperation() var op = new ExecOperation()
.fromProject(new BaseProject()) .fromProject(new BaseProject())
.timeout(5) .timeout(5)
.command(List.of("sleep", "10")); .command(sleep);
assertThat(op.timeout()).isEqualTo(5); assertThat(op.timeout()).isEqualTo(5);
assertThatCode(op::execute).isInstanceOf(ExitStatusException.class); assertThatCode(op::execute).isInstanceOf(ExitStatusException.class);
} }
@Test @Test
@EnabledOnOs({OS.LINUX, OS.MAC})
void testTouch() throws Exception { void testTouch() throws Exception {
var tmpFile = new File("hello.tmp"); var tmpFile = new File("hello.tmp");
tmpFile.deleteOnExit(); tmpFile.deleteOnExit();