Skip to content

Commit 3e78532

Browse files
Added tests for Busybox preprocessing
1 parent e7f3754 commit 3e78532

2 files changed

Lines changed: 59 additions & 4 deletions

File tree

src/main/java/de/variantsync/evolution/repository/BusyboxRepository.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package de.variantsync.evolution.repository;
22

3+
import de.variantsync.evolution.util.Logger;
34
import de.variantsync.evolution.variability.SPLCommit;
45
import org.eclipse.jgit.api.errors.GitAPIException;
56

@@ -15,8 +16,8 @@
1516

1617
/***
1718
* A specialized SPLRepository that performs the necessary preprocessing of BusyBox source files, whenever a new
18-
* commit is checked out. The preprocessing includes splitting of lines into multiple lines in order to deal with
19-
* inline preprocessor macros used to model variability.
19+
* commit or branch is checked out. The preprocessing includes splitting of lines into multiple lines in order to deal
20+
* with inline preprocessor macros used to model variability.
2021
* <br>
2122
* The preprocessing was copied from KernelHaven: net.ssehub.kernel_haven.busyboot.PrepareBusybox;
2223
* Copyright 2018-2019 University of Hildesheim, Software Systems Engineering
@@ -31,14 +32,25 @@ public BusyboxRepository(Path path) {
3132
@Override
3233
public SPLCommit checkoutCommit(final SPLCommit c, boolean forced) throws GitAPIException, IOException {
3334
SPLCommit previousCommit = super.checkoutCommit(c, forced);
34-
BusyboxRepository.normalizeDir(this.getPath().toFile());
35+
this.preprocess();
3536
return previousCommit;
3637
}
3738

3839
@Override
3940
public void checkoutBranch(final Branch branch) throws GitAPIException, IOException {
4041
super.checkoutBranch(branch);
41-
BusyboxRepository.normalizeDir(this.getPath().toFile());
42+
this.preprocess();
43+
}
44+
45+
public void preprocess() throws IOException {
46+
try {
47+
Logger.debug("Normalizing Busybox files.");
48+
BusyboxRepository.normalizeDir(this.getPath().toFile());
49+
Logger.debug("Finished normalization of Busybox files.");
50+
} catch (IOException e) {
51+
Logger.error("Was not able to normalize Busybox files.", e);
52+
throw e;
53+
}
4254
}
4355

4456
/*
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package de.variantsync.evolution.repository;
2+
3+
import de.variantsync.evolution.Main;
4+
import de.variantsync.evolution.util.Logger;
5+
import de.variantsync.evolution.variability.SPLCommit;
6+
import org.eclipse.jgit.api.errors.GitAPIException;
7+
import org.junit.After;
8+
import org.junit.Ignore;
9+
import org.junit.Test;
10+
11+
import java.io.IOException;
12+
import java.nio.file.Path;
13+
14+
// Tests are disabled as they require custom setup. They also do not assert anything and are meant to be used when debugging.
15+
@Ignore
16+
public class BusyboxRepositoryTest {
17+
// Adjust the path to the root of Busybox for testing
18+
private final BusyboxRepository BUSYBOX = new BusyboxRepository(Path.of("C:\\Users\\Alex\\develop\\busybox"));
19+
20+
static {
21+
Main.Initialize();
22+
}
23+
24+
// Clean the repo after each test
25+
@After
26+
public void restoreFiles() throws GitAPIException, IOException {
27+
BUSYBOX.stashCreate(true);
28+
BUSYBOX.dropStash();
29+
}
30+
31+
@Test
32+
public void normalize() throws IOException {
33+
BUSYBOX.preprocess();
34+
}
35+
36+
@Test
37+
public void checkoutCommit() throws GitAPIException, IOException {
38+
SPLCommit simpleCommit = new SPLCommit("f27a6a94a7fb172a6768bc450dbdec68f15bc78f");
39+
SPLCommit previousCommit = BUSYBOX.checkoutCommit(simpleCommit);
40+
BUSYBOX.checkoutCommit(previousCommit, true);
41+
}
42+
43+
}

0 commit comments

Comments
 (0)