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:
parent
0818a462c2
commit
58a8d6d6ef
|
|
@ -47,7 +47,19 @@ insttest_DATA = tests/archive-test.sh \
|
||||||
echo 'Output=TAP' >> $@.tmp; \
|
echo 'Output=TAP' >> $@.tmp; \
|
||||||
mv $@.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)
|
testmetadir = $(datadir)/installed-tests/$(PACKAGE)
|
||||||
testmeta_DATA = $(testfiles:=.test)
|
testmeta_DATA = $(testfiles:=.test)
|
||||||
|
|
||||||
|
if BUILDOPT_GJS
|
||||||
|
insttest_SCRIPTS += tests/test-core.js
|
||||||
|
testmeta_DATA += test-core.test
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|
|
||||||
10
configure.ac
10
configure.ac
|
|
@ -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([
|
AC_CONFIG_FILES([
|
||||||
Makefile
|
Makefile
|
||||||
embedded-dependencies/Makefile
|
embedded-dependencies/Makefile
|
||||||
|
|
@ -146,6 +155,7 @@ echo "
|
||||||
libsoup (retrieve remote HTTP repositories): $with_soup
|
libsoup (retrieve remote HTTP repositories): $with_soup
|
||||||
libarchive (parse tar files directly): $with_libarchive
|
libarchive (parse tar files directly): $with_libarchive
|
||||||
documentation: $enable_gtk_doc
|
documentation: $enable_gtk_doc
|
||||||
|
gjs-based tests: $have_gjs
|
||||||
dracut: $with_dracut"
|
dracut: $with_dracut"
|
||||||
AS_IF([test "x$with_dracut" = "xyes"], [
|
AS_IF([test "x$with_dracut" = "xyes"], [
|
||||||
echo " systemd unit dir: $with_systemdsystemunitdir"
|
echo " systemd unit dir: $with_systemdsystemunitdir"
|
||||||
|
|
|
||||||
|
|
@ -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");
|
||||||
Loading…
Reference in New Issue