1

I'm trying to learn to make applications with vala, and i'm fond of test driven developpement. But i can't find any example of real tested code in vala, envelope has one Unit Test, but i don't manage to adapt it in other projects.

here's my tests directory's Cmake file :

pkg_check_modules(DEPS REQUIRED
  granite>=0.3
  gtksourceview-3.0>=3.10
  gthread-2.0
  gtk+-3.0>=3.9.10
)

set (PKG_DEPS
 granite>=0.3
 gee-0.8
 gtksourceview-3.0
 gtk+-3.0
 webkit2gtk-4.0
 discount
)

set (VALA_DEPS
 granite
 gee-0.8
 gtksourceview-3.0
 gtk+-3.0
 webkit2gtk-4.0
 discount
)


find_package(Vala REQUIRED)

include(ValaVersion)
ensure_vala_version("0.23.2" MINIMUM)

include(ValaPrecompile)
enable_testing ()

add_definitions(${DEPS_CFLAGS})
add_definitions ("-DGETTEXT_PACKAGE=\"${GETTEXT_PACKAGE}\"")
add_definitions (${CC_OPTS})

link_libraries(${DEPS_LIBRARIES})
link_directories(${DEPS_LIBRARY_DIRS})

set (LIBS ${LIBS} enotes-clib)
set (EXEC_NAME_TESTS "enotes-tests")

vala_precompile(VALA_C_TEST ${EXEC_NAME_TESTS}
  ../src/Main.vala
  ../src/Application.vala
  ../src/Widgets/Editor.vala
  ../src/Widgets/Headerbar.vala
  ../src/Widgets/ViewEditStack.vala
  ../src/Widgets/NewNotebookDialog.vala
  ../src/Widgets/PreferencesDialog.vala
  ../src/Widgets/NotebookItem.vala
  ../src/Widgets/BookmarkItem.vala
  ../src/Widgets/TrashItem.vala
  ../src/Widgets/BookmarkButton.vala
  ../src/Widgets/PageItem.vala
  ../src/Widgets/PagesList.vala
  ../src/Widgets/Sidebar.vala
  ../src/Widgets/SidebarItem.vala
  ../src/Widgets/Viewer.vala
  ../src/Widgets/Window.vala
  ../src/Styles/air.vala
  ../src/Styles/elementary.vala
  ../src/Styles/modest.vala
  ../src/Services/Bookmark.vala
  ../src/Services/FileManager.vala
  ../src/Services/Notebook.vala
  ../src/Services/Page.vala
  ../src/Services/Settings.vala
  ../src/Services/Trash.vala
  ../src/config.vala

  FileManagerTest.vala
PACKAGES
  ${VALA_DEPS}
OPTIONS
  ${GLOBAL_VALAC_OPTIONS}
 -g
  --vapidir=${CMAKE_SOURCE_DIR}/vapi
  --thread
  --target-glib=2.38 # FIXME check before, and target the same version
)


add_executable(${EXEC_NAME_TESTS} ${VALA_C_TEST})
add_test (${EXEC_NAME_TESTS} ${CMAKE_CURRENT_BINARY_DIR}/enotes-tests)

# copy test data
file(COPY data DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

I obtain an error on add_executable() function :

tests/CMakeFiles/enotes-tests.dir/build.make:912: avertissement : surchargement de la recette pour la cible « tests/enotes-tests »
tests/CMakeFiles/enotes-tests.dir/build.make:89: avertissement : ancienne recette ignorée pour la cible « tests/enotes-tests »
make[2]: ***  Aucune règle pour fabriquer la cible « ../tests/enotes-tests », nécessaire pour « tests/enotes-tests ». Arrêt.
CMakeFiles/Makefile2:265 : la recette pour la cible « tests/CMakeFiles/enotes-tests.dir/all » a échouée
make[1]: *** [tests/CMakeFiles/enotes-tests.dir/all] Erreur 2
Makefile:127 : la recette pour la cible « all » a échouée
make: *** [all] Erreur 2

Besides, envelope is an unmaintained code, i'm wondering how elementary envisions unit testing nowadays. Some people have taken the topic, but unfortunately, i'm a vala beginner, i can't follow their steps :

http://chrisdaley.biz/test-driven-development-in-vala-pt-6.html#test-driven-development-in-vala-pt-6

EDIT : i'm not talking about writing a CmakeList file for my application, but writing a CmakeList file for tests/ directory. One of the tricky part is dealing with two main() functions.

If you have any lead on how to write cmake file for unit testing in vala the right way, i'll be very thankful.

1

I should suggest to you to take a look at the elementary OS webpage, at Developer Section:

Getting Started

You can find there how to get cmake modules to elementary-os development and how to write CMakeList files.

  • thanks, i've already made this tutorial, but nothing there talks about unit testing, and Cmake for the tests/ directory. – FXGhost Sep 9 '16 at 6:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.