source: ProjectBuilder/devel/pb-modules/t/YAML.t@ 2607

Last change on this file since 2607 was 2607, checked in by Bruno Cornec, 4 years ago

Fix YAML pb_Dump function, adds a test for embedded YAML, export PBCONFVER from Version and fix sles 10 sudoers

File size: 1.7 KB
Line 
1#!/usr/bin/perl -w
2#
3# Tests ProjectBuilder::YAML functions
4
5use strict;
6use Data::Dumper;
7use ProjectBuilder::Base;
8use ProjectBuilder::YAML;
9
10my $res;
11eval
12{
13 require Test::More;
14 Test::More->import();
15 $res = $@;
16 my ($tmv,$tmsv) = split(/\./,$Test::More::VERSION);
17 if ($tmsv lt 87) {
18 die "Test::More is not available in an appropriate version ($tmsv)";
19 }
20};
21
22# Test appropriate version not found so no test will be performed here
23if ($res) {
24 require Test;
25 Test->import();
26 plan(tests => 1);
27 print "# Faking tests as Test::More is not available in an appropriate version\n";
28 ok(1,1);
29 exit(0);
30}
31
32my $nt = 0;
33
34$ENV{'TMPDIR'} = "/tmp";
35pb_temp_init();
36open(FILE,"> $ENV{'TMPDIR'}/conf1.yml") || die "Unable to create $ENV{'TMPDIR'}/conf1.yml";
37print FILE "---\n";
38print FILE "colon:\n";
39print FILE " mageia-3-x86_64: 'ex: test'\n";
40print FILE "percent:\n";
41print FILE " mageia-3-x86_64: '%check'\n";
42print FILE "truc:\n";
43print FILE " mageia-4-x86_64: 'la tete a toto'\n";
44print FILE "yorro:\n";
45print FILE " mageia-3-x86_64: tartampion\n";
46print FILE "zz:\n";
47print FILE " mageia-3-x86_64: ''\n";
48close(FILE);
49
50my $tab1 = pb_LoadFile("$ENV{'TMPDIR'}/conf1.yml");
51open(FILE,"> $ENV{'TMPDIR'}/conf1bis.yml") || die "Unable to create $ENV{'TMPDIR'}/conf1bis.yml";
52print FILE Dumper($tab1);
53close(FILE);
54my $cnt = pb_get_content("$ENV{'TMPDIR'}/conf1.yml");
55my $tab2 = pb_Dump($tab1);
56open(FILE,"> $ENV{'TMPDIR'}/test1bis.yml") || die "Unable to create $ENV{'TMPDIR'}/test1bis.yml";
57print FILE Dumper($tab2);
58close(FILE);
59open(FILE,"> $ENV{'TMPDIR'}/test1.yml") || die "Unable to create $ENV{'TMPDIR'}/test1.yml";
60print FILE "$tab2";
61close(FILE);
62my $content = pb_get_content("$ENV{'TMPDIR'}/test1.yml");
63is($cnt, $content, "pb_DumpFile Test");
64$nt++;
65
66done_testing($nt);
Note: See TracBrowser for help on using the repository browser.