You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
1014 B

  1. #!/usr/bin/env bash
  2. if test ! -f "project.yml"; then
  3. echo -e "no project.yml was found -> generation failed\nplease run this command from the root of the project directory"
  4. exit 1
  5. fi
  6. if test -z $1; then
  7. echo "no file path was provided -> generation failed"
  8. exit 1
  9. fi
  10. name="$(basename $1)"
  11. mkdir -p "test/$(dirname $1)"
  12. mkdir -p "src/$(dirname $1)"
  13. testcontent="#include \"unity.h\"\n#include \"$1.h\"\n\nvoid setUp(void){}\nvoid tearDown(void){}"
  14. filecontent="#include \"$name.h\""
  15. headercontent="#ifndef ${name^^}_H\n#define ${name^^}_H\n\n\n#endif"
  16. if test -e "test/test_$1.c"; then
  17. echo "the file test/test_$1.c already exists -> generation failed"
  18. exit 1
  19. fi
  20. if test -e "src/$1.c"; then
  21. echo "the file src/$1.c already exists -> generation failed"
  22. exit 1
  23. fi
  24. if test -e "src/$1.h"; then
  25. echo "the file src/$1.h already exists -> generation failed"
  26. exit 1
  27. fi
  28. echo -e $testcontent > "test/test_$1.c"
  29. echo -e $filecontent > "src/$1.c"
  30. echo -e $headercontent > "src/$1.h"