Skip to content

Commit 52cb0fa

Browse files
committed
Make MakePlugin more wonderful
Seriously though, this fixes a permission problem that occurs when the project template has an executable and zip packaging messes up the permissions.
1 parent 48ba79d commit 52cb0fa

File tree

22 files changed

+480
-16
lines changed

22 files changed

+480
-16
lines changed

build-tools/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<modelVersion>4.0.0</modelVersion>
33
<groupId>fi.helsinki.cs.tmc</groupId>
44
<artifactId>build-tools</artifactId>
5-
<version>0.7.3-SNAPSHOT</version>
5+
<version>0.7.4-SNAPSHOT</version>
66
<name>build-tools</name>
77

88
<!-- Deploy to maven.testmycode.net/nexus -->

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<groupId>fi.helsinki.cs.tmc</groupId>
55
<artifactId>tmc-langs</artifactId>
6-
<version>0.7.3-SNAPSHOT</version>
6+
<version>0.7.4-SNAPSHOT</version>
77
<packaging>pom</packaging>
88
<name>tmc-langs</name>
99
<url>http://testmycode.net</url>

tmc-langs-cli/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<artifactId>tmc-langs</artifactId>
66
<groupId>fi.helsinki.cs.tmc</groupId>
7-
<version>0.7.3-SNAPSHOT</version>
7+
<version>0.7.4-SNAPSHOT</version>
88
</parent>
99
<modelVersion>4.0.0</modelVersion>
1010

tmc-langs-framework/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>fi.helsinki.cs.tmc</groupId>
66
<artifactId>tmc-langs</artifactId>
7-
<version>0.7.3-SNAPSHOT</version>
7+
<version>0.7.4-SNAPSHOT</version>
88
<relativePath>../</relativePath>
99
</parent>
1010
<properties>

tmc-langs-java/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>fi.helsinki.cs.tmc</groupId>
66
<artifactId>tmc-langs</artifactId>
7-
<version>0.7.3-SNAPSHOT</version>
7+
<version>0.7.4-SNAPSHOT</version>
88
</parent>
99

1010
<properties>

tmc-langs-make/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>fi.helsinki.cs.tmc</groupId>
66
<artifactId>tmc-langs</artifactId>
7-
<version>0.7.3-SNAPSHOT</version>
7+
<version>0.7.4-SNAPSHOT</version>
88
</parent>
99

1010
<properties>

tmc-langs-make/src/main/java/fi/helsinki/cs/tmc/langs/make/MakePlugin.java

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ public final class MakePlugin extends AbstractLanguagePlugin {
5050
private static final String CANT_PARSE_EXERCISE_DESCRIPTION =
5151
"Couldn't parse exercise description.";
5252
private static final String COMPILE_FAILED_MESSAGE = "Failed to compile project.";
53+
private static final String PERMISSION_MITIGATION_MESSAGE =
54+
"Permission problems, cleaning and trying again.";
55+
private static final String PERMISSIONS_FIX_FAILED_MESSAGE = "Fixing permission issues failed.";
56+
private static final String RUNNING_WITHOUT_VALGRIND_MESSAGE =
57+
"Trying to run tests without Valgrind.";
58+
private static final String PERMISSION_PROBLEM_INDICATOR = "Permission denied";
5359

5460
private static final Logger log = LoggerFactory.getLogger(MakePlugin.class);
5561

@@ -166,13 +172,28 @@ public RunResult runTests(Path path) {
166172
try {
167173
runTests(path, withValgrind);
168174
} catch (Exception e) {
169-
withValgrind = false;
170-
171-
try {
172-
runTests(path, withValgrind);
173-
} catch (Exception e1) {
174-
log.error(e1.toString());
175-
throw new RuntimeException(TEST_FAIL_MESSAGE);
175+
// In case the folder has a test binary without the executable bit
176+
if (e.getMessage().contains(PERMISSION_PROBLEM_INDICATOR)) {
177+
log.info(PERMISSION_MITIGATION_MESSAGE);
178+
clean(path);
179+
try {
180+
runTests(path, withValgrind);
181+
} catch (Exception e1) {
182+
log.info(PERMISSIONS_FIX_FAILED_MESSAGE);
183+
withValgrind = false;
184+
}
185+
} else {
186+
withValgrind = false;
187+
}
188+
if (!withValgrind) {
189+
// The system probably doesn't have Valgrind properly installed
190+
log.info(RUNNING_WITHOUT_VALGRIND_MESSAGE);
191+
try {
192+
runTests(path, withValgrind);
193+
} catch (Exception e1) {
194+
log.error(e1.toString());
195+
throw new RuntimeException(TEST_FAIL_MESSAGE);
196+
}
176197
}
177198
}
178199

tmc-langs-make/src/test/java/fi/helsinki/cs/tmc/langs/make/MakePluginTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,4 +246,11 @@ public void isExerciseCorrectTypeDoesIsNotFooledByDirectoryNamedMakefile() throw
246246
Files.delete(make);
247247
Files.delete(parent);
248248
}
249+
250+
@Test
251+
public void testProjectWithUnexecutableArtifacts() {
252+
Path path = TestUtils.getPath(getClass(), "wrong-permissions");
253+
RunResult result = makePlugin.runTests(path);
254+
assertEquals(result.status, RunResult.Status.PASSED);
255+
}
249256
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
MAIN_DIR = src
2+
TEST_DIR = test
3+
4+
.PHONY: main test
5+
6+
all: main test
7+
8+
main:
9+
$(MAKE) -C $(MAIN_DIR)
10+
11+
test:
12+
$(MAKE) -C $(TEST_DIR)
13+
14+
clean:
15+
rm -f tmc_available_points.txt tmc_test_results.xml valgrind.log file_with_exactly_128_bits.txt mockoutput mockinput
16+
$(MAKE) -C $(MAIN_DIR) clean
17+
$(MAKE) -C $(TEST_DIR) clean
18+
19+
run-main:
20+
$(MAKE) -C $(MAIN_DIR) run
21+
22+
run-test:
23+
$(MAKE) -C $(TEST_DIR) run
24+
25+
run-test-with-valgrind:
26+
$(MAKE) -C $(TEST_DIR) run-valgrind
27+
28+
get-points:
29+
$(MAKE) -C $(TEST_DIR) get-points
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
SRC_FILES=main.c source.c
2+
3+
all: main
4+
5+
main: $(SRC_FILES)
6+
gcc -g -Wall -Wextra -pedantic -std=c99 -o $@ $(SRC_FILES) -lm
7+
8+
clean:
9+
rm -f main
10+
11+
run: main
12+
# Running our main function from file main.c
13+
./main

0 commit comments

Comments
 (0)