Skip to content

Commit

Permalink
feat(qa): add dummy-ex-generator.sh
Browse files Browse the repository at this point in the history
Add script to generate dummy exercises (solutions, tests and subjects) from provided templates
  • Loading branch information
nprimo committed Sep 28, 2022
1 parent d612cec commit 44d2a65
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 0 deletions.
3 changes: 3 additions & 0 deletions scripts/README-template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Subject ${N}

Some random text for subject ${N}
5 changes: 5 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# dummy-ex-generator

A simple script to generate solutions, tests and subjects for dummy exercises from provided templates.
The script will create 3 directories in the working directory to store the dummy exercise solutions, tests and subjects.
It is possible to change the number of exercises created by varying the `N` variable inside the script.
53 changes: 53 additions & 0 deletions scripts/dummy-ex-generator.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash
# File:

N_FILES=10

TEST_DIR='tests'
SUBJECT_DIR='subjects'
SOLUTIONS_DIR='solutions'

TEST_TEMPLTATE='test-template.go'
SUBJECT_TEMPLATE='README-template.md'
SOLUTIONS_TEMPLATE='solution-template.go'

mkdir -p $TEST_DIR
mkdir -p $SUBJECT_DIR
mkdir -p $SOLUTIONS_DIR

fill_subjects() {
TEMPLATE=$1
OUTDIR=$2
for N in $(seq 1 $N_FILES)
do
DIR="dummy$N"
mkdir -p $OUTDIR/$DIR
cat $TEMPLATE | sed "s|\${N}|$N|g" > "./$OUTDIR/$DIR/README.md"
done
}

fill_solutions() {
TEMPLATE=$1
OUTDIR=$2
for N in $(seq 1 $N_FILES)
do
DIR="dummy$N"
mkdir -p $OUTDIR/$DIR
cat $TEMPLATE | sed "s|\${N}|$N|g" > "./$OUTDIR/$DIR/main.go"
done
}

fill_test() {
TEMPLATE=$1
OUTDIR=$2
for N in $(seq 1 $N_FILES)
do
DIR="dummy$N""_test"
mkdir -p $OUTDIR/$DIR
cat $TEMPLATE | sed "s|\${N}|$N|g" > "./$OUTDIR/$DIR/main.go"
done
}

fill_test $TEST_TEMPLTATE $TEST_DIR
fill_subjects $SUBJECT_TEMPLATE $SUBJECT_DIR
fill_solutions $SOLUTIONS_TEMPLATE $SOLUTIONS_DIR
7 changes: 7 additions & 0 deletions scripts/solution-template.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "fmt"

func main() {
fmt.Println("Hello World ${N}")
}
7 changes: 7 additions & 0 deletions scripts/test-template.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "github.com/01-edu/go-tests-training/lib/challenge"

func main() {
challenge.Program("dummy${N}")
}

0 comments on commit 44d2a65

Please sign in to comment.