-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateTestCases.sh
More file actions
executable file
·45 lines (36 loc) · 1.35 KB
/
Copy pathcreateTestCases.sh
File metadata and controls
executable file
·45 lines (36 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/zsh
resourcesFolder="src/test/resources"
testFolder="src/test/java/de/unituebingen/compilerbau"
templateFile="TestTemplate.java"
copyFileToTestFolder () {
mockFilePath=$1
fileName=Test${mockFilePath##*/Mock}
folder=${${mockFilePath#${resourcesFolder}"/"}%/*}
destinationPath=${testFolder}/${folder}/${fileName}
# create folder if not exist
mkdir -p ${testFolder}/${folder}
# copy template file to destination (Only if it doesnt already exist!)
if [ ! -f "${destinationPath}" ];
then
echo "Creating: ${destinationPath}"
else
return;
fi
cp -n "${templateFile}" "${destinationPath}"
# replace placeholder in template file
placeholder="Template"
placeholderFolder="MockFolder"
className=${${fileName#Test}%*.java}
if [[ $OSTYPE == 'darwin'* ]];
then
sed -i '' "s|${placeholder}|${className}|g" "${destinationPath}"
sed -i '' "s|${placeholderFolder}|${folder}|g" "${destinationPath}"
else
sed -i "s|${placeholder}|${className}|g" "${destinationPath}"
sed -i "s|${placeholderFolder}|${folder}|g" "${destinationPath}"
fi
# Insert package name to top of file
packageLine="package de.unituebingen.compilerbau.${folder//[\/]/.};"
echo "${packageLine}\n" | cat - "${destinationPath}" > temp && mv temp "${destinationPath}"
}
for x in "${resourcesFolder}"/**/*.java; do copyFileToTestFolder "$x"; done