From 44d2a6543712447f9d5b186c6245b3fc1a91e4a5 Mon Sep 17 00:00:00 2001 From: nprimo Date: Wed, 28 Sep 2022 17:02:40 +0100 Subject: [PATCH] feat(qa): add dummy-ex-generator.sh Add script to generate dummy exercises (solutions, tests and subjects) from provided templates --- scripts/README-template.md | 3 ++ scripts/README.md | 5 ++++ scripts/dummy-ex-generator.sh | 53 +++++++++++++++++++++++++++++++++++ scripts/solution-template.go | 7 +++++ scripts/test-template.go | 7 +++++ 5 files changed, 75 insertions(+) create mode 100644 scripts/README-template.md create mode 100644 scripts/README.md create mode 100755 scripts/dummy-ex-generator.sh create mode 100644 scripts/solution-template.go create mode 100644 scripts/test-template.go diff --git a/scripts/README-template.md b/scripts/README-template.md new file mode 100644 index 0000000..f7f6b84 --- /dev/null +++ b/scripts/README-template.md @@ -0,0 +1,3 @@ +# Subject ${N} + +Some random text for subject ${N} diff --git a/scripts/README.md b/scripts/README.md new file mode 100644 index 0000000..7603cb3 --- /dev/null +++ b/scripts/README.md @@ -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. \ No newline at end of file diff --git a/scripts/dummy-ex-generator.sh b/scripts/dummy-ex-generator.sh new file mode 100755 index 0000000..5ce534b --- /dev/null +++ b/scripts/dummy-ex-generator.sh @@ -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 \ No newline at end of file diff --git a/scripts/solution-template.go b/scripts/solution-template.go new file mode 100644 index 0000000..76573b9 --- /dev/null +++ b/scripts/solution-template.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Println("Hello World ${N}") +} \ No newline at end of file diff --git a/scripts/test-template.go b/scripts/test-template.go new file mode 100644 index 0000000..c8b4c66 --- /dev/null +++ b/scripts/test-template.go @@ -0,0 +1,7 @@ +package main + +import "github.com/01-edu/go-tests-training/lib/challenge" + +func main() { + challenge.Program("dummy${N}") +}