Fix build procedure.
[morzhol.git] / test / test.adb
blob47e83bb4b94be9678b77b73dd537a266e8812434
1 ------------------------------------------------------------------------------
2 -- Morzhol --
3 -- --
4 -- Copyright (C) 2007 --
5 -- Pascal Obry - Olivier Ramonat --
6 -- --
7 -- This library is free software; you can redistribute it and/or modify --
8 -- it under the terms of the GNU General Public License as published by --
9 -- the Free Software Foundation; either version 2 of the License, or (at --
10 -- your option) any later version. --
11 -- --
12 -- This library is distributed in the hope that it will be useful, but --
13 -- WITHOUT ANY WARRANTY; without even the implied warranty of --
14 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
15 -- General Public License for more details. --
16 -- --
17 -- You should have received a copy of the GNU General Public License --
18 -- along with this library; if not, write to the Free Software Foundation, --
19 -- Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. --
20 ------------------------------------------------------------------------------
22 with Ada.Command_Line;
23 with Ada.Directories;
24 with Ada.Exceptions;
25 with Ada.Strings.Unbounded;
26 with Ada.Text_IO;
28 with Morzhol.Strings;
29 with Morzhol.VC.RCS;
31 procedure Test is
33 use Ada;
34 use Ada.Text_IO;
35 use Ada.Command_Line;
36 use Ada.Strings.Unbounded;
38 use Morzhol.Strings;
39 use Morzhol.VC.RCS;
41 VCS_Engine : RCS;
43 begin
44 if HTML_To_Text
45 ("<a href='http://morzhol.google.code.com'>Morzhol</a>") /= "Morzhol"
46 or else HTML_To_Text ("A <em>small</em> test") /= "A small test"
47 or else HTML_To_Text
48 ("for <br /><hr /><br /> html_to_text") /= "for html_to_text"
49 then
50 Put_Line ("HTML_To_Text Error");
51 return;
52 end if;
54 Create_Test_File : declare
55 File_To_Create : File_Type;
56 begin
58 if Directories.Exists ("test/RCS") then
59 Directories.Delete_Tree ("test/RCS");
60 end if;
62 if Directories.Exists ("test/RCS_Test") then
63 Directories.Delete_File ("test/RCS_Test");
64 end if;
66 Create (File => File_To_Create,
67 Mode => Out_File,
68 Name => "test/RCS_Test");
70 Put (File_To_Create, "test");
71 Close (File_To_Create);
72 end Create_Test_File;
74 if not Lock (VCS_Engine, "test/RCS_Test") then
75 -- Try to add
77 if not Add (VCS_Engine, "test/RCS_Test", Author => "initial_author")
78 or else not Lock (VCS_Engine, "test/RCS_Test")
79 then
80 Put_Line ("Can not Lock RCS Test !");
81 return;
82 end if;
83 end if;
85 Change_Test_File : declare
86 File_To_Change : File_Type;
87 begin
88 Open (File => File_To_Change,
89 Mode => Out_File,
90 Name => "test/RCS_Test");
92 Put (File_To_Change, "modification");
93 Close (File_To_Change);
94 end Change_Test_File;
96 if not Commit
97 (Engine => VCS_Engine,
98 Filename => "test/RCS_Test",
99 Message => "first commit by test.adb",
100 Author => "author")
101 then
102 Ada.Text_IO.Put_Line ("Commit failure");
103 return;
104 end if;
106 Show_Logs : declare
107 File_Log : constant Morzhol.VC.Log :=
108 Get_Log (VCS_Engine, "test/RCS_Test");
109 Diff_Txt : Unbounded_String :=
110 +Diff (VCS_Engine, "test/RCS_Test",
111 -File_Log (2).Revision, -File_Log (1).Revision);
112 begin
113 -- Remove CR for Windows compatibility
114 Search_CR : loop
115 Strip_CR : declare
116 I : constant Natural := Index (Diff_Txt, String'(1 => ASCII.CR));
117 begin
118 exit Search_CR when I = 0;
119 Delete (Diff_Txt, I, I);
120 end Strip_CR;
121 end loop Search_CR;
123 if -Diff_Txt /=
124 "==================================================================="
125 & ASCII.LF & "RCS file: test/RCS/RCS_Test,v"
126 & ASCII.LF & "retrieving revision 1.1"
127 & ASCII.LF & "retrieving revision 1.2"
128 & ASCII.LF & "diff -r1.1 -r1.2"
129 & ASCII.LF & "1c1"
130 & ASCII.LF & "< test"
131 & ASCII.LF & "---"
132 & ASCII.LF & "> modification"
133 or else -File_Log (1).Author /= "author"
134 or else -File_Log (2).Author /= "initial_author"
135 then
136 Put_Line ("Diff error !");
137 return;
138 end if;
139 end Show_Logs;
141 Put_Line ("OK. All tests passed !");
142 Set_Exit_Status (Success);
144 exception
145 when E : others =>
146 Put_Line (Exceptions.Exception_Information (E));
147 Set_Exit_Status (Failure);
148 end Test;