<commit_before>USING: accessors fry ftp.server io.encodings.ascii io.files
io.pathnames io.servers kernel tools.test urls ;
FROM: ftp.client => ftp-get ;
IN: ftp.server.tests

CONSTANT: test-file-contents "Files are so boring anymore."

: create-test-file ( -- path )
    test-file-contents "ftp.server" [ ascii set-file-contents ] keep ;

: test-ftp-server ( quot: ( server path -- ) -- )
    '[
        "." 0 <ftp-server> [
            "ftp://localhost" >url insecure-addr set-url-addr
                "ftp" >>protocol
                create-test-file >>path
                @
        ] with-threaded-server
    ] with-test-directory ; inline

{ t } [
    [
        [ ftp-get ]
        [ path>> file-name ascii file-contents ] bi
    ] test-ftp-server test-file-contents =
] unit-test

[

    [
        "/" >>path
        [ ftp-get ]
        [ path>> file-name ascii file-contents ] bi
    ] test-ftp-server test-file-contents =
] must-fail<commit_msg>ftp.server: Don't fetch to the same directory we serve from or else it will overwrite the file. Race condition, only shows up on Windows for some reason.<commit_after>USING: accessors fry ftp.server io.encodings.ascii io.files
io.pathnames io.servers kernel tools.test urls ;
FROM: ftp.client => ftp-get ;
IN: ftp.server.tests

CONSTANT: test-file-contents "Files are so boring anymore."

: create-test-file ( -- path )
    test-file-contents "ftp.server" [ ascii set-file-contents ] keep ;

: test-ftp-server ( quot: ( server path -- ) -- )
    '[
        "." 0 <ftp-server> [
            "ftp://localhost" >url insecure-addr set-url-addr
                "ftp" >>protocol
                create-test-file >>path
                @
        ] with-threaded-server
    ] with-test-directory ; inline

{ t } [
    [
        ! give client its own directory so we don't overwrite the ftp server's file
        [
            [ ftp-get ]
            [ path>> file-name ascii file-contents ] bi
        ] with-test-directory
    ] test-ftp-server test-file-contents =
] unit-test

[

    [
        ! give client its own directory so we don't overwrite the ftp server's file
        [
            "/" >>path
            [ ftp-get ]
            [ path>> file-name ascii file-contents ] bi
        ] with-test-directory
    ] test-ftp-server test-file-contents =
] must-fail
{'fraction_non_alphanumeric': 0.12521588946459414, 'fraction_numerical': 0.0008635578583765112, 'mean_word_length': 1.9858247422680413, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5378267', 'n_tokens_mistral': 756, 'n_tokens_neox': 712, 'n_words': 187}