Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
# Script to copy required files to /var/tmp/opt/core/
set -e # Exit immediately if a command exits with a non-zero status
set -u # Treat unset variables as an error
TARGET_DIR=/var/tmp/opt/core
TARGET_DIR="/var/tmp/opt/core"
# Copy SpecificExercise.cfg to target directory
cp -v SpecificExercise.cfg "$TARGET_DIR/"
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.tum.cit.ase.ares.api.phobos;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.IOException;
Expand Down Expand Up @@ -47,6 +48,24 @@ void missingBaseAndRuntimeDependenciesUseDocumentedFailClosedErrors() throws Exc
assertTrue(missingRuntime.output().contains("PHB-ERUNTIME"));
}

@Test
void copyToolAssignsTargetDirectoryWithAsciiQuotes() throws Exception {
Path copyTool = TEMPLATES.resolve("PhobosCopyTool.sh");
String contents = Files.readString(copyTool, java.nio.charset.StandardCharsets.UTF_8);

assertTrue(contents.contains("TARGET_DIR=\"/var/tmp/opt/core\""),
"PhobosCopyTool.sh must assign TARGET_DIR using ASCII double quotes");
assertFalse(contents.indexOf('“') >= 0 || contents.indexOf('”') >= 0,
"PhobosCopyTool.sh must not contain Unicode curly quotation marks");

ProcessResult syntax = run("bash -n '" + copyTool + "'");
assertEquals(0, syntax.exitCode(), syntax.output());

ProcessResult parsed = run(
"eval \"$(grep -m1 '^TARGET_DIR=' '" + copyTool + "')\"; printf '%s' \"${TARGET_DIR}\"");
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
assertEquals("/var/tmp/opt/core", parsed.output());
}

private ProcessResult run(String script) throws IOException, InterruptedException {
Process process = new ProcessBuilder("bash", "-c", script).redirectErrorStream(true).start();
String output = new String(process.getInputStream().readAllBytes(), java.nio.charset.StandardCharsets.UTF_8);
Expand Down
Loading