tests: Add a gjs-based test

This covers introspection, and in general is a much better way to get
API coverage tests.
This commit is contained in:
Colin Walters 2013-09-18 12:01:46 -04:00
parent 0818a462c2
commit 58a8d6d6ef
3 changed files with 60 additions and 0 deletions

View File

@ -47,7 +47,19 @@ insttest_DATA = tests/archive-test.sh \
echo 'Output=TAP' >> $@.tmp; \
mv $@.tmp $@)
%.test: tests/%.js Makefile
$(AM_V_GEN) (echo '[Test]' > $@.tmp; \
echo 'Exec=$(pkglibexecdir)/installed-tests/$(notdir $<)' >> $@.tmp; \
echo 'Type=session' >> $@.tmp; \
mv $@.tmp $@)
testmetadir = $(datadir)/installed-tests/$(PACKAGE)
testmeta_DATA = $(testfiles:=.test)
if BUILDOPT_GJS
insttest_SCRIPTS += tests/test-core.js
testmeta_DATA += test-core.test
endif
endif

View File

@ -128,6 +128,15 @@ AS_IF([test "x$with_dracut" = "xyes"], [
])
])
dnl for tests
AC_PATH_PROG(GJS, [gjs])
if test -n "$GJS"; then
have_gjs=yes
else
have_gjs=no
fi
AM_CONDITIONAL(BUILDOPT_GJS, test x$have_gjs = xyes)
AC_CONFIG_FILES([
Makefile
embedded-dependencies/Makefile
@ -146,6 +155,7 @@ echo "
libsoup (retrieve remote HTTP repositories): $with_soup
libarchive (parse tar files directly): $with_libarchive
documentation: $enable_gtk_doc
gjs-based tests: $have_gjs
dracut: $with_dracut"
AS_IF([test "x$with_dracut" = "xyes"], [
echo " systemd unit dir: $with_systemdsystemunitdir"

38
tests/test-core.js Normal file
View File

@ -0,0 +1,38 @@
#!/usr/bin/env gjs
const Gio = imports.gi.Gio;
const OSTree = imports.gi.OSTree;
function assertEquals(a, b) {
if (a != b)
throw new Error("assertion failed " + JSON.stringify(a) + " == " + JSON.stringify(b));
}
let testDataDir = Gio.File.new_for_path('test-data');
testDataDir.make_directory(null);
testDataDir.get_child('some-file').replace_contents("hello world!", null, false, 0, null);
let repoPath = Gio.File.new_for_path('repo');
let repo = OSTree.Repo.new(repoPath);
repo.create(OSTree.RepoMode.ARCHIVE_Z2, null);
repo.open(null);
assertEquals(repo.get_mode(), OSTree.RepoMode.ARCHIVE_Z2);
repo.prepare_transaction(null);
let mtree = OSTree.MutableTree.new();
repo.write_directory_to_mtree(testDataDir, mtree, null, null);
let [,dirTree] = repo.write_mtree(mtree, null);
let [,commit] = repo.write_commit(null, 'Some subject', 'Some body', null, dirTree, null);
print("commit => " + commit);
repo.commit_transaction(null, null);
let [,root,checksum] = repo.read_commit(commit, null);
let child = root.get_child('some-file');
let info = child.query_info("standard::name,standard::type,standard::size", 0, null);
assertEquals(info.get_size(), 12);
print("test-core complete");